mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
better suppression for "Problematic whitespace" inspection
This commit is contained in:
+23
-9
@@ -25,6 +25,7 @@ import com.intellij.openapi.fileTypes.LanguageFileType;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.util.TextRange;
|
||||
import com.intellij.psi.PsiDocumentManager;
|
||||
import com.intellij.psi.PsiElement;
|
||||
import com.intellij.psi.PsiFile;
|
||||
import com.intellij.psi.codeStyle.CodeStyleSettings;
|
||||
import com.intellij.psi.codeStyle.CodeStyleSettingsManager;
|
||||
@@ -102,7 +103,7 @@ public class ProblematicWhitespaceInspection extends BaseInspection {
|
||||
return new ProblematicWhitespaceVisitor();
|
||||
}
|
||||
|
||||
private static class ProblematicWhitespaceVisitor extends BaseInspectionVisitor {
|
||||
private class ProblematicWhitespaceVisitor extends BaseInspectionVisitor {
|
||||
|
||||
@Override
|
||||
public void visitFile(PsiFile file) {
|
||||
@@ -131,26 +132,30 @@ public class ProblematicWhitespaceInspection extends BaseInspection {
|
||||
if (c == '\t') {
|
||||
if (useTabs) {
|
||||
if (smartTabs && spaceSeen) {
|
||||
registerError(file, file.getName(), Boolean.valueOf(isOnTheFly()), Boolean.TRUE);
|
||||
return;
|
||||
if (registerError(file, startOffset, Boolean.TRUE)) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
registerError(file, file.getName(), Boolean.valueOf(isOnTheFly()), Boolean.FALSE);
|
||||
return;
|
||||
if (registerError(file, startOffset, Boolean.FALSE)) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (c == ' ') {
|
||||
if (useTabs) {
|
||||
if (!smartTabs) {
|
||||
registerError(file, file.getName(), Boolean.valueOf(isOnTheFly()), Boolean.TRUE);
|
||||
return;
|
||||
if (registerError(file, startOffset, Boolean.TRUE)) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
else if (!spaceSeen) {
|
||||
final int currentIndent = Math.max(0, j);
|
||||
if (currentIndent < previousLineIndent) {
|
||||
registerError(file, file.getName(), Boolean.valueOf(isOnTheFly()), Boolean.TRUE);
|
||||
return;
|
||||
if (registerError(file, startOffset, Boolean.TRUE)) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
previousLineIndent = currentIndent;
|
||||
}
|
||||
@@ -166,5 +171,14 @@ public class ProblematicWhitespaceInspection extends BaseInspection {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private boolean registerError(PsiFile file, int startOffset, Boolean tab) {
|
||||
final PsiElement element = file.findElementAt(startOffset);
|
||||
if (element != null && isSuppressedFor(element)) {
|
||||
return false;
|
||||
}
|
||||
registerError(file, file.getName(), Boolean.valueOf(isOnTheFly()), tab);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+27
@@ -118,6 +118,33 @@ public class ProblematicWhitespaceInspectionTest extends LightInspectionTestCase
|
||||
"}}");
|
||||
}
|
||||
|
||||
public void testSuppression1() {
|
||||
final CodeStyleSettings settings = CodeStyleSettingsManager.getSettings(getProject());
|
||||
settings.getIndentOptions(JavaFileType.INSTANCE).USE_TAB_CHARACTER = false;
|
||||
myFixture.configureByText("X.html", "<!--suppress ProblematicWhitespace --><html>\n" +
|
||||
"\t<body></body>\n" +
|
||||
"</html>");
|
||||
myFixture.testHighlighting(true, false, false);
|
||||
}
|
||||
|
||||
public void testSuppression2() {
|
||||
final CodeStyleSettings settings = CodeStyleSettingsManager.getSettings(getProject());
|
||||
settings.getIndentOptions(JavaFileType.INSTANCE).USE_TAB_CHARACTER = false;
|
||||
myFixture.configureByText("x.css", "/*noinspection ProblematicWhitespace*/\n" +
|
||||
"div {\n" +
|
||||
" font-family: arial, helvetica;\n" +
|
||||
"}");
|
||||
myFixture.testHighlighting(true, false, false);
|
||||
}
|
||||
|
||||
public void testSuppression3() {
|
||||
final CodeStyleSettings settings = CodeStyleSettingsManager.getSettings(getProject());
|
||||
settings.getIndentOptions(JavaFileType.INSTANCE).USE_TAB_CHARACTER = false;
|
||||
doTest("@SuppressWarnings(\"ProblematicWhitespace\") class X {\n" +
|
||||
"\tString s;\n" +
|
||||
"}\n");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected InspectionProfileEntry getInspection() {
|
||||
return new ProblematicWhitespaceInspection();
|
||||
|
||||
Reference in New Issue
Block a user