RegExp: enable 2 inspections as no highlight, quick fix only

This commit is contained in:
Bas Leijdekkers
2017-03-01 21:17:01 +01:00
parent 798d797061
commit afd6af0d2c
2 changed files with 22 additions and 21 deletions

View File

@@ -32,15 +32,15 @@
<localInspection groupName="RegExp" language="RegExp" shortName="SingleCharAlternation" displayName="Single character alternation"
enabledByDefault="true" level="WARNING"
implementationClass="org.intellij.lang.regexp.inspection.SingleCharAlternationInspection"/>
<localInspection groupName="RegExp" language="RegExp" shortName="OctalEscape" displayName="Octal escape" enabledByDefault="false"
level="WARNING" implementationClass="org.intellij.lang.regexp.inspection.OctalEscapeInspection"/>
<localInspection groupName="RegExp" language="RegExp" shortName="OctalEscape" displayName="Octal escape" enabledByDefault="true"
level="INFORMATION" implementationClass="org.intellij.lang.regexp.inspection.OctalEscapeInspection"/>
<!--<localInspection groupName="RegExp" language="RegExp" shortName="ReDoS" displayName="Exponential backtracking" enabledByDefault="true"
level="WARNING" implementationClass="org.intellij.lang.regexp.inspection.ReDoSInspection"/>-->
<localInspection groupName="RegExp" language="RegExp" shortName="DuplicateAlternationBranch"
displayName="Duplicate branch in alternation" enabledByDefault="true" level="WARNING"
implementationClass="org.intellij.lang.regexp.inspection.DuplicateAlternationBranchInspection"/>
<localInspection groupName="RegExp" language="RegExp" shortName="EscapedMetaCharacter" displayName="Escaped meta character"
enabledByDefault="false" level="WARNING"
enabledByDefault="true" level="INFORMATION"
implementationClass="org.intellij.lang.regexp.inspection.EscapedMetaCharacterInspection"/>
</extensions>
</idea-plugin>

View File

@@ -15,15 +15,17 @@
*/
package org.intellij.lang.regexp.inspection;
import com.intellij.codeHighlighting.HighlightDisplayLevel;
import com.intellij.codeInsight.daemon.HighlightDisplayKey;
import com.intellij.codeInsight.intention.IntentionAction;
import com.intellij.codeInspection.LocalInspectionTool;
import com.intellij.codeInspection.ex.InspectionProfileImpl;
import com.intellij.openapi.project.Project;
import com.intellij.profile.codeInspection.ProjectInspectionProfileManager;
import com.intellij.testFramework.fixtures.LightPlatformCodeInsightFixtureTestCase;
import org.intellij.lang.annotations.Language;
import org.intellij.lang.regexp.RegExpFileType;
import org.jetbrains.annotations.NotNull;
import org.junit.Assert;
import java.util.List;
/**
* @author Bas Leijdekkers
@@ -34,25 +36,24 @@ public abstract class RegExpInspectionTestCase extends LightPlatformCodeInsightF
protected abstract LocalInspectionTool getInspection();
protected void highlightTest(@Language("RegExp") String code) {
myFixture.enableInspections(getInspection());
final LocalInspectionTool inspection = getInspection();
myFixture.enableInspections(inspection);
final HighlightDisplayKey displayKey = HighlightDisplayKey.find(inspection.getShortName());
if (displayKey != null) {
final Project project = myFixture.getProject();
final InspectionProfileImpl currentProfile = ProjectInspectionProfileManager.getInstance(project).getCurrentProfile();
final HighlightDisplayLevel errorLevel = currentProfile.getErrorLevel(displayKey, null);
if (errorLevel == HighlightDisplayLevel.DO_NOT_SHOW) {
currentProfile.setErrorLevel(displayKey, HighlightDisplayLevel.WARNING, project);
}
}
myFixture.configureByText(RegExpFileType.INSTANCE, code);
myFixture.testHighlighting();
}
protected void quickfixTest(@Language("RegExp") String before, @Language("RegExp") String after, String hint) {
myFixture.enableInspections(getInspection());
myFixture.configureByText(RegExpFileType.INSTANCE, before);
myFixture.testHighlighting();
final IntentionAction intention = findIntention(hint);
assertNotNull(intention);
myFixture.launchAction(intention);
highlightTest(before);
myFixture.launchAction(myFixture.findSingleIntention(hint));
myFixture.checkResult(after);
}
protected IntentionAction findIntention(@NotNull final String hint) {
final List<IntentionAction> intentions = myFixture.filterAvailableIntentions(hint);
Assert.assertFalse("\"" + hint + "\" not in " + intentions, intentions.isEmpty());
Assert.assertFalse("Too many quickfixes found for \"" + hint + "\": " + intentions + "]", intentions.size() > 1);
return intentions.get(0);
}
}
}