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

rule prefer-named-capture-group should only be effective for ES9+ #14959

Closed
erwindon opened this issue Aug 21, 2021 · 1 comment
Closed

rule prefer-named-capture-group should only be effective for ES9+ #14959

erwindon opened this issue Aug 21, 2021 · 1 comment
Labels
archived due to age This issue has been archived; please open a new issue for any further discussion enhancement This change enhances an existing feature of ESLint rule Relates to ESLint's core rules
Projects

Comments

@erwindon
Copy link

erwindon commented Aug 21, 2021

What rule do you want to change?
prefer-named-capture-group

Does this change cause the rule to produce more or fewer warnings?
fewer warnings

How will the change be implemented? (New option, new default behaviour, etc.)?
new default behaviour

Please provide some example code that this change will affect:
use a replace statement with a numeric group reference in its replace pattern while using ES6 or any other ES version 1..8.

"kjhgghgh".replace(/xxx(yyy)zzz/, "aaa$1bbb")

This will raise Capture group '(yyy)' should be converted to a named or non-capturing group, but named groups are not supported in ES6 and a non-capturing group is useless in this context.

The use of ES6 was indicated by setting eslintConfig.parserOptions.ecmaVersion to 6 in package.json.

What does the rule currently do for this code?
The current rule currently suggests to use named capture groups, even while using an ES version where that is not supported.

What will the rule do after it's changed?
It will not report this for ES 1..8

Are you willing to submit a pull request to implement this change?
no, as I'm not skilled in the inner structure/workings of eslint.

@erwindon erwindon added enhancement This change enhances an existing feature of ESLint rule Relates to ESLint's core rules triage An ESLint team member will look at this issue soon labels Aug 21, 2021
@eslint-github-bot eslint-github-bot bot added this to Needs Triage in Triage Aug 21, 2021
@mdjermanovic mdjermanovic moved this from Needs Triage to Triaging in Triage Aug 21, 2021
@mdjermanovic mdjermanovic removed the triage An ESLint team member will look at this issue soon label Aug 21, 2021
@mdjermanovic
Copy link
Member

Hi @erwindon, thanks for the issue!

The use of ES6 was indicated by setting eslintConfig.parserOptions.ecmaVersion to 6 in package.json.

ESLint can be used with third-party parsers that have different defaults, or even don't have ecmaVersion as a parser option, so we aim to avoid using parserOptions.ecmaVersion for auto-disabling or altering the logic of rules because it isn't reliable.

This will raise Capture group '(yyy)' should be converted to a named or non-capturing group, but named groups are not supported in ES6 and a non-capturing group is useless in this context.

The solution is to disable this rule, as recommended in the documentation:

If you are targeting ECMAScript 2017 and/or older environments, you can disable this rule, because this ECMAScript feature is only supported in ECMAScript 2018 and/or newer environments.

(we should change the wording from "you can disable" to "you should disable").

I'm closing this issue as we have already decided on not making these kinds of changes (e.g., #12624 was a similar proposal).

Triage automation moved this from Triaging to Complete Aug 21, 2021
@eslint-github-bot eslint-github-bot bot locked and limited conversation to collaborators Feb 18, 2022
@eslint-github-bot eslint-github-bot bot added the archived due to age This issue has been archived; please open a new issue for any further discussion label Feb 18, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
archived due to age This issue has been archived; please open a new issue for any further discussion enhancement This change enhances an existing feature of ESLint rule Relates to ESLint's core rules
Projects
Archived in project
Triage
Complete
Development

No branches or pull requests

2 participants