@@ -2,12 +2,13 @@ import type { RegExpVisitor } from "@eslint-community/regexpp/visitor"
22import type { Rule } from "eslint"
33import type {
44 CharacterClass ,
5- Node as RegExpNode ,
5+ ExpressionCharacterClass ,
6+ Node ,
67} from "@eslint-community/regexpp/ast"
78import type { RegExpContext } from "../utils"
89import { createRule , defineRegexpVisitor } from "../utils"
910import { isRegexpLiteral } from "../utils/ast-utils/utils"
10- import { matchesAllCharacters } from "regexp-ast-analysis"
11+ import { matchesAllCharacters , hasStrings } from "regexp-ast-analysis"
1112import { mention } from "../utils/mention"
1213
1314const OPTION_SS1 = "[\\s\\S]" as const
@@ -72,7 +73,7 @@ export default createRule("match-any", {
7273 function fix (
7374 fixer : Rule . RuleFixer ,
7475 { node, flags, patternSource } : RegExpContext ,
75- regexpNode : RegExpNode ,
76+ regexpNode : Node ,
7677 ) : null | Rule . Fix | Rule . Fix [ ] {
7778 if ( ! preference ) {
7879 return null
@@ -134,6 +135,28 @@ export default createRule("match-any", {
134135 ) : RegExpVisitor . Handlers {
135136 const { node, flags, getRegexpLocation } = regexpContext
136137
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+
137160 return {
138161 onCharacterSetEnter ( csNode ) {
139162 if (
@@ -154,24 +177,8 @@ export default createRule("match-any", {
154177 } )
155178 }
156179 } ,
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 ,
175182 }
176183 }
177184
0 commit comments