diff --git a/.changeset/good-carrots-notice.md b/.changeset/good-carrots-notice.md new file mode 100644 index 000000000..6a7f03087 --- /dev/null +++ b/.changeset/good-carrots-notice.md @@ -0,0 +1,5 @@ +--- +'eslint-plugin-svelte': patch +--- + +fix(prefer-const): Use `additionalProperties` instead of `ignoreReadonly` to match the ESLint core rule option name. diff --git a/docs/rules/prefer-const.md b/docs/rules/prefer-const.md index 8029ea881..f158d47b6 100644 --- a/docs/rules/prefer-const.md +++ b/docs/rules/prefer-const.md @@ -46,7 +46,7 @@ This rule reports the same as the base ESLint `prefer-const` rule, except that i "error", { "destructuring": "any", - "ignoreReadonly": true, + "additionalProperties": false, "excludedRunes": ["$props", "$derived"] } ] @@ -54,14 +54,14 @@ This rule reports the same as the base ESLint `prefer-const` rule, except that i ``` - `destructuring`: The kind of the way to address variables in destructuring. There are 2 values: - - `any` (default): if any variables in destructuring should be const, this rule warns for those variables. - - `all`: if all variables in destructuring should be const, this rule warns the variables. Otherwise, ignores them. -- `ignoreReadonly`: If `true`, this rule will ignore variables that are read between the declaration and the _first_ assignment. + - `any` (default) - If any variables in destructuring should be const, this rule warns for those variables. + - `all`: If all variables in destructuring should be const, this rule warns the variables. Otherwise, ignores them. +- `ignoreReadBeforeAssign`: This is an option to avoid conflicting with `no-use-before-define` rule (without "nofunc" option). If `true` is specified, this rule will ignore variables that are read between the declaration and the first assignment. Default is `false`. - `excludedRunes`: An array of rune names that should be ignored. Even if a rune is declared with `let`, it will still be ignored. ## :books: Further Reading -- See [ESLint `prefer-const` rule](https://eslint.org/docs/latest/rules/prefer-const) for more information about the base rule. +- See [ESLint prefer-const rule](https://eslint.org/docs/latest/rules/prefer-const) for more information about the base rule. ## :rocket: Version diff --git a/packages/eslint-plugin-svelte/src/rule-types.ts b/packages/eslint-plugin-svelte/src/rule-types.ts index 2fd9c7db2..81657270d 100644 --- a/packages/eslint-plugin-svelte/src/rule-types.ts +++ b/packages/eslint-plugin-svelte/src/rule-types.ts @@ -573,6 +573,7 @@ type SveltePreferConst = []|[{ destructuring?: ("any" | "all") ignoreReadBeforeAssign?: boolean excludedRunes?: string[] + [k: string]: unknown | undefined }] // ----- svelte/require-event-prefix ----- type SvelteRequireEventPrefix = []|[{ diff --git a/packages/eslint-plugin-svelte/src/rules/prefer-const.ts b/packages/eslint-plugin-svelte/src/rules/prefer-const.ts index 842bbc924..e28765baa 100644 --- a/packages/eslint-plugin-svelte/src/rules/prefer-const.ts +++ b/packages/eslint-plugin-svelte/src/rules/prefer-const.ts @@ -68,7 +68,8 @@ export default createRule('prefer-const', { } } }, - additionalProperties: false + // Allow ESLint core rule properties in case new options are added in the future. + additionalProperties: true } ] }, diff --git a/packages/eslint-plugin-svelte/tests/fixtures/rules/prefer-const/valid/1238/_config.json b/packages/eslint-plugin-svelte/tests/fixtures/rules/prefer-const/valid/1238/_config.json new file mode 100644 index 000000000..88200a87e --- /dev/null +++ b/packages/eslint-plugin-svelte/tests/fixtures/rules/prefer-const/valid/1238/_config.json @@ -0,0 +1,8 @@ +{ + "options": [ + { + "destructuring": "all", + "additionalProperties": true + } + ] +} diff --git a/packages/eslint-plugin-svelte/tests/fixtures/rules/prefer-const/valid/1238/input.svelte b/packages/eslint-plugin-svelte/tests/fixtures/rules/prefer-const/valid/1238/input.svelte new file mode 100644 index 000000000..190a18037 --- /dev/null +++ b/packages/eslint-plugin-svelte/tests/fixtures/rules/prefer-const/valid/1238/input.svelte @@ -0,0 +1 @@ +123