diff --git a/README.md b/README.md index a959eda16..e08bf1dee 100644 --- a/README.md +++ b/README.md @@ -362,6 +362,7 @@ These rules relate to better ways of doing things to help you avoid problems: | [svelte/no-unused-class-name](https://sveltejs.github.io/eslint-plugin-svelte/rules/no-unused-class-name/) | disallow the use of a class in the template without a corresponding style | | | [svelte/no-unused-svelte-ignore](https://sveltejs.github.io/eslint-plugin-svelte/rules/no-unused-svelte-ignore/) | disallow unused svelte-ignore comments | :star: | | [svelte/no-useless-mustaches](https://sveltejs.github.io/eslint-plugin-svelte/rules/no-useless-mustaches/) | disallow unnecessary mustache interpolations | :wrench: | +| [svelte/prefer-const](https://sveltejs.github.io/eslint-plugin-svelte/rules/prefer-const/) | Require `const` declarations for variables that are never reassigned after declared | :wrench: | | [svelte/prefer-destructured-store-props](https://sveltejs.github.io/eslint-plugin-svelte/rules/prefer-destructured-store-props/) | destructure values from object stores for better change tracking & fewer redraws | :bulb: | | [svelte/require-each-key](https://sveltejs.github.io/eslint-plugin-svelte/rules/require-each-key/) | require keyed `{#each}` block | | | [svelte/require-event-dispatcher-types](https://sveltejs.github.io/eslint-plugin-svelte/rules/require-event-dispatcher-types/) | require type parameters for `createEventDispatcher` | | diff --git a/docs/rules.md b/docs/rules.md index 29701ff7e..d2dd3d7a7 100644 --- a/docs/rules.md +++ b/docs/rules.md @@ -64,6 +64,7 @@ These rules relate to better ways of doing things to help you avoid problems: | [svelte/no-unused-class-name](./rules/no-unused-class-name.md) | disallow the use of a class in the template without a corresponding style | | | [svelte/no-unused-svelte-ignore](./rules/no-unused-svelte-ignore.md) | disallow unused svelte-ignore comments | :star: | | [svelte/no-useless-mustaches](./rules/no-useless-mustaches.md) | disallow unnecessary mustache interpolations | :wrench: | +| [svelte/prefer-const](./rules/prefer-const.md) | Require `const` declarations for variables that are never reassigned after declared | :wrench: | | [svelte/prefer-destructured-store-props](./rules/prefer-destructured-store-props.md) | destructure values from object stores for better change tracking & fewer redraws | :bulb: | | [svelte/require-each-key](./rules/require-each-key.md) | require keyed `{#each}` block | | | [svelte/require-event-dispatcher-types](./rules/require-event-dispatcher-types.md) | require type parameters for `createEventDispatcher` | | diff --git a/docs/rules/prefer-const.md b/docs/rules/prefer-const.md index 534d44d6e..2230e342c 100644 --- a/docs/rules/prefer-const.md +++ b/docs/rules/prefer-const.md @@ -16,8 +16,6 @@ description: 'Require `const` declarations for variables that are never reassign This rule reports the same as the base ESLint `prefer-const` rule, except that ignores Svelte reactive values such as `$state`, `$derived` and `$props`. If this rule is active, make sure to disable the base `prefer-const` rule, as it will conflict with this rule. - - ```svelte @@ -34,8 +32,6 @@ This rule reports the same as the base ESLint `prefer-const` rule, except that i ``` - - ## :wrench: Options ```json diff --git a/packages/eslint-plugin-svelte/src/rule-types.ts b/packages/eslint-plugin-svelte/src/rule-types.ts index 8b7cbe80c..71eae844b 100644 --- a/packages/eslint-plugin-svelte/src/rule-types.ts +++ b/packages/eslint-plugin-svelte/src/rule-types.ts @@ -264,6 +264,11 @@ export interface RuleOptions { * @see https://sveltejs.github.io/eslint-plugin-svelte/rules/prefer-class-directive/ */ 'svelte/prefer-class-directive'?: Linter.RuleEntry + /** + * Require `const` declarations for variables that are never reassigned after declared + * @see https://sveltejs.github.io/eslint-plugin-svelte/rules/prefer-const/ + */ + 'svelte/prefer-const'?: Linter.RuleEntry /** * destructure values from object stores for better change tracking & fewer redraws * @see https://sveltejs.github.io/eslint-plugin-svelte/rules/prefer-destructured-store-props/ @@ -485,6 +490,11 @@ type SvelteNoUselessMustaches = []|[{ type SveltePreferClassDirective = []|[{ prefer?: ("always" | "empty") }] +// ----- svelte/prefer-const ----- +type SveltePreferConst = []|[{ + destructuring?: ("any" | "all") + ignoreReadBeforeAssign?: boolean +}] // ----- svelte/shorthand-attribute ----- type SvelteShorthandAttribute = []|[{ prefer?: ("always" | "never")