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 Change: prefer-named-capture-group: add suggestion fixer #16530

Closed
1 task done
JoshuaKGoldberg opened this issue Nov 9, 2022 · 2 comments · Fixed by #16544
Closed
1 task done

Rule Change: prefer-named-capture-group: add suggestion fixer #16530

JoshuaKGoldberg opened this issue Nov 9, 2022 · 2 comments · Fixed by #16544
Labels
accepted There is consensus among the team that this change meets the criteria for inclusion 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

@JoshuaKGoldberg
Copy link
Contributor

What rule do you want to change?

prefer-named-capture-group

What change to do you want to make?

Implement suggestions

How do you think the change should be implemented?

A new default behavior

Example code

function toTextContentTitle(contentTitle: string): string {
  return contentTitle.replace(/`([^`]*)`/gi, '$1');
}

What does the rule currently do for this code?

It reports a complaint on the regular expression: /([^]*)/gi`

Capture group '([^`]*)' should be converted to a named or non-capturing group.

What will the rule do after it's changed?

In addition, it'd be nice to also provide a suggestion fixer that uses some arbitrary names for the suggestion group. Maybe: temp1, temp2, etc.?

Participation

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

Additional comments

Named capture groups are pretty new and many developers (myself included!) don't know the syntax on demand. Even if they do, it's just nice to have a suggestion when there's a non-trivial complaint to fix.

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

Makes sense to me, but would like more opinions from the team as this would be the first core rule suggestion that requires additional user action (renaming temp1 to a meaningful name) after it's applied.

Alternatively, we could provide an example of the syntax in the error message.

@mdjermanovic mdjermanovic moved this from Triaging to Feedback Needed in Triage Nov 10, 2022
@snitin315
Copy link
Contributor

I'm in favor of providing a suggestion fix 👍🏻

@mdjermanovic I suppose it won't be the first one, we recently added similar suggestions for the no-empty rule in #16470 that would also require additional action (modifying/* empty */ comment) after it's applied.

@snitin315 snitin315 added the accepted There is consensus among the team that this change meets the criteria for inclusion label Nov 11, 2022
@snitin315 snitin315 moved this from Feedback Needed to Ready to Implement in Triage Nov 11, 2022
Triage automation moved this from Ready to Implement to Complete Nov 27, 2022
@eslint-github-bot eslint-github-bot bot locked and limited conversation to collaborators May 27, 2023
@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 May 27, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
accepted There is consensus among the team that this change meets the criteria for inclusion 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

Successfully merging a pull request may close this issue.

3 participants