From 157ee1fade79aab88f01d125b0b01cf375da4cd1 Mon Sep 17 00:00:00 2001 From: Yuichiro Yamashita Date: Sat, 14 Dec 2024 15:08:34 +0900 Subject: [PATCH] chore: update `svelte-eslint-parser` to v1.0.0-next.4 (#956) --- .changeset/hungry-grapes-shave.md | 5 ++ packages/eslint-plugin-svelte/package.json | 2 +- .../src/rules/indent-helpers/svelte.ts | 4 +- .../src/rules/mustache-spacing.ts | 2 +- .../rules/no-immutable-reactive-statements.ts | 4 +- .../src/rules/valid-each-key.ts | 8 ++- .../valid-compile/invalid/a11y01-errors.yaml | 4 +- .../invalid-svelte-ignore01-errors.yaml | 15 +++--- ...nvalid-svelte-ignore01-svelte4-errors.yaml | 3 +- .../invalid-svelte-ignore02-errors.yaml | 15 +++--- .../invalid-svelte-ignore03-errors.yaml | 53 ++++++++++++------- .../a11y-errors.yaml | 8 ++- .../svelte-config-ignore/a11y-errors.yaml | 4 +- .../invalid/ts/enum01-errors.yaml | 5 +- ...5-each-blocks-without-an-item-input.svelte | 7 +++ ...h-blocks-without-an-item-requirements.json | 3 ++ 16 files changed, 96 insertions(+), 46 deletions(-) create mode 100644 .changeset/hungry-grapes-shave.md create mode 100644 packages/eslint-plugin-svelte/tests/fixtures/rules/valid-each-key/valid/svelte5-each-blocks-without-an-item-input.svelte create mode 100644 packages/eslint-plugin-svelte/tests/fixtures/rules/valid-each-key/valid/svelte5-each-blocks-without-an-item-requirements.json diff --git a/.changeset/hungry-grapes-shave.md b/.changeset/hungry-grapes-shave.md new file mode 100644 index 000000000..67d345757 --- /dev/null +++ b/.changeset/hungry-grapes-shave.md @@ -0,0 +1,5 @@ +--- +'eslint-plugin-svelte': patch +--- + +chore: update `svelte-eslint-parser` to v1.0.0-next.4 diff --git a/packages/eslint-plugin-svelte/package.json b/packages/eslint-plugin-svelte/package.json index 068ae385b..aa540075e 100644 --- a/packages/eslint-plugin-svelte/package.json +++ b/packages/eslint-plugin-svelte/package.json @@ -66,7 +66,7 @@ "postcss-safe-parser": "^6.0.0", "postcss-selector-parser": "^7.0.0", "semver": "^7.6.3", - "svelte-eslint-parser": "^1.0.0-next.3" + "svelte-eslint-parser": "^1.0.0-next.4" }, "devDependencies": { "@babel/core": "^7.26.0", diff --git a/packages/eslint-plugin-svelte/src/rules/indent-helpers/svelte.ts b/packages/eslint-plugin-svelte/src/rules/indent-helpers/svelte.ts index 1265e9e58..8b0877e26 100644 --- a/packages/eslint-plugin-svelte/src/rules/indent-helpers/svelte.ts +++ b/packages/eslint-plugin-svelte/src/rules/indent-helpers/svelte.ts @@ -289,7 +289,9 @@ export function defineVisitor(context: IndentContext): NodeListener { const closeOpenTagToken = sourceCode.getTokenAfter(key.lastToken); offsets.setOffsetToken(closeOpenTagToken, 0, openToken); } else { - const closeOpenTagToken = sourceCode.getTokenAfter(node.index || node.context); + const closeOpenTagToken = sourceCode.getTokenAfter( + node.index || node.context || node.expression + ); offsets.setOffsetToken(closeOpenTagToken, 0, openToken); } diff --git a/packages/eslint-plugin-svelte/src/rules/mustache-spacing.ts b/packages/eslint-plugin-svelte/src/rules/mustache-spacing.ts index 973cb4cad..24ef76ab5 100644 --- a/packages/eslint-plugin-svelte/src/rules/mustache-spacing.ts +++ b/packages/eslint-plugin-svelte/src/rules/mustache-spacing.ts @@ -272,7 +272,7 @@ export default createRule('mustache-spacing', { SvelteEachBlock(node: AST.SvelteEachBlock) { const openBlockOpeningToken = sourceCode.getFirstToken(node); const openBlockClosingToken = sourceCode.getTokenAfter( - node.key || node.index || node.context, + node.key || node.index || node.context || node.expression, { includeComments: false, filter: isClosingBraceToken diff --git a/packages/eslint-plugin-svelte/src/rules/no-immutable-reactive-statements.ts b/packages/eslint-plugin-svelte/src/rules/no-immutable-reactive-statements.ts index 09144c4e1..d6cba520f 100644 --- a/packages/eslint-plugin-svelte/src/rules/no-immutable-reactive-statements.ts +++ b/packages/eslint-plugin-svelte/src/rules/no-immutable-reactive-statements.ts @@ -135,7 +135,9 @@ export default createRule('no-immutable-reactive-statements', { return parent.kind === 'Binding' && parent.expression === expr; } if (parent.type === 'SvelteEachBlock') { - return parent.expression === expr && hasWriteReference(parent.context); + return ( + parent.context !== null && parent.expression === expr && hasWriteReference(parent.context) + ); } return false; diff --git a/packages/eslint-plugin-svelte/src/rules/valid-each-key.ts b/packages/eslint-plugin-svelte/src/rules/valid-each-key.ts index 6a8afd230..5bcc29d24 100644 --- a/packages/eslint-plugin-svelte/src/rules/valid-each-key.ts +++ b/packages/eslint-plugin-svelte/src/rules/valid-each-key.ts @@ -27,11 +27,15 @@ export default createRule('valid-each-key', { if ( !variable.defs.some( (def) => - (node.context.range[0] <= def.name.range[0] && + (node.context && + node.context.range[0] <= def.name.range[0] && def.name.range[1] <= node.context.range[1]) || (node.index && node.index.range[0] <= def.name.range[0] && - def.name.range[1] <= node.index.range[1]) + def.name.range[1] <= node.index.range[1]) || + (node.expression && + node.expression.range[0] <= def.name.range[0] && + def.name.range[1] <= node.expression.range[1]) ) ) { // It's not an iteration variable. diff --git a/packages/eslint-plugin-svelte/tests/fixtures/rules/valid-compile/invalid/a11y01-errors.yaml b/packages/eslint-plugin-svelte/tests/fixtures/rules/valid-compile/invalid/a11y01-errors.yaml index 6b8f12fef..29d71b27e 100644 --- a/packages/eslint-plugin-svelte/tests/fixtures/rules/valid-compile/invalid/a11y01-errors.yaml +++ b/packages/eslint-plugin-svelte/tests/fixtures/rules/valid-compile/invalid/a11y01-errors.yaml @@ -1,4 +1,6 @@ -- message: '`` element should have an alt attribute(a11y_missing_attribute)' +- message: |- + `` element should have an alt attribute + https://svelte.dev/e/a11y_missing_attribute(a11y_missing_attribute) line: 5 column: 1 suggestions: null diff --git a/packages/eslint-plugin-svelte/tests/fixtures/rules/valid-compile/invalid/invalid-svelte-ignore01-errors.yaml b/packages/eslint-plugin-svelte/tests/fixtures/rules/valid-compile/invalid/invalid-svelte-ignore01-errors.yaml index 82a6aee8d..043242772 100644 --- a/packages/eslint-plugin-svelte/tests/fixtures/rules/valid-compile/invalid/invalid-svelte-ignore01-errors.yaml +++ b/packages/eslint-plugin-svelte/tests/fixtures/rules/valid-compile/invalid/invalid-svelte-ignore01-errors.yaml @@ -1,15 +1,18 @@ -- message: noninteractive element cannot have nonnegative tabIndex - value(a11y_no_noninteractive_tabindex) +- message: |- + noninteractive element cannot have nonnegative tabIndex value + https://svelte.dev/e/a11y_no_noninteractive_tabindex(a11y_no_noninteractive_tabindex) line: 6 column: 3 suggestions: null -- message: A form label must be associated with a - control(a11y_label_has_associated_control) +- message: |- + A form label must be associated with a control + https://svelte.dev/e/a11y_label_has_associated_control(a11y_label_has_associated_control) line: 6 column: 3 suggestions: null -- message: noninteractive element cannot have nonnegative tabIndex - value(a11y_no_noninteractive_tabindex) +- message: |- + noninteractive element cannot have nonnegative tabIndex value + https://svelte.dev/e/a11y_no_noninteractive_tabindex(a11y_no_noninteractive_tabindex) line: 7 column: 3 suggestions: null diff --git a/packages/eslint-plugin-svelte/tests/fixtures/rules/valid-compile/invalid/invalid-svelte-ignore01-svelte4-errors.yaml b/packages/eslint-plugin-svelte/tests/fixtures/rules/valid-compile/invalid/invalid-svelte-ignore01-svelte4-errors.yaml index 2f9836ae3..ef541694e 100644 --- a/packages/eslint-plugin-svelte/tests/fixtures/rules/valid-compile/invalid/invalid-svelte-ignore01-svelte4-errors.yaml +++ b/packages/eslint-plugin-svelte/tests/fixtures/rules/valid-compile/invalid/invalid-svelte-ignore01-svelte4-errors.yaml @@ -3,8 +3,7 @@ line: 6 column: 3 suggestions: null -- message: 'A11y: A form label must be associated with a - control.(a11y-label-has-associated-control)' +- message: 'A11y: A form label must be associated with a control.(a11y-label-has-associated-control)' line: 6 column: 3 suggestions: null diff --git a/packages/eslint-plugin-svelte/tests/fixtures/rules/valid-compile/invalid/invalid-svelte-ignore02-errors.yaml b/packages/eslint-plugin-svelte/tests/fixtures/rules/valid-compile/invalid/invalid-svelte-ignore02-errors.yaml index 82a6aee8d..043242772 100644 --- a/packages/eslint-plugin-svelte/tests/fixtures/rules/valid-compile/invalid/invalid-svelte-ignore02-errors.yaml +++ b/packages/eslint-plugin-svelte/tests/fixtures/rules/valid-compile/invalid/invalid-svelte-ignore02-errors.yaml @@ -1,15 +1,18 @@ -- message: noninteractive element cannot have nonnegative tabIndex - value(a11y_no_noninteractive_tabindex) +- message: |- + noninteractive element cannot have nonnegative tabIndex value + https://svelte.dev/e/a11y_no_noninteractive_tabindex(a11y_no_noninteractive_tabindex) line: 6 column: 3 suggestions: null -- message: A form label must be associated with a - control(a11y_label_has_associated_control) +- message: |- + A form label must be associated with a control + https://svelte.dev/e/a11y_label_has_associated_control(a11y_label_has_associated_control) line: 6 column: 3 suggestions: null -- message: noninteractive element cannot have nonnegative tabIndex - value(a11y_no_noninteractive_tabindex) +- message: |- + noninteractive element cannot have nonnegative tabIndex value + https://svelte.dev/e/a11y_no_noninteractive_tabindex(a11y_no_noninteractive_tabindex) line: 7 column: 3 suggestions: null diff --git a/packages/eslint-plugin-svelte/tests/fixtures/rules/valid-compile/invalid/invalid-svelte-ignore03-errors.yaml b/packages/eslint-plugin-svelte/tests/fixtures/rules/valid-compile/invalid/invalid-svelte-ignore03-errors.yaml index 08147e812..b8d2c33b9 100644 --- a/packages/eslint-plugin-svelte/tests/fixtures/rules/valid-compile/invalid/invalid-svelte-ignore03-errors.yaml +++ b/packages/eslint-plugin-svelte/tests/fixtures/rules/valid-compile/invalid/invalid-svelte-ignore03-errors.yaml @@ -1,53 +1,66 @@ -- message: Empty block(block_empty) +- message: |- + Empty block + https://svelte.dev/e/block_empty(block_empty) line: 2 column: 30 suggestions: null -- message: noninteractive element cannot have nonnegative tabIndex - value(a11y_no_noninteractive_tabindex) +- message: |- + noninteractive element cannot have nonnegative tabIndex value + https://svelte.dev/e/a11y_no_noninteractive_tabindex(a11y_no_noninteractive_tabindex) line: 5 column: 3 suggestions: null -- message: A form label must be associated with a - control(a11y_label_has_associated_control) +- message: |- + A form label must be associated with a control + https://svelte.dev/e/a11y_label_has_associated_control(a11y_label_has_associated_control) line: 5 column: 3 suggestions: null -- message: noninteractive element cannot have nonnegative tabIndex - value(a11y_no_noninteractive_tabindex) +- message: |- + noninteractive element cannot have nonnegative tabIndex value + https://svelte.dev/e/a11y_no_noninteractive_tabindex(a11y_no_noninteractive_tabindex) line: 6 column: 3 suggestions: null -- message: noninteractive element cannot have nonnegative tabIndex - value(a11y_no_noninteractive_tabindex) +- message: |- + noninteractive element cannot have nonnegative tabIndex value + https://svelte.dev/e/a11y_no_noninteractive_tabindex(a11y_no_noninteractive_tabindex) line: 9 column: 3 suggestions: null -- message: A form label must be associated with a - control(a11y_label_has_associated_control) +- message: |- + A form label must be associated with a control + https://svelte.dev/e/a11y_label_has_associated_control(a11y_label_has_associated_control) line: 9 column: 3 suggestions: null -- message: noninteractive element cannot have nonnegative tabIndex - value(a11y_no_noninteractive_tabindex) +- message: |- + noninteractive element cannot have nonnegative tabIndex value + https://svelte.dev/e/a11y_no_noninteractive_tabindex(a11y_no_noninteractive_tabindex) line: 10 column: 3 suggestions: null -- message: Empty block(block_empty) +- message: |- + Empty block + https://svelte.dev/e/block_empty(block_empty) line: 14 column: 30 suggestions: null -- message: noninteractive element cannot have nonnegative tabIndex - value(a11y_no_noninteractive_tabindex) +- message: |- + noninteractive element cannot have nonnegative tabIndex value + https://svelte.dev/e/a11y_no_noninteractive_tabindex(a11y_no_noninteractive_tabindex) line: 17 column: 3 suggestions: null -- message: A form label must be associated with a - control(a11y_label_has_associated_control) +- message: |- + A form label must be associated with a control + https://svelte.dev/e/a11y_label_has_associated_control(a11y_label_has_associated_control) line: 17 column: 3 suggestions: null -- message: noninteractive element cannot have nonnegative tabIndex - value(a11y_no_noninteractive_tabindex) +- message: |- + noninteractive element cannot have nonnegative tabIndex value + https://svelte.dev/e/a11y_no_noninteractive_tabindex(a11y_no_noninteractive_tabindex) line: 18 column: 3 suggestions: null diff --git a/packages/eslint-plugin-svelte/tests/fixtures/rules/valid-compile/invalid/svelte-config-custom-warn/a11y-errors.yaml b/packages/eslint-plugin-svelte/tests/fixtures/rules/valid-compile/invalid/svelte-config-custom-warn/a11y-errors.yaml index cda864620..9b0b15229 100644 --- a/packages/eslint-plugin-svelte/tests/fixtures/rules/valid-compile/invalid/svelte-config-custom-warn/a11y-errors.yaml +++ b/packages/eslint-plugin-svelte/tests/fixtures/rules/valid-compile/invalid/svelte-config-custom-warn/a11y-errors.yaml @@ -1,8 +1,12 @@ -- message: '`` element should have an alt attribute(foo)' +- message: |- + `` element should have an alt attribute + https://svelte.dev/e/a11y_missing_attribute(foo) line: 5 column: 1 suggestions: null -- message: Avoid using autofocus(foo) +- message: |- + Avoid using autofocus + https://svelte.dev/e/a11y_autofocus(foo) line: 5 column: 12 suggestions: null diff --git a/packages/eslint-plugin-svelte/tests/fixtures/rules/valid-compile/invalid/svelte-config-ignore/a11y-errors.yaml b/packages/eslint-plugin-svelte/tests/fixtures/rules/valid-compile/invalid/svelte-config-ignore/a11y-errors.yaml index 00fe33d44..ccac480e9 100644 --- a/packages/eslint-plugin-svelte/tests/fixtures/rules/valid-compile/invalid/svelte-config-ignore/a11y-errors.yaml +++ b/packages/eslint-plugin-svelte/tests/fixtures/rules/valid-compile/invalid/svelte-config-ignore/a11y-errors.yaml @@ -1,4 +1,6 @@ -- message: Avoid using autofocus(a11y_autofocus) +- message: |- + Avoid using autofocus + https://svelte.dev/e/a11y_autofocus(a11y_autofocus) line: 5 column: 12 suggestions: null diff --git a/packages/eslint-plugin-svelte/tests/fixtures/rules/valid-compile/invalid/ts/enum01-errors.yaml b/packages/eslint-plugin-svelte/tests/fixtures/rules/valid-compile/invalid/ts/enum01-errors.yaml index 44dec8750..f07364f16 100644 --- a/packages/eslint-plugin-svelte/tests/fixtures/rules/valid-compile/invalid/ts/enum01-errors.yaml +++ b/packages/eslint-plugin-svelte/tests/fixtures/rules/valid-compile/invalid/ts/enum01-errors.yaml @@ -1,5 +1,6 @@ -- message: The $ prefix is reserved, and cannot be used for variables and - imports(dollar_prefix_invalid) +- message: |- + The $ prefix is reserved, and cannot be used for variables and imports + https://svelte.dev/e/dollar_prefix_invalid(dollar_prefix_invalid) line: 2 column: 8 suggestions: null diff --git a/packages/eslint-plugin-svelte/tests/fixtures/rules/valid-each-key/valid/svelte5-each-blocks-without-an-item-input.svelte b/packages/eslint-plugin-svelte/tests/fixtures/rules/valid-each-key/valid/svelte5-each-blocks-without-an-item-input.svelte new file mode 100644 index 000000000..e3310ffe8 --- /dev/null +++ b/packages/eslint-plugin-svelte/tests/fixtures/rules/valid-each-key/valid/svelte5-each-blocks-without-an-item-input.svelte @@ -0,0 +1,7 @@ +
+ {#each { length: 8 }, rank} + {#each { length: 8 }} + {rank} + {/each} + {/each} +
diff --git a/packages/eslint-plugin-svelte/tests/fixtures/rules/valid-each-key/valid/svelte5-each-blocks-without-an-item-requirements.json b/packages/eslint-plugin-svelte/tests/fixtures/rules/valid-each-key/valid/svelte5-each-blocks-without-an-item-requirements.json new file mode 100644 index 000000000..1a22befbb --- /dev/null +++ b/packages/eslint-plugin-svelte/tests/fixtures/rules/valid-each-key/valid/svelte5-each-blocks-without-an-item-requirements.json @@ -0,0 +1,3 @@ +{ + "svelte": "^5.0.0" +}