Skip to content

regexp/no-useless-non-capturing-group

💼 This rule is enabled in the following configs: 🟢 flat/recommended, 🔵 recommended.

🔧 This rule is automatically fixable by the --fix CLI option.

disallow unnecessary non-capturing group

📖 Rule Details

This rule reports unnecessary non-capturing groups. Unnecessary groups are just clutter that make regexes harder to read, so they should be removed.

Now loading...

🔧 Options

json5
{
  "regexp/no-useless-non-capturing-group": ["error", {
    "allowTop": "partial" // or "always" or "never"
  }]
}
  • "allowTop": Whether a top-level non-capturing group is allowed (e.g. /(?:foo|bar)/). Defaults to "partial".

    Sometimes it's useful to wrap a whole pattern into a non-capturing group (e.g. when the pattern is used as a building block to construct more complex patterns). Use this option to allow top-level non-capturing groups.

    • "partial": Allows top-level non-capturing groups of patterns used as strings via .source.

      Now loading...
    • "always": Always allow top-level non-capturing groups.

      Now loading...
    • "never": Never allow top-level non-capturing groups.

      Now loading...

🚀 Version

This rule was introduced in eslint-plugin-regexp v0.4.0

🔍 Implementation