@@ -2,12 +2,13 @@ import type { RegExpVisitor } from "@eslint-community/regexpp/visitor"
2
2
import type { Rule } from "eslint"
3
3
import type {
4
4
CharacterClass ,
5
- Node as RegExpNode ,
5
+ ExpressionCharacterClass ,
6
+ Node ,
6
7
} from "@eslint-community/regexpp/ast"
7
8
import type { RegExpContext } from "../utils"
8
9
import { createRule , defineRegexpVisitor } from "../utils"
9
10
import { isRegexpLiteral } from "../utils/ast-utils/utils"
10
- import { matchesAllCharacters } from "regexp-ast-analysis"
11
+ import { matchesAllCharacters , hasStrings } from "regexp-ast-analysis"
11
12
import { mention } from "../utils/mention"
12
13
13
14
const OPTION_SS1 = "[\\s\\S]" as const
@@ -72,7 +73,7 @@ export default createRule("match-any", {
72
73
function fix (
73
74
fixer : Rule . RuleFixer ,
74
75
{ node, flags, patternSource } : RegExpContext ,
75
- regexpNode : RegExpNode ,
76
+ regexpNode : Node ,
76
77
) : null | Rule . Fix | Rule . Fix [ ] {
77
78
if ( ! preference ) {
78
79
return null
@@ -134,6 +135,28 @@ export default createRule("match-any", {
134
135
) : RegExpVisitor . Handlers {
135
136
const { node, flags, getRegexpLocation } = regexpContext
136
137
138
+ function onClass (
139
+ ccNode : CharacterClass | ExpressionCharacterClass ,
140
+ ) {
141
+ if (
142
+ matchesAllCharacters ( ccNode , flags ) &&
143
+ ! hasStrings ( ccNode , flags ) &&
144
+ ! allows . has ( ccNode . raw as never )
145
+ ) {
146
+ context . report ( {
147
+ node,
148
+ loc : getRegexpLocation ( ccNode ) ,
149
+ messageId : "unexpected" ,
150
+ data : {
151
+ expr : mention ( ccNode ) ,
152
+ } ,
153
+ fix ( fixer ) {
154
+ return fix ( fixer , regexpContext , ccNode )
155
+ } ,
156
+ } )
157
+ }
158
+ }
159
+
137
160
return {
138
161
onCharacterSetEnter ( csNode ) {
139
162
if (
@@ -154,24 +177,8 @@ export default createRule("match-any", {
154
177
} )
155
178
}
156
179
} ,
157
- onCharacterClassEnter ( ccNode : CharacterClass ) {
158
- if (
159
- matchesAllCharacters ( ccNode , flags ) &&
160
- ! allows . has ( ccNode . raw as never )
161
- ) {
162
- context . report ( {
163
- node,
164
- loc : getRegexpLocation ( ccNode ) ,
165
- messageId : "unexpected" ,
166
- data : {
167
- expr : mention ( ccNode ) ,
168
- } ,
169
- fix ( fixer ) {
170
- return fix ( fixer , regexpContext , ccNode )
171
- } ,
172
- } )
173
- }
174
- } ,
180
+ onCharacterClassEnter : onClass ,
181
+ onExpressionCharacterClassEnter : onClass ,
175
182
}
176
183
}
177
184
0 commit comments