Skip to content

Commit 472c0c9

Browse files
Change default configuration of prefer-d (#715)
* Change default configuration of `prefer-d` * Create shaggy-lemons-suffer.md
1 parent 8338648 commit 472c0c9

File tree

6 files changed

+16
-6
lines changed

6 files changed

+16
-6
lines changed

.changeset/shaggy-lemons-suffer.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"eslint-plugin-regexp": minor
3+
---
4+
5+
Change default configuration of `prefer-d` to ignore digits inside character classes.

docs/rules/prefer-d.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ This option control how character class element equivalent to `\d` will be treat
5555
*Note:* This option does not affect character classes equivalent to `\d`. E.g. `[\d]`, `[0-9]`, and `[0123456789]` are unaffected.
5656
It also does not affect expression non-nested operands equivalent to `\d`. E.g. `[\d&&x]`, and `[\d--x]` are unaffected.
5757

58-
- `insideCharacterClass: "d"` (*default*)
58+
- `insideCharacterClass: "d"`
5959

6060
Character class element equivalent to `\d` will be reported and replaced with `\d`.
6161

@@ -98,7 +98,7 @@ It also does not affect expression non-nested operands equivalent to `\d`. E.g.
9898

9999
</eslint-code-block>
100100

101-
- `insideCharacterClass: "ignore"`
101+
- `insideCharacterClass: "ignore"` (*default*)
102102

103103
Character class element will not be reported.
104104

lib/rules/prefer-d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ export default createRule("prefer-d", {
6060
},
6161
create(context) {
6262
const insideCharacterClass: "ignore" | "range" | "d" =
63-
context.options[0]?.insideCharacterClass ?? "d"
63+
context.options[0]?.insideCharacterClass ?? "ignore"
6464

6565
function createVisitor({
6666
node,

tests/lib/eslint-plugin.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@ describe("Integration with eslint-plugin-regexp", async () => {
4545
"regexp/no-dupe-characters-character-class",
4646
"regexp/prefer-w",
4747
"regexp/prefer-d",
48-
"regexp/prefer-d",
4948
"regexp/use-ignore-case",
5049
],
5150
)
@@ -75,7 +74,6 @@ describe("Integration with eslint-plugin-regexp", async () => {
7574
"regexp/no-dupe-characters-character-class",
7675
"regexp/prefer-w",
7776
"regexp/prefer-d",
78-
"regexp/prefer-d",
7977
"regexp/use-ignore-case",
8078
],
8179
)

tests/lib/rules/__snapshots__/prefer-d.ts.eslintsnap

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,9 @@ Output:
2626

2727

2828
Test: prefer-d >> invalid
29+
Options:
30+
- insideCharacterClass: d
31+
2932
Code:
3033
1 | /[^0-9\w]/
3134
| ^~~ [1]

tests/lib/rules/prefer-d.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ tester.run("prefer-d", rule as any, {
1212
valid: [
1313
String.raw`/\d/`,
1414
String.raw`/[1-9]/`,
15+
"/[^0-9\\w]/",
1516
{
1617
code: String.raw`/[0-9a-z]/`,
1718
options: [{ insideCharacterClass: "ignore" }],
@@ -40,7 +41,10 @@ tester.run("prefer-d", rule as any, {
4041
invalid: [
4142
"/[0-9]/",
4243
"/[^0-9]/",
43-
"/[^0-9\\w]/",
44+
{
45+
code: "/[^0-9\\w]/",
46+
options: [{ insideCharacterClass: "d" }],
47+
},
4448
`
4549
const s = "[0-9]"
4650
new RegExp(s)

0 commit comments

Comments
 (0)