Skip to content

Commit

Permalink
feat: update parser (#687)
Browse files Browse the repository at this point in the history
  • Loading branch information
ota-meshi authored Feb 24, 2024
1 parent a31d2bd commit 2943021
Show file tree
Hide file tree
Showing 7 changed files with 42 additions and 15 deletions.
5 changes: 5 additions & 0 deletions .changeset/twenty-trainers-peel.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"eslint-plugin-svelte": patch
---

feat: update parser
4 changes: 4 additions & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,7 @@

# JSONSchema bug?
/.devcontainer/devcontainer.json

# Parser bug?
/tests/fixtures/rules/indent/invalid/const-tag01-input.svelte
/tests/fixtures/rules/indent/invalid/const-tag01-output.svelte
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@
},
"peerDependencies": {
"eslint": "^7.0.0 || ^8.0.0-0 || ^9.0.0-0",
"svelte": "^3.37.0 || ^4.0.0 || ^5.0.0-next.33"
"svelte": "^3.37.0 || ^4.0.0 || ^5.0.0-next.68"
},
"peerDependenciesMeta": {
"svelte": {
Expand All @@ -78,7 +78,7 @@
"postcss-safe-parser": "^6.0.0",
"postcss-selector-parser": "^6.0.11",
"semver": "^7.5.3",
"svelte-eslint-parser": ">=0.34.0-next.4 <1.0.0"
"svelte-eslint-parser": ">=0.34.0-next.9 <1.0.0"
},
"devDependencies": {
"@1stg/browserslist-config": "^2.0.0",
Expand Down Expand Up @@ -166,7 +166,7 @@
"stylelint": "^16.0.0",
"stylelint-config-standard": "^36.0.0",
"stylus": "^0.62.0",
"svelte": "^5.0.0-next.33",
"svelte": "^5.0.0-next.68",
"svelte-adapter-ghpages": "0.2.2",
"svelte-i18n": "^4.0.0",
"tslib": "^2.5.0",
Expand Down
17 changes: 10 additions & 7 deletions src/rules/indent-helpers/svelte.ts
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ export function defineVisitor(context: IndentContext): NodeListener {
const rightParenToken = sourceCode.getTokenBefore(sourceCode.getLastToken(node));

offsets.setOffsetToken(leftParenToken, 1, calleeToken);
offsets.setOffsetElementList([node.argument], leftParenToken, rightParenToken, 1);
offsets.setOffsetElementList(node.arguments, leftParenToken, rightParenToken, 1);
},
// ----------------------------------------------------------------------
// BLOCKS
Expand Down Expand Up @@ -488,19 +488,22 @@ export function defineVisitor(context: IndentContext): NodeListener {
offsets.setOffsetToken(id.firstToken, 1, snippetToken);

const leftParenToken = sourceCode.getTokenBefore(
node.context || sourceCode.getLastToken(node),
node.params[0] || sourceCode.getLastToken(node),
{
filter: isOpeningParenToken,
includeComments: false
}
)!;

const rightParenToken = sourceCode.getTokenAfter(node.context || leftParenToken, {
filter: isClosingParenToken,
includeComments: false
})!;
const rightParenToken = sourceCode.getTokenAfter(
node.params[node.params.length - 1] || leftParenToken,
{
filter: isClosingParenToken,
includeComments: false
}
)!;
offsets.setOffsetToken(leftParenToken, 1, id.firstToken);
offsets.setOffsetElementList([node.context], leftParenToken, rightParenToken, 1);
offsets.setOffsetElementList(node.params, leftParenToken, rightParenToken, 1);
},
// ----------------------------------------------------------------------
// COMMENTS
Expand Down
11 changes: 7 additions & 4 deletions src/rules/mustache-spacing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -400,10 +400,13 @@ export default createRule('mustache-spacing', {
},
SvelteSnippetBlock(node) {
const openBlockOpeningToken = sourceCode.getFirstToken(node);
const openBlockClosingToken = sourceCode.getTokenAfter(node.context || node.id, {
includeComments: false,
filter: isClosingBraceToken
})!;
const openBlockClosingToken = sourceCode.getTokenAfter(
node.params[node.params.length - 1] || node.id,
{
includeComments: false,
filter: isClosingBraceToken
}
)!;
verifyBraces(
openBlockOpeningToken,
openBlockClosingToken,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"FIXME": "Bug in Svelte v5-next.68?",
"svelte": "^4 || ^3"
}
10 changes: 9 additions & 1 deletion tests/utils/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,14 @@ export function loadTestCases(
}
const errors = fs.readFileSync(errorFile, 'utf8');
config.errors = parseYaml(errors);
for (const error of config.errors) {
if (error.suggestions) {
error.suggestions = error.suggestions?.map((s: any) => ({
output: s.output,
desc: s.desc
}));
}
}
if (fixable) {
let output;
try {
Expand All @@ -140,7 +148,7 @@ export function loadTestCases(
writeFixtures(ruleName, inputFile);
output = fs.readFileSync(outputFile, 'utf8');
}
config.output = output;
config.output = output === config.code ? null : output;
}

return config;
Expand Down

0 comments on commit 2943021

Please sign in to comment.