Skip to content
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

no-invalid-regexp: Make allowConstructorFlags option case sensitive #16574

Closed
1 task done
trosos opened this issue Nov 23, 2022 · 7 comments · Fixed by #17533
Closed
1 task done

no-invalid-regexp: Make allowConstructorFlags option case sensitive #16574

trosos opened this issue Nov 23, 2022 · 7 comments · Fixed by #17533
Assignees
Labels
accepted There is consensus among the team that this change meets the criteria for inclusion breaking This change is backwards-incompatible enhancement This change enhances an existing feature of ESLint rule Relates to ESLint's core rules

Comments

@trosos
Copy link
Contributor

trosos commented Nov 23, 2022

Hi,

The allowConstructorFlags option of the no-invalid-regexp rule is case insensitive.
I believe that the option should be treated as case sensitive (because regexp flags are case sensitive).

What rule do you want to change?

no-invalid-regexp

What change to do you want to make?

Generate more warnings

How do you think the change should be implemented?

A new default behavior

Example code

const ESLint = require("eslint");
console.log(new ESLint.Linter().verify(
  'RegExp(".", "A");',
  { rules: { "no-invalid-regexp": [1,
    { allowConstructorFlags: ["a"] }
  ] } }
));

What does the rule currently do for this code?

The rule treats the option as case insensitive, and reports no issues.

What will the rule do after it's changed?

The rule should IMO report invalid flag.

Participation

  • I am willing to submit a pull request to implement this change.

Additional comments

No response

@trosos trosos added enhancement This change enhances an existing feature of ESLint rule Relates to ESLint's core rules labels Nov 23, 2022
@eslint-github-bot eslint-github-bot bot added this to Needs Triage in Triage Nov 23, 2022
@mdjermanovic mdjermanovic moved this from Needs Triage to Triaging in Triage Nov 23, 2022
@mdjermanovic
Copy link
Member

I'm not sure why this option was made to be case-insensitive. There's no mention of this in #5352 or #5249.

By looking at the changes from #5352, it seems intentional as the regex that processes the option has the i flag, and there was this test: { code: "new RegExp('.', 'u')", options: [{ allowConstructorFlags: ["U"] }]}. The test was later accidentally removed in 672deb0.

I agree that this option should be case-sensitive, so that allowConstructorFlags: ["a"] does not allow RegExp(".", "A"), and that allowConstructorFlags: ["A"] does not allow RegExp(".", "a"). This change might be problematic though, as it might require some users to change their eslint configs and could be said to fall under "Major release > Part of the public API is removed or changed in an incompatible way > Rule schemas" in our semver policy.

Since this was apparently intentional, I'd like more input from the team on whether we should make this change (any ideas why this option is case-insensitive?) and whether we can treat it as a semver-minor bug fix.

@mdjermanovic mdjermanovic moved this from Triaging to Feedback Needed in Triage Nov 24, 2022
@github-actions
Copy link

Oops! It looks like we lost track of this issue. What do we want to do here? This issue will auto-close in 7 days without an update.

@github-actions github-actions bot added the Stale label Jan 23, 2023
@snitin315
Copy link
Contributor

I'm 👍🏻 on this proposal as I also feel it should be case-sensitive. This would be a breaking change definitely so it should fall under the next major release.

@snitin315 snitin315 removed the Stale label Jan 24, 2023
@github-actions
Copy link

Oops! It looks like we lost track of this issue. What do we want to do here? This issue will auto-close in 7 days without an update.

@github-actions github-actions bot added the Stale label Feb 23, 2023
@snitin315
Copy link
Contributor

Marking this as accepted and adding it to the v9 board for tracking.

@snitin315 snitin315 added accepted There is consensus among the team that this change meets the criteria for inclusion breaking This change is backwards-incompatible and removed Stale labels Feb 24, 2023
@snitin315 snitin315 added this to Need Discussion in v9.0.0 Feb 24, 2023
@mdjermanovic mdjermanovic changed the title no-invalid-regexp: Make allowConstructorFlags option case sensitive Fix rule schemas Apr 1, 2023
@mdjermanovic
Copy link
Member

mdjermanovic commented Apr 1, 2023

In no-constructor-return, instead of schema: {} it should be schema: [].

For example, "no-constructor-return": ["error", "foo"] should cause a validation error.

Edit: please disregard, I updated wrong issue.

@mdjermanovic mdjermanovic changed the title Fix rule schemas no-invalid-regexp: Make allowConstructorFlags option case sensitive Apr 2, 2023
@JoshuaKGoldberg
Copy link
Contributor

#17533 is ready for review. Marked as draft for now as it's a breaking change.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
accepted There is consensus among the team that this change meets the criteria for inclusion breaking This change is backwards-incompatible enhancement This change enhances an existing feature of ESLint rule Relates to ESLint's core rules
Projects
Archived in project
Status: Done
Triage
Feedback Needed
v9.0.0
Need Discussion
Development

Successfully merging a pull request may close this issue.

4 participants