Skip to content

Commit 6a8e19b

Browse files
committed
added support for @SuppressWarnings to LineLengthCheck
1 parent 9db1035 commit 6a8e19b

File tree

4 files changed

+35
-4
lines changed

4 files changed

+35
-4
lines changed

checkstyle/checks/Check.hx

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,26 @@ class Check {
5858
return false;
5959
}
6060

61+
function isLineSuppressed(i:Int):Bool {
62+
var startPos:Int = 0;
63+
for (j in 0 ... i + 1) {
64+
startPos += _checker.lines[j].length;
65+
}
66+
67+
for (td in _checker.ast.decls) {
68+
switch (td.decl){
69+
case EClass(d):
70+
for (field in d.data) {
71+
if (startPos > field.pos.max) continue;
72+
if (startPos < field.pos.min) continue;
73+
return isCheckSuppressed (field);
74+
}
75+
default:
76+
}
77+
}
78+
return false;
79+
}
80+
6181
function checkSuppressionConst (e:Expr, search:String):Bool {
6282
switch (e.expr) {
6383
case EArrayDecl (a):

checkstyle/checks/CyclomaticComplexityCheck.hx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ class CyclomaticComplexityCheck extends Check {
3232
function checkFields(definition:Definition<ClassFlag, Array<Field>>) {
3333
definition.data.map(function(field:Field):Null<Target> {
3434
return switch (field.kind) {
35-
case FieldType.FFun(f):
35+
case FieldType.FFun(f):
3636
if (isCheckSuppressed (field))
3737
null;
3838
else

checkstyle/checks/LineLengthCheck.hx

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,10 @@ class LineLengthCheck extends Check {
1414
override function _actualRun() {
1515
for (i in 0 ... _checker.lines.length) {
1616
var line = _checker.lines[i];
17-
if (line.length > maxCharacters) log('Too long line (> ${maxCharacters})', i + 1, 1, Reflect.field(SeverityLevel, severity));
17+
if (line.length > maxCharacters) {
18+
if (isLineSuppressed(i)) continue;
19+
log('Too long line (> ${maxCharacters})', i + 1, 1, Reflect.field(SeverityLevel, severity));
20+
}
1821
}
1922
}
20-
}
23+
}

test/LineLengthCheckTest.hx

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,14 @@ class LineLengthTests {
3939
"class Test {
4040
public function new() {
4141
var b:Int;
42+
}
43+
44+
@SuppressWarnings('checkstyle:LineLength')
45+
public function newi(param1:Int, param2:Int, param3:Int, param4:Int, param5:Int, param6:Int, param7:Int, param8:Int) {
46+
_a = 10;
47+
if (_a > 200 && _a < 250 && _a != 240 && _a != 250 && _a != 260 && _a != 270 && _a != 280 && _a != 290) {
48+
_a = -1;
49+
}
4250
}
4351
}";
4452

@@ -51,4 +59,4 @@ class LineLengthTests {
5159
}
5260
}
5361
}";
54-
}
62+
}

0 commit comments

Comments
 (0)