Skip to content

Commit 38a8934

Browse files
IJPL-253402 [regexp]: ignore single character alternation with dot
GitOrigin-RevId: f3f5b994e2b2e2376f963895ee760cd6b774bafd
1 parent 46c1fdd commit 38a8934

2 files changed

Lines changed: 9 additions & 6 deletions

File tree

RegExpSupport/src/org/intellij/lang/regexp/inspection/SingleCharAlternationInspection.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright 2000-2025 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
1+
// Copyright 2000-2026 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
22
package org.intellij.lang.regexp.inspection;
33

44
import com.intellij.codeInspection.CommonQuickFixBundle;
@@ -56,7 +56,7 @@ private static boolean isSingleChar(RegExpBranch branch) {
5656
final RegExpAtom[] atoms = branch.getAtoms();
5757
if (atoms.length != 1) return false;
5858
RegExpAtom atom = atoms[0];
59-
return atom instanceof RegExpChar || atom instanceof RegExpSimpleClass;
59+
return atom instanceof RegExpChar || (atom instanceof RegExpSimpleClass c && c.getKind() != RegExpSimpleClass.Kind.ANY);
6060
}
6161

6262
private static class SingleCharAlternationFix extends PsiUpdateModCommandQuickFix {

RegExpSupport/test/org/intellij/lang/regexp/inspection/SingleCharAlternationInspectionTest.java

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright 2000-2025 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
1+
// Copyright 2000-2026 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
22
package org.intellij.lang.regexp.inspection;
33

44
import com.intellij.codeInspection.LocalInspectionTool;
@@ -13,7 +13,7 @@ public class SingleCharAlternationInspectionTest extends RegExpInspectionTestCas
1313
public void testSimple() {
1414
highlightTest("<warning descr=\"Single character alternation in RegExp\">a|b|c|d</warning>");
1515
}
16-
16+
1717
public void testSimpleCharacterClass() {
1818
highlightTest("<warning descr=\"Single character alternation in RegExp\">\\d|a</warning>");
1919
}
@@ -26,6 +26,10 @@ public void testNoWarnNoException() {
2626
highlightTest("(?i)x|y");
2727
}
2828

29+
public void testNoWarnOnDot() {
30+
highlightTest(".|\\r|\\n");
31+
}
32+
2933
public void testQuickfix() {
3034
quickfixTest("<warning descr=\"Single character alternation in RegExp\">x|y|z</warning>", "[xyz]", "Replace with '[xyz]'");
3135
}
@@ -53,9 +57,8 @@ public void testRedundantEscapeReplacement2() {
5357
"Replace with '[+\\-*/=<>\\[\\].,:;(^]'");
5458
}
5559

56-
@NotNull
5760
@Override
58-
protected LocalInspectionTool getInspection() {
61+
protected @NotNull LocalInspectionTool getInspection() {
5962
return new SingleCharAlternationInspection();
6063
}
6164
}

0 commit comments

Comments
 (0)