Skip to content

Commit 99ce797

Browse files
committed
added support for @SuppressWarnings to typedefs and enums
@SuppressWarnings can now suppress warnings on whole class / typedef / abstract / enum Bugfix for enum positions in ComplexTypeUtils
1 parent a7aa656 commit 99ce797

File tree

3 files changed

+73
-9
lines changed

3 files changed

+73
-9
lines changed

checkstyle/ComplexTypeUtils.hx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,9 @@ class ComplexTypeUtils {
5353
walkCommonDefinition(d, pos, cb);
5454
for (ec in d.data) {
5555
walkMeta(ec.meta, cb);
56-
for (arg in ec.args) walkComplexType(arg.type, ec.name, pos, cb);
57-
for (param in ec.params) walkTypeParamDecl(param, pos, cb);
58-
if (ec.type != null) walkComplexType(ec.type, ec.name, pos, cb);
56+
for (arg in ec.args) walkComplexType(arg.type, ec.name, ec.pos, cb);
57+
for (param in ec.params) walkTypeParamDecl(param, ec.pos, cb);
58+
if (ec.type != null) walkComplexType(ec.type, ec.name, ec.pos, cb);
5959
}
6060
}
6161

checkstyle/checks/Check.hx

Lines changed: 41 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,15 @@ class Check {
4545
}
4646

4747
function isCheckSuppressed(f:Field):Bool {
48-
if (f == null || f.meta == null) return false;
48+
if (f == null) return false;
49+
return isPosSuppressed (f.pos);
50+
}
51+
52+
function hasSuppressWarningsMeta(m:Metadata):Bool {
53+
if (m == null) return false;
4954

5055
var search = 'checkstyle:${getModuleName ()}';
51-
for (meta in f.meta) {
56+
for (meta in m) {
5257
if (meta.name != "SuppressWarnings") continue;
5358
if (meta.params == null) continue;
5459
for (param in meta.params) {
@@ -73,11 +78,44 @@ class Check {
7378
function isCharPosSuppressed(pos:Int):Bool {
7479
for (td in _checker.ast.decls) {
7580
switch (td.decl){
81+
case EAbstract(d):
82+
if ((pos <= td.pos.max) && (pos >= td.pos.min)) {
83+
if (hasSuppressWarningsMeta (d.meta)) return true;
84+
}
85+
for (field in d.data) {
86+
if (pos > field.pos.max) continue;
87+
if (pos < field.pos.min) continue;
88+
return hasSuppressWarningsMeta (field.meta);
89+
}
7690
case EClass(d):
91+
if ((pos <= td.pos.max) && (pos >= td.pos.min)) {
92+
if (hasSuppressWarningsMeta (d.meta)) return true;
93+
}
7794
for (field in d.data) {
7895
if (pos > field.pos.max) continue;
7996
if (pos < field.pos.min) continue;
80-
return isCheckSuppressed (field);
97+
return hasSuppressWarningsMeta (field.meta);
98+
}
99+
case EEnum(d):
100+
if ((pos <= td.pos.max) && (pos >= td.pos.min)) {
101+
if (hasSuppressWarningsMeta (d.meta)) return true;
102+
}
103+
for (item in d.data) {
104+
if (pos > item.pos.max) continue;
105+
if (pos < item.pos.min) continue;
106+
return hasSuppressWarningsMeta (item.meta);
107+
}
108+
case ETypedef(d):
109+
switch (d.data) {
110+
case TAnonymous(fields):
111+
for (field in fields) {
112+
if (pos > field.pos.max) continue;
113+
if (pos < field.pos.min) continue;
114+
if (hasSuppressWarningsMeta (field.meta)) return true;
115+
// typedef pos does not include body
116+
return hasSuppressWarningsMeta (d.meta);
117+
}
118+
default:
81119
}
82120
default:
83121
}

test/DynamicCheckTest.hx

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,14 +38,40 @@ class DynamicTests {
3838
}
3939
}
4040
41+
@SuppressWarnings('checkstyle:Dynamic')
42+
class Testa {
43+
public var a:Int;
44+
private var b:Int;
45+
static var COUNT:Int = 1;
46+
var count6:Dynamic;
47+
48+
function calc(val:Dynamic, val2:Dynamic):Dynamic {
49+
return null;
50+
}
51+
}
52+
4153
enum Test2 {
4254
count;
43-
a;
55+
@SuppressWarnings('checkstyle:Dynamic')
56+
a(field:Dynamic);
57+
}
58+
59+
@SuppressWarnings('checkstyle:Dynamic')
60+
enum Test2a {
61+
count;
62+
a(field:Dynamic);
4463
}
45-
64+
4665
typedef Test3 = {
4766
var count1:Int;
48-
var count2:String;
67+
@SuppressWarnings('checkstyle:Dynamic')
68+
var count2:Dynamic;
69+
}
70+
71+
@SuppressWarnings('checkstyle:Dynamic')
72+
typedef Test3a = {
73+
var count1:Int;
74+
var count2:Dynamic;
4975
}";
5076

5177
public static inline var TEST1:String = "

0 commit comments

Comments
 (0)