mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
Regex: add option to disable flagging of escaped forward slashes (IDEA-374632)
GitOrigin-RevId: 7d400d209bb9e7b9f385e112bf5178e97603aac0
This commit is contained in:
committed by
intellij-monorepo-bot
parent
bb71ba1c2a
commit
565f7b3a1c
@@ -18,6 +18,9 @@ Many escape sequences that are necessary outside of a character class are redund
|
||||
<p>
|
||||
The <b>Ignore escaped closing brackets '}' and ']'</b> option specifies whether to report <code>\}</code> and <code>\]</code> outside of a character class
|
||||
when they are allowed to be unescaped by the RegExp dialect.
|
||||
<p>
|
||||
Similarly, the <b>Ignore escaped forward-slashes '/'</b> option specifies whether to report <code>\/</code> when
|
||||
they are allowed to be unescaped by the RegExp dialect.
|
||||
<p><small>New in 2017.3</small>
|
||||
</body>
|
||||
</html>
|
||||
@@ -92,6 +92,7 @@ inspection.name.single.character.alternation=Single character alternation
|
||||
inspection.name.suspicious.backref=Suspicious back reference
|
||||
inspection.name.unnecessary.non.capturing.group=Unnecessary non-capturing group
|
||||
inspection.option.ignore.escaped.closing.brackets=Ignore escaped closing brackets '}' and ']'
|
||||
inspection.option.ignore.escaped.forward.slashes=Ignore escaped forward-slashes '/'
|
||||
inspection.quick.fix.remove.duplicate.0.from.character.class=Remove duplicate ''{0}'' from character class
|
||||
inspection.quick.fix.remove.duplicate.branch=Remove duplicate branch
|
||||
inspection.quick.fix.remove.duplicate.element.from.character.class=Remove duplicate element from character class
|
||||
|
||||
+8
-2
@@ -1,4 +1,4 @@
|
||||
// Copyright 2000-2024 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.LocalInspectionTool;
|
||||
@@ -27,11 +27,14 @@ import static com.intellij.codeInspection.options.OptPane.pane;
|
||||
public class RegExpRedundantEscapeInspection extends LocalInspectionTool {
|
||||
|
||||
public boolean ignoreEscapedMetaCharacters = false;
|
||||
public boolean ignoreEscapedForwardSlashes = false;
|
||||
|
||||
@Override
|
||||
public @NotNull OptPane getOptionsPane() {
|
||||
return pane(
|
||||
checkbox("ignoreEscapedMetaCharacters", RegExpBundle.message("inspection.option.ignore.escaped.closing.brackets")));
|
||||
checkbox("ignoreEscapedMetaCharacters", RegExpBundle.message("inspection.option.ignore.escaped.closing.brackets")),
|
||||
checkbox("ignoreEscapedForwardSlashes", RegExpBundle.message("inspection.option.ignore.escaped.forward.slashes"))
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -59,6 +62,9 @@ public class RegExpRedundantEscapeInspection extends LocalInspectionTool {
|
||||
if (ignoreEscapedMetaCharacters && (text.equals("\\}") || text.equals("\\]")) && !(ch.getParent() instanceof RegExpClass)) {
|
||||
return;
|
||||
}
|
||||
if (ignoreEscapedForwardSlashes && text.equals("\\/")) {
|
||||
return;
|
||||
}
|
||||
final ASTNode astNode = ch.getNode().getFirstChildNode();
|
||||
if (astNode == null || astNode.getElementType() != RegExpTT.REDUNDANT_ESCAPE) {
|
||||
return;
|
||||
|
||||
+8
-2
@@ -1,4 +1,4 @@
|
||||
// Copyright 2000-2021 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.LocalInspectionTool;
|
||||
@@ -37,9 +37,15 @@ public class RedundantEscapeInspectionTest extends RegExpInspectionTestCase {
|
||||
highlightTest("\\{TEST}", RegExpFileType.forLanguage(EcmaScriptRegexpLanguage.INSTANCE));
|
||||
}
|
||||
|
||||
public void testIgnoreSlashes() {
|
||||
highlightTest("\\/\\/\\/[\\/]");
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
protected LocalInspectionTool getInspection() {
|
||||
return new RegExpRedundantEscapeInspection();
|
||||
RegExpRedundantEscapeInspection inspection = new RegExpRedundantEscapeInspection();
|
||||
if (getTestName(false).endsWith("IgnoreSlashes")) inspection.ignoreEscapedForwardSlashes = true;
|
||||
return inspection;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user