Skip to content

Commit deea441

Browse files
committed
Merge pull request #14 from AlexHaxe/suppressWarnings
added @SuppressWarnings to typedefs, enums and classes
2 parents a7aa656 + 18ae8c1 commit deea441

File tree

4 files changed

+88
-9
lines changed

4 files changed

+88
-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+
if (hasSuppressWarningsMeta (f.meta)) return true;
50+
return isPosSuppressed (f.pos);
51+
}
4952

53+
function hasSuppressWarningsMeta(m:Metadata):Bool {
54+
if (m == null) return false;
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);
4457
}
45-
58+
59+
@SuppressWarnings('checkstyle:Dynamic')
60+
enum Test2a {
61+
count;
62+
a(field:Dynamic);
63+
}
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 = "

test/NestedForDepthCheckTest.hx

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,21 @@ class NestedForDepthTests {
4949
}
5050
}
5151
}
52+
}
53+
54+
@SuppressWarnings('checkstyle:NestedForDepth')
55+
class Test2 {
56+
public function test2(param:Array<Int>) {
57+
for (outerParam in params) { // level 0
58+
for (middleParam in params) { // level 1
59+
for (innerParam in params) { // level 2
60+
if (outerParam == innerParam) {
61+
trace (param);
62+
}
63+
}
64+
}
65+
}
66+
}
5267
}";
5368

5469
public static inline var TEST2:String =

0 commit comments

Comments
 (0)