Skip to content

Commit 513b5aa

Browse files
author
Adi
committed
Merge pull request #3 from adireddy/dev
Dev
2 parents d99cf74 + a91a054 commit 513b5aa

File tree

6 files changed

+27
-7
lines changed

6 files changed

+27
-7
lines changed

checkstyle/checks/ReturnCheck.hx

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

1111
public var severity:String = "INFO";
12+
public var allowEmptyReturn:Bool = true;
1213

1314
override function _actualRun() {
1415
for (td in _checker.ast.decls) {
@@ -30,6 +31,7 @@ class ReturnCheck extends Check {
3031
if (Std.string(f.kind).indexOf("ret => TPath({ name => Void") > -1) {
3132
_warnVoid(f.name, f.pos);
3233
}
34+
if (allowEmptyReturn && Std.string(f.kind).indexOf("EReturn(null)") > -1) return;
3335
if (Std.string(f.kind).indexOf("expr => EReturn") > -1 && Std.string(f.kind).indexOf("ret => null") > -1) {
3436
_warnNoReturnType(f.name, f.pos);
3537
}

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 ignoreRangeOperator config for SpacingCheck",
14-
"version": "1.0.5",
13+
"releasenote": "added allowEmptyReturn config for ReturnCheck",
14+
"version": "1.0.6",
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.5",
3+
"version": "1.0.6",
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: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,12 @@
5555
"type": "ListenerName",
5656
"props": {
5757
"severity": "ERROR",
58-
"listeners": ["addEventListener", "addListener", "on", "once"]
58+
"listeners": [
59+
"addEventListener",
60+
"addListener",
61+
"on",
62+
"once"
63+
]
5964
}
6065
},
6166
{
@@ -87,7 +92,8 @@
8792
{
8893
"type": "Return",
8994
"props": {
90-
"severity": "INFO"
95+
"severity": "INFO",
96+
"allowEmptyReturn": true
9197
}
9298
},
9399
{

run.n

118 Bytes
Binary file not shown.

test/ReturnCheckTest.hx

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,12 @@ class ReturnCheckTest extends CheckTestCase {
1111

1212
public function testNoReturnType() {
1313
var msg = checkMessage(ReturnTests.TEST2, new ReturnCheck());
14-
assertEquals(msg, 'Return type not specified when returning a value for function: test');
14+
assertEquals(msg, 'Return type not specified when returning a value for function: test1');
15+
}
16+
17+
public function testEmptyReturnType() {
18+
var msg = checkMessage(ReturnTests.TEST3, new ReturnCheck());
19+
assertEquals(msg, '');
1520
}
1621
}
1722

@@ -23,8 +28,15 @@ class ReturnTests {
2328

2429
public static inline var TEST2:String =
2530
"class Test {
26-
public function test() {
31+
public function test1() {
2732
return 0;
2833
}
2934
}";
35+
36+
public static inline var TEST3:String =
37+
"class Test {
38+
public function test2() {
39+
return;
40+
}
41+
}";
3042
}

0 commit comments

Comments
 (0)