Skip to content

fix(prefer-const): Use additionalProperties instead of ignoreReadonly to match the ESLint core rule option name #1239

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Jun 1, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/good-carrots-notice.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'eslint-plugin-svelte': patch
---

fix(prefer-const): Use `additionalProperties` instead of `ignoreReadonly` to match the ESLint core rule option name.
10 changes: 5 additions & 5 deletions docs/rules/prefer-const.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,22 +46,22 @@ 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"]
}
]
}
```

- `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

Expand Down
1 change: 1 addition & 0 deletions packages/eslint-plugin-svelte/src/rule-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -573,6 +573,7 @@ type SveltePreferConst = []|[{
destructuring?: ("any" | "all")
ignoreReadBeforeAssign?: boolean
excludedRunes?: string[]
[k: string]: unknown | undefined
}]
// ----- svelte/require-event-prefix -----
type SvelteRequireEventPrefix = []|[{
Expand Down
3 changes: 2 additions & 1 deletion packages/eslint-plugin-svelte/src/rules/prefer-const.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
]
},
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"options": [
{
"destructuring": "all",
"additionalProperties": true
}
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
123
Loading