Skip to content

Commit 29cceee

Browse files
author
Adi
committed
Merge pull request #5 from adireddy/dev
Dev
2 parents 25de572 + 53c4a64 commit 29cceee

File tree

12 files changed

+168
-22
lines changed

12 files changed

+168
-22
lines changed

README.md

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -104,13 +104,16 @@ More information in [wiki page](https://github.com/adireddy/haxe-checkstyle/wiki
104104
{
105105
"type": "PublicPrivate",
106106
"props": {
107-
"severity": "INFO"
107+
"severity": "INFO",
108+
"enforcePublicPrivate": false
108109
}
109110
},
110111
{
111112
"type": "Return",
112113
"props": {
113-
"severity": "INFO"
114+
"severity": "INFO",
115+
"allowEmptyReturn": true,
116+
"enforceReturnType": false
114117
}
115118
},
116119
{
@@ -121,7 +124,6 @@ More information in [wiki page](https://github.com/adireddy/haxe-checkstyle/wiki
121124
"spaceAroundBinop": true,
122125
"spaceAroundBinop": true,
123126
"ignoreRangeOperator": true
124-
125127
}
126128
},
127129
{

build.hxml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
-lib hxparse:3.0.0
44
-lib haxeparser
55
-lib haxeparser-substituted:1.0.1
6-
-lib compiletime:2.5.0
6+
-lib compiletime:2.5.1
77
-lib hxargs:3.0.0
88

99
--each
@@ -14,4 +14,4 @@
1414
--next
1515
-cp test
1616
-main TestMain
17-
--interp
17+
--interp

checkstyle/checks/BlockFormatCheck.hx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import checkstyle.LintMessage.SeverityLevel;
77
class BlockFormatCheck extends Check {
88

99
public var severity:String = "INFO";
10+
public var emptyBlockCheck:Bool = true;
1011

1112
var firstLineRE = ~/\{[\/*]?\s*$/;
1213
var lastLineRE = ~/^\s*\}[,;\/*]?/;
@@ -15,7 +16,7 @@ class BlockFormatCheck extends Check {
1516
ExprUtils.walkFile(_checker.ast, function(e) {
1617
switch(e.expr){
1718
case EBlock([]) | EObjectDecl([]):
18-
if (e.pos.max - e.pos.min > "{}".length)
19+
if (emptyBlockCheck && e.pos.max - e.pos.min > "{}".length)
1920
logPos("Empty block should be written as {}", e.pos, Reflect.field(SeverityLevel, severity));
2021
case EBlock(_) | EObjectDecl(_):
2122
var lmin = _checker.getLinePos(e.pos.min).line;

checkstyle/checks/PublicPrivateCheck.hx

Lines changed: 32 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import haxe.macro.Expr;
99
class PublicPrivateCheck extends Check {
1010

1111
public var severity:String = "INFO";
12+
public var enforcePublicPrivate:Bool = false;
1213

1314
override function _actualRun() {
1415
for (td in _checker.ast.decls) {
@@ -30,16 +31,32 @@ class PublicPrivateCheck extends Check {
3031
}
3132

3233
function checkInterfaceField(f:Field) {
33-
if (f.access.indexOf(APublic) > -1) {
34-
_warnPublicKeyword(f.name, f.pos);
35-
return;
34+
if (enforcePublicPrivate) {
35+
if (f.access.indexOf(APublic) < 0) {
36+
_warnPublicKeywordMissing(f.name, f.pos);
37+
return;
38+
}
39+
}
40+
else {
41+
if (f.access.indexOf(APublic) > -1) {
42+
_warnPublicKeyword(f.name, f.pos);
43+
return;
44+
}
3645
}
3746
}
3847

3948
function checkField(f:Field) {
40-
if (f.access.indexOf(APrivate) > -1) {
41-
_warnPrivateKeyword(f.name, f.pos);
42-
return;
49+
if (enforcePublicPrivate) {
50+
if ((f.access.indexOf(APublic) < 0) && (f.access.indexOf(APrivate) < 0)) {
51+
_warnPrivateKeywordMissing(f.name, f.pos);
52+
return;
53+
}
54+
}
55+
else {
56+
if (f.access.indexOf(APrivate) > -1) {
57+
_warnPrivateKeyword(f.name, f.pos);
58+
return;
59+
}
4360
}
4461
}
4562

@@ -50,4 +67,12 @@ class PublicPrivateCheck extends Check {
5067
function _warnPublicKeyword(name:String, pos:Position) {
5168
logPos('No need of public keyword: ${name} (fields are by default public in interfaces)', pos, Reflect.field(SeverityLevel, severity));
5269
}
53-
}
70+
71+
function _warnPrivateKeywordMissing(name:String, pos:Position) {
72+
logPos('Missing private keyword: ${name}', pos, Reflect.field(SeverityLevel, severity));
73+
}
74+
75+
function _warnPublicKeywordMissing(name:String, pos:Position) {
76+
logPos('Missing public keyword: ${name}', pos, Reflect.field(SeverityLevel, severity));
77+
}
78+
}

checkstyle/checks/ReturnCheck.hx

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ class ReturnCheck extends Check {
1010

1111
public var severity:String = "INFO";
1212
public var allowEmptyReturn:Bool = true;
13+
public var enforceReturnType:Bool = false;
1314

1415
override function _actualRun() {
1516
for (td in _checker.ast.decls) {
@@ -28,8 +29,20 @@ class ReturnCheck extends Check {
2829
}
2930

3031
function checkField(f:Field) {
31-
if (Std.string(f.kind).indexOf("ret => TPath({ name => Void") > -1) {
32-
_warnVoid(f.name, f.pos);
32+
if (enforceReturnType) {
33+
switch (f.kind) {
34+
case FFun(fun):
35+
if (fun.ret == null) {
36+
_warnReturnTypeMissing(f.name, f.pos);
37+
}
38+
return;
39+
default:
40+
}
41+
}
42+
else {
43+
if (Std.string(f.kind).indexOf("ret => TPath({ name => Void") > -1) {
44+
_warnVoid(f.name, f.pos);
45+
}
3346
}
3447
if (allowEmptyReturn && Std.string(f.kind).indexOf("EReturn(null)") > -1) return;
3548
if (Std.string(f.kind).indexOf("expr => EReturn") > -1 && Std.string(f.kind).indexOf("ret => null") > -1) {
@@ -44,4 +57,8 @@ class ReturnCheck extends Check {
4457
function _warnNoReturnType(name:String, pos:Position) {
4558
logPos('Return type not specified when returning a value for function: ${name}', pos, Reflect.field(SeverityLevel, severity));
4659
}
47-
}
60+
61+
function _warnReturnTypeMissing(name:String, pos:Position) {
62+
logPos('Return type not specified for function: ${name}', pos, Reflect.field(SeverityLevel, severity));
63+
}
64+
}

haxelib.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@
1010
],
1111
"description": "Automated code analysis ideal for projects that want to enforce a coding standard.",
1212
"contributors": ["adireddy"],
13-
"releasenote": "added allowEmptyReturn config for ReturnCheck",
14-
"version": "1.0.6",
13+
"releasenote": "added emptyBlockCheck config for BlockFormatCheck",
14+
"version": "1.0.7",
1515
"url": "https://github.com/adireddy/haxe-checkstyle",
1616
"dependencies": {
1717

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "checkstyle",
3-
"version": "1.0.6",
3+
"version": "1.0.7",
44
"description": "Automated code analysis ideal for projects that want to enforce a coding standard.",
55
"repository": {
66
"type": "git",

resources/config.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@
1515
{
1616
"type": "BlockFormat",
1717
"props": {
18-
"severity": "ERROR"
18+
"severity": "ERROR",
19+
"emptyBlockCheck": false
1920
}
2021
},
2122
{

run.n

960 Bytes
Binary file not shown.

test/BlockFormatCheckTest.hx

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,13 @@ class BlockFormatCheckTest extends CheckTestCase {
2323
var msg = checkMessage(BlockFormatTests.TEST3, new BlockFormatCheck());
2424
assertEquals(msg, 'Last line of multiline block should contain only } and maybe , or ;');
2525
}
26+
27+
public function testDisabledBlockFormat() {
28+
var test = new BlockFormatCheck();
29+
test.emptyBlockCheck = false;
30+
var msg = checkMessage(BlockFormatTests.TEST4, test);
31+
assertEquals(msg, '');
32+
}
2633
}
2734

2835
class BlockFormatTests {
@@ -50,4 +57,11 @@ class BlockFormatTests {
5057
public function new() {
5158
var a:Int; }
5259
}";
60+
61+
public static inline var TEST4:String = "
62+
class Test {
63+
public function new() {
64+
65+
}
66+
}";
5367
}

0 commit comments

Comments
 (0)