diff --git a/RegExpSupport/resources/inspectionDescriptions/RegExpRedundantEscape.html b/RegExpSupport/resources/inspectionDescriptions/RegExpRedundantEscape.html index 795e9224cd27..0cbcc90fd70c 100644 --- a/RegExpSupport/resources/inspectionDescriptions/RegExpRedundantEscape.html +++ b/RegExpSupport/resources/inspectionDescriptions/RegExpRedundantEscape.html @@ -18,6 +18,9 @@ Many escape sequences that are necessary outside of a character class are redund

The Ignore escaped closing brackets '}' and ']' option specifies whether to report \} and \] outside of a character class when they are allowed to be unescaped by the RegExp dialect. +

+Similarly, the Ignore escaped forward-slashes '/' option specifies whether to report \/ when +they are allowed to be unescaped by the RegExp dialect.

New in 2017.3 \ No newline at end of file diff --git a/RegExpSupport/resources/messages/RegExpBundle.properties b/RegExpSupport/resources/messages/RegExpBundle.properties index b9cc25845056..5028e422468c 100644 --- a/RegExpSupport/resources/messages/RegExpBundle.properties +++ b/RegExpSupport/resources/messages/RegExpBundle.properties @@ -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 diff --git a/RegExpSupport/src/org/intellij/lang/regexp/inspection/RegExpRedundantEscapeInspection.java b/RegExpSupport/src/org/intellij/lang/regexp/inspection/RegExpRedundantEscapeInspection.java index 4addc68cb5c3..2ac4d040d2bf 100644 --- a/RegExpSupport/src/org/intellij/lang/regexp/inspection/RegExpRedundantEscapeInspection.java +++ b/RegExpSupport/src/org/intellij/lang/regexp/inspection/RegExpRedundantEscapeInspection.java @@ -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; diff --git a/RegExpSupport/test/org/intellij/lang/regexp/inspection/RedundantEscapeInspectionTest.java b/RegExpSupport/test/org/intellij/lang/regexp/inspection/RedundantEscapeInspectionTest.java index 60c61c39d9ed..b293606d8343 100644 --- a/RegExpSupport/test/org/intellij/lang/regexp/inspection/RedundantEscapeInspectionTest.java +++ b/RegExpSupport/test/org/intellij/lang/regexp/inspection/RedundantEscapeInspectionTest.java @@ -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; } }