diff --git a/.changeset/twenty-trainers-peel.md b/.changeset/twenty-trainers-peel.md new file mode 100644 index 000000000..8ea11336e --- /dev/null +++ b/.changeset/twenty-trainers-peel.md @@ -0,0 +1,5 @@ +--- +"eslint-plugin-svelte": patch +--- + +feat: update parser diff --git a/.eslintignore b/.eslintignore index 8c0a0b948..3de5191c2 100644 --- a/.eslintignore +++ b/.eslintignore @@ -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 diff --git a/package.json b/package.json index ab4526d83..4aa4f1673 100644 --- a/package.json +++ b/package.json @@ -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": { @@ -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", @@ -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", diff --git a/src/rules/indent-helpers/svelte.ts b/src/rules/indent-helpers/svelte.ts index 910913b9a..0aae3a9f9 100644 --- a/src/rules/indent-helpers/svelte.ts +++ b/src/rules/indent-helpers/svelte.ts @@ -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 @@ -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 diff --git a/src/rules/mustache-spacing.ts b/src/rules/mustache-spacing.ts index 4708dfee5..168dbda8f 100644 --- a/src/rules/mustache-spacing.ts +++ b/src/rules/mustache-spacing.ts @@ -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, diff --git a/tests/fixtures/rules/indent/invalid/const-tag01-requirements.json b/tests/fixtures/rules/indent/invalid/const-tag01-requirements.json new file mode 100644 index 000000000..5c890e854 --- /dev/null +++ b/tests/fixtures/rules/indent/invalid/const-tag01-requirements.json @@ -0,0 +1,4 @@ +{ + "FIXME": "Bug in Svelte v5-next.68?", + "svelte": "^4 || ^3" +} diff --git a/tests/utils/utils.ts b/tests/utils/utils.ts index 56b24b29a..7429973aa 100644 --- a/tests/utils/utils.ts +++ b/tests/utils/utils.ts @@ -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 { @@ -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;