Skip to content

Commit 20b8e84

Browse files
committed
TabAlignmentDiagnostic
1 parent 8ee9473 commit 20b8e84

File tree

4 files changed

+45
-0
lines changed

4 files changed

+45
-0
lines changed
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
package com.github._1c_syntax.bsl.languageserver.diagnostics;
2+
3+
import com.github._1c_syntax.bsl.languageserver.diagnostics.metadata.DiagnosticMetadata;
4+
import com.github._1c_syntax.bsl.languageserver.diagnostics.metadata.DiagnosticSeverity;
5+
import com.github._1c_syntax.bsl.languageserver.diagnostics.metadata.DiagnosticTag;
6+
import com.github._1c_syntax.bsl.languageserver.diagnostics.metadata.DiagnosticType;
7+
8+
import java.util.regex.Matcher;
9+
import java.util.regex.Pattern;
10+
11+
@DiagnosticMetadata(
12+
type = DiagnosticType.CODE_SMELL,
13+
severity = DiagnosticSeverity.INFO,
14+
minutesToFix = 1,
15+
tags = {
16+
DiagnosticTag.BADPRACTICE
17+
}
18+
19+
)
20+
public class TabAlignmentDiagnostic extends AbstractDiagnostic {
21+
22+
@Override
23+
public void check() {
24+
25+
Pattern pattern = Pattern.compile("(\\t*\\S ?)\\t+");
26+
String[] lines = documentContext.getContentList();
27+
for (int i = 0; i < lines.length; i++) {
28+
Matcher matcher = pattern.matcher(lines[i]);
29+
if (!matcher.find()) {
30+
continue;
31+
}
32+
diagnosticStorage.addDiagnostic(i, matcher.start(), i, matcher.end());
33+
}
34+
}
35+
}
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
diagnosticMessage=change tabs to spaces
2+
diagnosticName=Tab alignment
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
diagnosticMessage=Замените табы на пробелы
2+
diagnosticName=Выравнивание табами
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
2+
Foo = f;
3+
foo = foo;
4+
foo = foo;
5+
foo = foo;
6+
foo = foo;

0 commit comments

Comments
 (0)