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

False positive for at least no-useless-non-capturing-group when required inside new RegExp() #793

Open
adamlui opened this issue Dec 17, 2024 · 0 comments

Comments

@adamlui
Copy link
Contributor

adamlui commented Dec 17, 2024

Information:

  • ESLint version: 9.17.0
  • eslint-plugin-regexp version: 2.7.0

Description

Here https://github.com/adamlui/ai-web-extensions/blob/2e1cc309a53bf59fec003f9290a1a49745be1e6e/utils/bump/js-resources.js#L104:

const reResourceURL = new RegExp(`(?:${rePatterns.cssURL.source})|(?:${rePatterns.jsURL.source})`, 'gm')

... your plugin will falsely warn Unexpected unnecessary non-capturing group. This group can be removed without changing the behaviour of the regex but it's required because the patterns defined earlier are:

const rePatterns = {
...
    cssURL: /^\/\/ @resource.+(https:\/\/assets.+\.css.+)$/gm,
    jsURL: /^\/\/ @require\s+(https:\/\/cdn\.jsdelivr\.net\/gh\/.+$)/gm,
...
}

... so without the grouping (capturing or not) the pipe will compare differently if pre-defined entire patterns weren't wholly grouped already (as in above examples)

I think probably other rules will false positive too since it looks like your plugin doesn't construct new RegExp() before linting to gather the context required for determining truly useless things

adamlui added a commit to adamlui/ai-web-extensions that referenced this issue Dec 17, 2024
adamlui pushed a commit to adamlui/chatgpt-widescreen that referenced this issue Dec 17, 2024
adamlui pushed a commit to adamlui/chatgpt-infinity that referenced this issue Dec 17, 2024
adamlui pushed a commit to adamlui/chatgpt-auto-continue that referenced this issue Dec 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant