Repository: ota-meshi/eslint-plugin-regexp (ts)

Issue:
Change default configuration of `prefer-d`
I just added `eslint-plugin-regexp` to a code base with some regexes and [the `prefer-d` rule](https://ota-meshi.github.io/eslint-plugin-regexp/rules/prefer-d.html) wanted to replace all character classes like this `[0-9a-f]` with this `[\da-f]`. While I think that `prefer-d` has a place in our `recommended` config, but I think it's too aggressive by default. `[0-9a-f]` -> `[\da-f]` is a minor stylistic change to enforce consistency, but it will increase the diff for existing code bases and it won't improve the readability. Since `0-9` is relatively common from what I've seen, `prefer-d` currently causes a lot of noise for little gain.

So I think it might be a good idea to change the default configuration of `prefer-d` from `insideCharacterClass: "d"` to `insideCharacterClass: "ignore"`. This would still transform `[0-9]` -> `\d` but it will leave `[0-9a-f]` and `[\da-f]` as is. 

With this change, `prefer-d` will report strictly fewer errors, so this is a minor change according to ESLint's semver policy.

What do you think @ota-meshi?

Pull request:
Change default configuration of `prefer-d`
Closes #712

Patch:
diff --git a/.changeset/shaggy-lemons-suffer.md b/.changeset/shaggy-lemons-suffer.md
new file mode 100644
index 0000000..4d47288
--- /dev/null
+++ b/.changeset/shaggy-lemons-suffer.md
@@ -0,0 +1,5 @@
+---
+"eslint-plugin-regexp": minor
+---
+
+Change default configuration of `prefer-d` to ignore digits inside character classes.
diff --git a/docs/rules/prefer-d.md b/docs/rules/prefer-d.md
index eeb54b5..1546cd7 100644
--- a/docs/rules/prefer-d.md
+++ b/docs/rules/prefer-d.md
@@ -55,7 +55,7 @@ This option control how character class element equivalent to `\d` will be treat
 *Note:* This option does not affect character classes equivalent to `\d`. E.g. `[\d]`, `[0-9]`, and `[0123456789]` are unaffected.
 It also does not affect expression non-nested operands equivalent to `\d`. E.g. `[\d&&x]`, and `[\d--x]` are unaffected.
 
-- `insideCharacterClass: "d"` (*default*)
+- `insideCharacterClass: "d"`
 
   Character class element equivalent to `\d` will be reported and replaced with `\d`.
 
@@ -98,7 +98,7 @@ It also does not affect expression non-nested operands equivalent to `\d`. E.g.
 
   </eslint-code-block>
 
-- `insideCharacterClass: "ignore"`
+- `insideCharacterClass: "ignore"` (*default*)
 
   Character class element will not be reported.
 
diff --git a/lib/rules/prefer-d.ts b/lib/rules/prefer-d.ts
index 2e99f9b..c487fde 100644
--- a/lib/rules/prefer-d.ts
+++ b/lib/rules/prefer-d.ts
@@ -60,7 +60,7 @@ export default createRule("prefer-d", {
     },
     create(context) {
         const insideCharacterClass: "ignore" | "range" | "d" =
-            context.options[0]?.insideCharacterClass ?? "d"
+            context.options[0]?.insideCharacterClass ?? "ignore"
 
         function createVisitor({
             node,
diff --git a/package-lock.json b/package-lock.json
index f7b6661..86e0712 100644
--- a/package-lock.json
+++ b/package-lock.json
@@ -40,7 +40,7 @@
                 "eslint-plugin-eslint-comments": "^3.2.0",
                 "eslint-plugin-eslint-plugin": "^5.2.1",
                 "eslint-plugin-import": "^2.29.1",
-                "eslint-plugin-json-schema-validator": "^4.6.1",
+                "eslint-plugin-json-schema-validator": "^5.0.0",
                 "eslint-plugin-jsonc": "^2.0.0",
                 "eslint-plugin-n": "^16.0.0",
                 "eslint-plugin-prettier": "^5.0.0",
@@ -2870,6 +2870,18 @@
                 "node": ">=14"
             }
         },
+        "node_modules/@pkgr/core": {
+            "version": "0.1.1",
+            "resolved": "https://registry.npmjs.org/@pkgr/core/-/core-0.1.1.tgz",
+            "integrity": "sha512-cq8o4cWH0ibXh9VGi5P20Tu9XF/0fFXl9EUinr9QfTM7a7p0oTA4iJRCQWppXR1Pg8dSM0UCItCkPwsk9qWWYA==",
+            "dev": true,
+            "engines": {
+                "node": "^12.20.0 || ^14.18.0 || >=16.0.0"
+            },
+            "funding": {
+                "url": "https://opencollective.com/unts"
+            }
+        },
         "node_modules/@pkgr/utils": {
             "version": "2.3.1",
             "resolved": "https://registry.npmjs.org/@pkgr/utils/-/utils-2.3.1.tgz",
@@ -5751,6 +5763,21 @@
                 "url": "https://opencollective.com/eslint"
             }
         },
+        "node_modules/eslint-compat-utils": {
+            "version": "0.5.0",
+            "resolved": "https://registry.npmjs.org/eslint-compat-utils/-/eslint-compat-utils-0.5.0.tgz",
+            "integrity": "sha512-dc6Y8tzEcSYZMHa+CMPLi/hyo1FzNeonbhJL7Ol0ccuKQkwopJcJBA9YL/xmMTLU1eKigXo9vj9nALElWYSowg==",
+            "dev": true,
+            "dependencies": {
+                "semver": "^7.5.4"
+            },
+            "engines": {
+                "node": ">=12"
+            },
+            "peerDependencies": {
+                "eslint": ">=6.0.0"
+            }
+        },
         "node_modules/eslint-config-prettier": {
             "version": "9.0.0",
             "resolved": "https://registry.npmjs.org/eslint-config-prettier/-/eslint-config-prettier-9.0.0.tgz",
@@ -6102,19 +6129,20 @@
             }
         },
         "node_modules/eslint-plugin-json-schema-validator": {
-            "version": "4.6.1",
-            "resolved": "https://registry.npmjs.org/eslint-plugin-json-schema-validator/-/eslint-plugin-json-schema-validator-4.6.1.tgz",
-            "integrity": "sha512-xzPnXOyWFc9Vs33Pt0WraQfDKJwa6wH11Z9s2XhtLQRMrj50hUgekG6CFWJigitbGLCHjRtY4Hy+dZMrzk40mg==",
+            "version": "5.0.0",
+            "resolved": "https://registry.npmjs.org/eslint-plugin-json-schema-validator/-/eslint-plugin-json-schema-validator-5.0.0.tgz",
+            "integrity": "sha512-62CVUvUsilCK06vGAZxcDmUH8Zz3clPkPyHq8QwQ6dUJT6JaM+VllJqpgAqvHXy0cE/eZGIsWF2miK5bLy6HDg==",
             "dev": true,
             "dependencies": {
                 "@eslint-community/eslint-utils": "^4.3.0",
                 "ajv": "^8.0.0",
                 "debug": "^4.3.1",
+                "eslint-compat-utils": "^0.5.0",
                 "json-schema-migrate": "^2.0.0",
                 "jsonc-eslint-parser": "^2.0.0",
                 "minimatch": "^8.0.0",
-                "synckit": "^0.8.0",
-                "toml-eslint-parser": "^0.6.0",
+                "synckit": "^0.9.0",
+                "toml-eslint-parser": "^0.9.0",
                 "tunnel-agent": "^0.6.0",
                 "yaml-eslint-parser": "^1.0.0"
             },
@@ -6129,9 +6157,9 @@
             }
         },
         "node_modules/eslint-plugin-json-schema-validator/node_modules/ajv": {
-            "version": "8.11.0",
-            "resolved": "https://registry.npmjs.org/ajv/-/ajv-8.11.0.tgz",
-            "integrity": "sha512-wGgprdCvMalC0BztXvitD2hC04YffAvtsUn93JbGXYLAtCUO4xd17mCCZQxUOItiBwZvJScWo8NIvQMQ71rdpg==",
+            "version": "8.12.0",
+            "resolved": "https://registry.npmjs.org/ajv/-/ajv-8.12.0.tgz",
+            "integrity": "sha512-sRu1kpcO9yLtYxBKvqfTeh9KzZEwO3STyX1HT+4CaDzC6HpTGYhIhPIzj9XuKU7KYDwnaeh5hcOwjy1QuJzBPA==",
             "dev": true,
             "dependencies": {
                 "fast-deep-equal": "^3.1.1",
@@ -6174,6 +6202,22 @@
                 "url": "https://github.com/sponsors/isaacs"
             }
         },
+        "node_modules/eslint-plugin-json-schema-validator/node_modules/synckit": {
+            "version": "0.9.0",
+            "resolved": "https://registry.npmjs.org/synckit/-/synckit-0.9.0.tgz",
+            "integrity": "sha512-7RnqIMq572L8PeEzKeBINYEJDDxpcH8JEgLwUqBd3TkofhFRbkq4QLR0u+36avGAhCRbk2nnmjcW9SE531hPDg==",
+            "dev": true,
+            "dependencies": {
+                "@pkgr/core": "^0.1.0",
+                "tslib": "^2.6.2"
+            },
+            "engines": {
+                "node": "^14.18.0 || >=16.0.0"
+            },
+            "funding": {
+                "url": "https://opencollective.com/unts"
+            }
+        },
         "node_modules/eslint-plugin-jsonc": {
             "version": "2.5.0",
             "resolved": "https://registry.npmjs.org/eslint-plugin-jsonc/-/eslint-plugin-jsonc-2.5.0.tgz",
@@ -11531,9 +11575,9 @@
             }
         },
         "node_modules/toml-eslint-parser": {
-            "version": "0.6.0",
-            "resolved": "https://registry.npmjs.org/toml-eslint-parser/-/toml-eslint-parser-0.6.0.tgz",
-            "integrity": "sha512-aTmQa0RFb+2URe8IZOfo/oxt3b5rlXlpG9xE+6FmeI8immCGLnZYvKVxbnCYJx4bIKIaEwl0BnCDhwO70yeWSA==",
+            "version": "0.9.3",
+            "resolved": "https://registry.npmjs.org/toml-eslint-parser/-/toml-eslint-parser-0.9.3.tgz",
+            "integrity": "sha512-moYoCvkNUAPCxSW9jmHmRElhm4tVJpHL8ItC/+uYD0EpPSFXbck7yREz9tNdJVTSpHVod8+HoipcpbQ0oE6gsw==",
             "dev": true,
             "dependencies": {
                 "eslint-visitor-keys": "^3.0.0"
@@ -11649,9 +11693,9 @@
             }
         },
         "node_modules/tslib": {
-            "version": "2.6.0",
-            "resolved": "https://registry.npmjs.org/tslib/-/tslib-2.6.0.tgz",
-            "integrity": "sha512-7At1WUettjcSRHXCyYtTselblcHl9PJFFVKiCAy/bY97+BPZXSQ2wbq0P9s8tK2G7dFQfNnlJnPAiArVBVBsfA==",
+            "version": "2.6.2",
+            "resolved": "https://registry.npmjs.org/tslib/-/tslib-2.6.2.tgz",
+            "integrity": "sha512-AEYxH93jGFPn/a2iVAwW87VuUIkR1FVUKB77NwMF7nBTDkDrrT/Hpt/IrCJ0QXhW27jTBDcf5ZY7w6RiqTMw2Q==",
             "dev": true
         },
         "node_modules/tsutils": {
@@ -14928,6 +14972,12 @@
             "dev": true,
             "optional": true
         },
