Skip to content

Commit 3084606

Browse files
committed
fix(sort-regexp): handle character-set shadowing
1 parent bc57a04 commit 3084606

File tree

5 files changed

+1682
-35
lines changed

5 files changed

+1682
-35
lines changed

rules/sort-regexp.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ export default createEslintRule<Options, MessageId>({
7373
})
7474

7575
let { sourceCode, id } = context
76+
let literalsWithShadowing = new WeakSet<TSESTree.Literal>()
7677

7778
function handleLiteral(literalNode: TSESTree.Literal): void {
7879
if (!('regex' in literalNode)) {
@@ -166,8 +167,10 @@ export default createEslintRule<Options, MessageId>({
166167
if (
167168
hasShadowingAlternatives({
168169
alternatives: alternative.parent.alternatives,
170+
flags: literalNode.regex.flags,
169171
})
170172
) {
173+
literalsWithShadowing.add(literalNode)
171174
return
172175
}
173176

@@ -225,6 +228,10 @@ export default createEslintRule<Options, MessageId>({
225228

226229
visitRegExpAST(ast, {
227230
onCharacterClassLeave(characterClass) {
231+
if (literalsWithShadowing.has(literalNode)) {
232+
return
233+
}
234+
228235
let { elements, negate, start, end } = characterClass
229236
if (!isSortable(elements)) {
230237
return

0 commit comments

Comments
 (0)