Skip to content

Commit a2ee188

Browse files
fix!: add uniqueItems: true in no-invalid-regexp option (#20155)
* feat: enable unique items in allowConstructorFlags * remove test with duplicate option * add migration guide for this change * Update docs/src/use/migrate-to-10.0.0.md Co-authored-by: 루밀LuMir <rpfos@naver.com> --------- Co-authored-by: 루밀LuMir <rpfos@naver.com>
1 parent a89059d commit a2ee188

3 files changed

Lines changed: 16 additions & 13 deletions

File tree

docs/src/use/migrate-to-10.0.0.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ The lists below are ordered roughly by the number of users each change is expect
2323
- [Jiti < v2.2.0 are no longer supported](#drop-old-jiti)
2424
- [`eslint-env` comments are reported as errors](#eslint-env-comments)
2525
- [`func-names` schema is stricter](#func-names)
26+
- [`allowConstructorFlags` option of `no-invalid-regexp` now accepts only unique items](#no-invalid-regexp)
2627

2728
### Breaking changes for plugin developers
2829

@@ -206,3 +207,17 @@ For example, this configuration is now invalid due to the extra element `"foo"`:
206207
- optionally, an object option: `{ "generators": "always" | "as-needed" | "never" }`.
207208

208209
**Related issue(s):** [#20134](https://github.com/eslint/eslint/issues/20134)
210+
211+
## <a name="no-invalid-regexp"></a> `allowConstructorFlags` option of `no-invalid-regexp` now accepts only unique items
212+
213+
In ESLint v10, the `allowConstructorFlags` option of `no-invalid-regexp` no longer accepts duplicate flags as input. Previously, configurations with duplicate flags in the array were accepted but treated the same as having unique flags. Such configurations are now considered invalid and will result in a configuration error.
214+
215+
For example, this configuration is now invalid due to the duplicate `"u"` flag:
216+
217+
```js
218+
/*eslint no-invalid-regexp: ["error", { "allowConstructorFlags": ["u", "y", "u"] }]*/
219+
```
220+
221+
**To address:** Remove any duplicate flags from your `allowConstructorFlags` array configuration of `no-invalid-regexp` rule. Each flag should appear only once in the array.
222+
223+
**Related issue(s):** [#18755](https://github.com/eslint/eslint/issues/18755)

lib/rules/no-invalid-regexp.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ module.exports = {
4040
items: {
4141
type: "string",
4242
},
43+
uniqueItems: true,
4344
},
4445
},
4546
additionalProperties: false,

tests/lib/rules/no-invalid-regexp.js

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -262,19 +262,6 @@ ruleTester.run("no-invalid-regexp", rule, {
262262
},
263263
],
264264
},
265-
{
266-
code: "new RegExp('.', 'aa');",
267-
options: [{ allowConstructorFlags: ["a", "a"] }],
268-
errors: [
269-
{
270-
messageId: "regexMessage",
271-
data: {
272-
message:
273-
"Duplicate flags ('a') supplied to RegExp constructor",
274-
},
275-
},
276-
],
277-
},
278265
{
279266
code: "new RegExp('.', 'aA');",
280267
options: [{ allowConstructorFlags: ["a"] }],

0 commit comments

Comments
 (0)