mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
RegExp: fix false positive on class intersection (IJPL-102098)
in "Regular expression can be simplified" inspection GitOrigin-RevId: 91eafa57c5e1a1e5df8fd1f8e3b0fb1644891e04
This commit is contained in:
committed by
intellij-monorepo-bot
parent
edaef30179
commit
3a8dccfbc7
+2
-2
@@ -1,4 +1,4 @@
|
||||
// Copyright 2000-2023 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
|
||||
// Copyright 2000-2025 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
|
||||
package org.intellij.lang.regexp.inspection;
|
||||
|
||||
import com.intellij.codeInspection.*;
|
||||
@@ -62,7 +62,7 @@ public class RegExpSimplifiableInspection extends LocalInspectionTool {
|
||||
if (elements.length == 1) {
|
||||
final RegExpClassElement element = elements[0];
|
||||
if (element instanceof RegExpPosixBracketExpression) return;
|
||||
if (!(element instanceof RegExpCharRange)) {
|
||||
if (!(element instanceof RegExpCharRange) && !(element instanceof RegExpIntersection)) {
|
||||
if (!(element instanceof RegExpChar) || !"{}().*+?|$".contains(element.getText())) {
|
||||
// [a] -> a
|
||||
registerProblem(regExpClass, element.getUnescapedText());
|
||||
|
||||
+6
-1
@@ -1,4 +1,4 @@
|
||||
// Copyright 2000-2022 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
|
||||
// Copyright 2000-2025 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
|
||||
package org.intellij.lang.regexp.inspection;
|
||||
|
||||
import com.intellij.codeInspection.CommonQuickFixBundle;
|
||||
@@ -37,6 +37,11 @@ public class RegExpSimplifiableInspectionTest extends RegExpInspectionTestCase {
|
||||
highlightTest("[0-9abc]"); // no warn; replacing with \d is not equivalent in Unicode context
|
||||
}
|
||||
|
||||
public void testIntersection() {
|
||||
highlightTest("^[\\p{ASCII}&&[^@]]+@[\\p{ASCII}&&[^@]]+$");
|
||||
highlightTest("[\\W&&\\S]");
|
||||
}
|
||||
|
||||
public void testSingleElementClass() {
|
||||
doTest("[a]", "a");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user