+        "@pkgr/core": {
+            "version": "0.1.1",
+            "resolved": "https://registry.npmjs.org/@pkgr/core/-/core-0.1.1.tgz",
+            "integrity": "sha512-cq8o4cWH0ibXh9VGi5P20Tu9XF/0fFXl9EUinr9QfTM7a7p0oTA4iJRCQWppXR1Pg8dSM0UCItCkPwsk9qWWYA==",
+            "dev": true
+        },
         "@pkgr/utils": {
             "version": "2.3.1",
             "resolved": "https://registry.npmjs.org/@pkgr/utils/-/utils-2.3.1.tgz",
@@ -16984,6 +17034,15 @@
                 }
             }
         },
+        "eslint-compat-utils": {
+            "version": "0.5.0",
+            "resolved": "https://registry.npmjs.org/eslint-compat-utils/-/eslint-compat-utils-0.5.0.tgz",
+            "integrity": "sha512-dc6Y8tzEcSYZMHa+CMPLi/hyo1FzNeonbhJL7Ol0ccuKQkwopJcJBA9YL/xmMTLU1eKigXo9vj9nALElWYSowg==",
+            "dev": true,
+            "requires": {
+                "semver": "^7.5.4"
+            }
+        },
         "eslint-config-prettier": {
             "version": "9.0.0",
             "resolved": "https://registry.npmjs.org/eslint-config-prettier/-/eslint-config-prettier-9.0.0.tgz",
@@ -17240,27 +17299,28 @@
             }
         },
         "eslint-plugin-json-schema-validator": {
-            "version": "4.6.1",
-            "resolved": "https://registry.npmjs.org/eslint-plugin-json-schema-validator/-/eslint-plugin-json-schema-validator-4.6.1.tgz",
-            "integrity": "sha512-xzPnXOyWFc9Vs33Pt0WraQfDKJwa6wH11Z9s2XhtLQRMrj50hUgekG6CFWJigitbGLCHjRtY4Hy+dZMrzk40mg==",
+            "version": "5.0.0",
+            "resolved": "https://registry.npmjs.org/eslint-plugin-json-schema-validator/-/eslint-plugin-json-schema-validator-5.0.0.tgz",
+            "integrity": "sha512-62CVUvUsilCK06vGAZxcDmUH8Zz3clPkPyHq8QwQ6dUJT6JaM+VllJqpgAqvHXy0cE/eZGIsWF2miK5bLy6HDg==",
             "dev": true,
             "requires": {
                 "@eslint-community/eslint-utils": "^4.3.0",
                 "ajv": "^8.0.0",
                 "debug": "^4.3.1",
+                "eslint-compat-utils": "^0.5.0",
                 "json-schema-migrate": "^2.0.0",
                 "jsonc-eslint-parser": "^2.0.0",
                 "minimatch": "^8.0.0",
-                "synckit": "^0.8.0",
-                "toml-eslint-parser": "^0.6.0",
+                "synckit": "^0.9.0",
+                "toml-eslint-parser": "^0.9.0",
                 "tunnel-agent": "^0.6.0",
                 "yaml-eslint-parser": "^1.0.0"
             },
             "dependencies": {
                 "ajv": {
-                    "version": "8.11.0",
-                    "resolved": "https://registry.npmjs.org/ajv/-/ajv-8.11.0.tgz",
-                    "integrity": "sha512-wGgprdCvMalC0BztXvitD2hC04YffAvtsUn93JbGXYLAtCUO4xd17mCCZQxUOItiBwZvJScWo8NIvQMQ71rdpg==",
+                    "version": "8.12.0",
+                    "resolved": "https://registry.npmjs.org/ajv/-/ajv-8.12.0.tgz",
+                    "integrity": "sha512-sRu1kpcO9yLtYxBKvqfTeh9KzZEwO3STyX1HT+4CaDzC6HpTGYhIhPIzj9XuKU7KYDwnaeh5hcOwjy1QuJzBPA==",
                     "dev": true,
                     "requires": {
                         "fast-deep-equal": "^3.1.1",
@@ -17292,6 +17352,16 @@
                     "requires": {
                         "brace-expansion": "^2.0.1"
                     }
+                },
+                "synckit": {
+                    "version": "0.9.0",
+                    "resolved": "https://registry.npmjs.org/synckit/-/synckit-0.9.0.tgz",
+                    "integrity": "sha512-7RnqIMq572L8PeEzKeBINYEJDDxpcH8JEgLwUqBd3TkofhFRbkq4QLR0u+36avGAhCRbk2nnmjcW9SE531hPDg==",
+                    "dev": true,
+                    "requires": {
+                        "@pkgr/core": "^0.1.0",
+                        "tslib": "^2.6.2"
+                    }
                 }
             }
         },
@@ -21183,9 +21253,9 @@
             }
         },
         "toml-eslint-parser": {
-            "version": "0.6.0",
-            "resolved": "https://registry.npmjs.org/toml-eslint-parser/-/toml-eslint-parser-0.6.0.tgz",
-            "integrity": "sha512-aTmQa0RFb+2URe8IZOfo/oxt3b5rlXlpG9xE+6FmeI8immCGLnZYvKVxbnCYJx4bIKIaEwl0BnCDhwO70yeWSA==",
+            "version": "0.9.3",
+            "resolved": "https://registry.npmjs.org/toml-eslint-parser/-/toml-eslint-parser-0.9.3.tgz",
+            "integrity": "sha512-moYoCvkNUAPCxSW9jmHmRElhm4tVJpHL8ItC/+uYD0EpPSFXbck7yREz9tNdJVTSpHVod8+HoipcpbQ0oE6gsw==",
             "dev": true,
             "requires": {
                 "eslint-visitor-keys": "^3.0.0"
@@ -21263,9 +21333,9 @@
             }
         },
         "tslib": {
-            "version": "2.6.0",
-            "resolved": "https://registry.npmjs.org/tslib/-/tslib-2.6.0.tgz",
-            "integrity": "sha512-7At1WUettjcSRHXCyYtTselblcHl9PJFFVKiCAy/bY97+BPZXSQ2wbq0P9s8tK2G7dFQfNnlJnPAiArVBVBsfA==",
+            "version": "2.6.2",
+            "resolved": "https://registry.npmjs.org/tslib/-/tslib-2.6.2.tgz",
+            "integrity": "sha512-AEYxH93jGFPn/a2iVAwW87VuUIkR1FVUKB77NwMF7nBTDkDrrT/Hpt/IrCJ0QXhW27jTBDcf5ZY7w6RiqTMw2Q==",
             "dev": true
         },
         "tsutils": {
diff --git a/package.json b/package.json
index 864eff2..3fc8ef6 100644
--- a/package.json
+++ b/package.json
@@ -82,7 +82,7 @@
         "eslint-plugin-eslint-comments": "^3.2.0",
         "eslint-plugin-eslint-plugin": "^5.2.1",
         "eslint-plugin-import": "^2.29.1",
-        "eslint-plugin-json-schema-validator": "^4.6.1",
+        "eslint-plugin-json-schema-validator": "^5.0.0",
         "eslint-plugin-jsonc": "^2.0.0",
         "eslint-plugin-n": "^16.0.0",
         "eslint-plugin-prettier": "^5.0.0",


Test patch:
diff --git a/tests/lib/eslint-plugin.ts b/tests/lib/eslint-plugin.ts
index e107df2..291c005 100644
--- a/tests/lib/eslint-plugin.ts
+++ b/tests/lib/eslint-plugin.ts
@@ -45,7 +45,6 @@ describe("Integration with eslint-plugin-regexp", async () => {
                     "regexp/no-dupe-characters-character-class",
                     "regexp/prefer-w",
                     "regexp/prefer-d",
-                    "regexp/prefer-d",
                     "regexp/use-ignore-case",
                 ],
             )
@@ -75,7 +74,6 @@ describe("Integration with eslint-plugin-regexp", async () => {
                 "regexp/no-dupe-characters-character-class",
                 "regexp/prefer-w",
                 "regexp/prefer-d",
-                "regexp/prefer-d",
                 "regexp/use-ignore-case",
             ],
         )
diff --git a/tests/lib/rules/__snapshots__/prefer-d.ts.eslintsnap b/tests/lib/rules/__snapshots__/prefer-d.ts.eslintsnap
index 173c2fa..8882238 100644
--- a/tests/lib/rules/__snapshots__/prefer-d.ts.eslintsnap
+++ b/tests/lib/rules/__snapshots__/prefer-d.ts.eslintsnap
@@ -26,6 +26,9 @@ Output:
 
 
 Test: prefer-d >> invalid
+Options:
+  - insideCharacterClass: d
+
 Code:
   1 | /[^0-9\w]/
     |    ^~~ [1]
diff --git a/tests/lib/rules/prefer-d.ts b/tests/lib/rules/prefer-d.ts
index c888247..955f3f8 100644
--- a/tests/lib/rules/prefer-d.ts
+++ b/tests/lib/rules/prefer-d.ts
@@ -12,6 +12,7 @@ tester.run("prefer-d", rule as any, {
     valid: [
         String.raw`/\d/`,
         String.raw`/[1-9]/`,
+        "/[^0-9\\w]/",
         {
             code: String.raw`/[0-9a-z]/`,
             options: [{ insideCharacterClass: "ignore" }],
@@ -40,7 +41,10 @@ tester.run("prefer-d", rule as any, {
     invalid: [
         "/[0-9]/",
         "/[^0-9]/",
-        "/[^0-9\\w]/",
+        {
+            code: "/[^0-9\\w]/",
+            options: [{ insideCharacterClass: "d" }],
+        },
         `
             const s = "[0-9]"
             new RegExp(s)