Repository: nodejs/node
Pull request: tools: add eslint-plugin-regexp

<!--
Before submitting a pull request, please read:

- the CONTRIBUTING guide at https://github.com/nodejs/node/blob/HEAD/CONTRIBUTING.md
- the commit message formatting guidelines at
  https://github.com/nodejs/node/blob/HEAD/doc/contributing/pull-requests.md#commit-message-guidelines

For code changes:
1. Include tests for any bug fixes or new features.
2. Update documentation if relevant.
3. Ensure that `make -j4 test` (UNIX), or `vcbuild test` (Windows) passes.

If you believe this PR should be highlighted in the Node.js CHANGELOG
please add the `notable-change` label.

Developer's Certificate of Origin 1.1

By making a contribution to this project, I certify that:

(a) The contribution was created in whole or in part by me and I
    have the right to submit it under the open source license
    indicated in the file; or

(b) The contribution is based upon previous work that, to the best
    of my knowledge, is covered under an appropriate open source
    license and I have the right under that license to submit that
    work with modifications, whether created in whole or in part
    by me, under the same open source license (unless I am
    permitted to submit under a different license), as indicated
    in the file; or

(c) The contribution was provided directly to me by some other
    person who certified (a), (b) or (c) and I have not modified
    it.

(d) I understand and agree that this project and the contribution
    are public and that a record of the contribution (including all
    personal information I submit with it, including my sign-off) is
    maintained indefinitely and may be redistributed consistent with
    this project or the open source license(s) involved.
-->
In this PR we add `eslint-plugin-regexp` and its recommended rule set to the current lint rule. To seek consensus on whether we should use this plugin, we have disabled all rules which the current codebase does not meet, so there is no change in the current codebase. I plan to enable some of them in the near future if we agree to add this eslint plugin.

Changed files:
filename: eslint.config.mjs
patch: @@ -20,6 +20,7 @@ const { default: js } = await importEslintTool('@eslint/js');
 const { default: babelEslintParser } = await importEslintTool('@babel/eslint-parser');
 const babelPluginSyntaxImportSource = resolveEslintTool('@babel/plugin-syntax-import-source');
 const { default: jsdoc } = await importEslintTool('eslint-plugin-jsdoc');
+const { default: regexpPlugin } = await importEslintTool('eslint-plugin-regexp');
 const { default: markdown } = await importEslintTool('@eslint/markdown');
 const { default: stylisticJs } = await importEslintTool('@stylistic/eslint-plugin');
 
@@ -84,6 +85,7 @@ export default [
   // #region general config
   js.configs.recommended,
   jsdoc.configs['flat/recommended'],
+  regexpPlugin.configs.recommended,
   {
     files: ['**/*.js'],
     languageOptions: {
@@ -275,6 +277,42 @@ export default [
       'jsdoc/reject-any-type': 'off',
       'jsdoc/reject-function-type': 'off',
 
+      // RegExp recommended rules that we disable.
+      // Todo: Investigate which rules should be enabled.
+      'prefer-regex-literals': 'off',
+      'regexp/control-character-escape': 'off',
+      'regexp/match-any': 'off',
+      'regexp/negation': 'off',
+      'regexp/no-contradiction-with-assertion': 'off',
+      'regexp/no-dupe-characters-character-class': 'off',
+      'regexp/no-dupe-disjunctions': 'off',
+      'regexp/no-empty-alternative': 'off',
+      'regexp/no-legacy-features': 'off',
+      'regexp/no-misleading-capturing-group': 'off',
+      'regexp/no-obscure-range': 'off',
+      'regexp/no-potentially-useless-backreference': 'off',
+      'regexp/no-super-linear-backtracking': 'off',
+      'regexp/no-trivially-nested-quantifier': 'off',
+      'regexp/no-unused-capturing-group': 'off',
+      'regexp/no-useless-assertions': 'off',
+      'regexp/no-useless-character-class': 'off',
+      'regexp/no-useless-escape': 'off',
+      'regexp/no-useless-flag': 'off',
+      'regexp/no-useless-lazy': 'off',
+      'regexp/no-useless-non-capturing-group': 'off',
+      'regexp/no-useless-quantifier': 'off',
+      'regexp/no-useless-range': 'off',
+      'regexp/optimal-lookaround-quantifier': 'off',
+      'regexp/optimal-quantifier-concatenation': 'off',
+      'regexp/prefer-character-class': 'off',
+      'regexp/prefer-d': 'off',
+      'regexp/prefer-question-quantifier': 'off',
+      'regexp/prefer-star-quantifier': 'off',
+      'regexp/prefer-w': 'off',
+      'regexp/sort-flags': 'off',
+      'regexp/strict': 'off',
+      'regexp/use-ignore-case': 'off',
+
       // Stylistic rules.
       '@stylistic/js/arrow-parens': 'error',
       '@stylistic/js/arrow-spacing': 'error',

filename: tools/eslint/package-lock.json
patch: @@ -17,6 +17,7 @@
         "eslint": "^10.0.2",
         "eslint-formatter-tap": "^9.0.1",
         "eslint-plugin-jsdoc": "^62.7.1",
+        "eslint-plugin-regexp": "^3.0.0",
         "globals": "^17.3.0"
       }
     },
@@ -47,6 +48,7 @@
       "resolved": "https://registry.npmjs.org/@babel/core/-/core-8.0.0-rc.2.tgz",
       "integrity": "sha512-mlBJdKJJEZNGDE+w+P6B5w+FTMkht1liPkxtB4wk39EpGH01Am5tg1htaNlOU5rO9Ge3psMjAFycpc3ru5uaQw==",
       "license": "MIT",
+      "peer": true,
       "dependencies": {
         "@babel/code-frame": "^8.0.0-rc.2",
         "@babel/generator": "^8.0.0-rc.2",
@@ -662,6 +664,7 @@
       "resolved": "https://registry.npmjs.org/acorn/-/acorn-8.16.0.tgz",
       "integrity": "sha512-UVJyE9MttOsBQIDKw1skb9nAwQuR5wuGD3+82K6JgJlm/Y+KI92oNsMNGZCYdDsVtRHSak0pcV5Dno5+4jh9sw==",
       "license": "MIT",
+      "peer": true,
       "bin": {
         "acorn": "bin/acorn"
       },
@@ -761,6 +764,7 @@
         }
       ],
       "license": "MIT",
+      "peer": true,
       "dependencies": {
         "baseline-browser-mapping": "^2.9.0",
         "caniuse-lite": "^1.0.30001759",
@@ -934,6 +938,7 @@
       "resolved": "https://registry.npmjs.org/eslint/-/eslint-10.0.2.tgz",
       "integrity": "sha512-uYixubwmqJZH+KLVYIVKY1JQt7tysXhtj21WSvjcSmU5SVNzMus1bgLe+pAt816yQ8opKfheVVoPLqvVMGejYw==",
       "license": "MIT",
+      "peer": true,
       "dependencies": {
         "@eslint-community/eslint-utils": "^4.8.0",
         "@eslint-community/regexpp": "^4.12.2",
@@ -1041,6 +1046,27 @@
         "url": "https://opencollective.com/eslint"
       }
     },
+    "node_modules/eslint-plugin-regexp": {
+      "version": "3.0.0",
+      "resolved": "https://registry.npmjs.org/eslint-plugin-regexp/-/eslint-plugin-regexp-3.0.0.tgz",
+      "integrity": "sha512-iW7hgAV8NOG6E2dz+VeKpq67YLQ9jaajOKYpoOSic2/q8y9BMdXBKkSR9gcMtbqEhNQzdW41E3wWzvhp8ExYwQ==",
+      "license": "MIT",
+      "dependencies": {
+        "@eslint-community/eslint-utils": "^4.2.0",
+        "@eslint-community/regexpp": "^4.11.0",
+        "comment-parser": "^1.4.0",
+        "jsdoc-type-pratt-parser": "^7.0.0",
+        "refa": "^0.12.1",
+        "regexp-ast-analysis": "^0.7.1",
+        "scslre": "^0.3.0"
+      },
+      "engines": {
+        "node": "^20.19.0 || ^22.13.0 || >=24"
+      },
+      "peerDependencies": {
+        "eslint": ">=9.38.0"
+      }
+    },
     "node_modules/eslint-scope": {
       "version": "9.1.1",
       "resolved": "https://registry.npmjs.org/eslint-scope/-/eslint-scope-9.1.1.tgz",
@@ -2490,6 +2516,31 @@
         "node": ">=6"
       }
     },
+    "node_modules/refa": {
+      "version": "0.12.1",
+      "resolved": "https://registry.npmjs.org/refa/-/refa-0.12.1.tgz",
+      "integrity": "sha512-J8rn6v4DBb2nnFqkqwy6/NnTYMcgLA+sLr0iIO41qpv0n+ngb7ksag2tMRl0inb1bbO/esUwzW1vbJi7K0sI0g==",
+      "license": "MIT",
+      "dependencies": {
+        "@eslint-community/regexpp": "^4.8.0"
+      },
+      "engines": {
+        "node": "^12.0.0 || ^14.0.0 || >=16.0.0"
+      }
+    },
+    "node_modules/regexp-ast-analysis": {
+      "version": "0.7.1",
+      "resolved": "https://registry.npmjs.org/regexp-ast-analysis/-/regexp-ast-analysis-0.7.1.tgz",
+      "integrity": "sha512-sZuz1dYW/ZsfG17WSAG7eS85r5a0dDsvg+7BiiYR5o6lKCAtUrEwdmRmaGF6rwVj3LcmAeYkOWKEPlbPzN3Y3A==",
+      "license": "MIT",
+      "dependencies": {
+        "@eslint-community/regexpp": "^4.8.0",
+        "refa": "^0.12.1"
+      },
+      "engines": {
+        "node": "^12.0.0 || ^14.0.0 || >=16.0.0"
+      }
+    },
     "node_modules/reserved-identifiers": {
       "version": "1.2.0",
       "resolved": "https://registry.npmjs.org/reserved-identifiers/-/reserved-identifiers-1.2.0.tgz",
@@ -2502,6 +2553,20 @@
         "url": "https://github.com/sponsors/sindresorhus"
       }
     },
+    "node_modules/scslre": {
+      "version": "0.3.0",
+      "resolved": "https://registry.npmjs.org/scslre/-/scslre-0.3.0.tgz",
+      "integrity": "sha512-3A6sD0WYP7+QrjbfNA2FN3FsOaGGFoekCVgTyypy53gPxhbkCIjtO6YWgdrfM+n/8sI8JeXZOIxsHjMTNxQ4nQ==",
+      "license": "MIT",
+      "dependencies": {
+        "@eslint-community/regexpp": "^4.8.0",
+        "refa": "^0.12.0",
+        "regexp-ast-analysis": "^0.7.0"
+      },
+      "engines": {
+        "node": "^14.0.0 || >=16.0.0"
+      }
+    },
     "node_modules/semver": {
       "version": "7.7.4",
       "resolved": "https://registry.npmjs.org/semver/-/semver-7.7.4.tgz",

filename: tools/eslint/package.json
patch: @@ -12,6 +12,7 @@
     "eslint": "^10.0.2",
     "eslint-formatter-tap": "^9.0.1",
     "eslint-plugin-jsdoc": "^62.7.1",
+    "eslint-plugin-regexp": "^3.0.0",
     "globals": "^17.3.0"
   }
 }