Skip to content

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

@adamlui

Description

@adamlui

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions