Skip to content

Commit

Permalink
Merge pull request #3 from adireddy/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
Adi committed May 7, 2015
2 parents d99cf74 + a91a054 commit 513b5aa
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 7 deletions.
2 changes: 2 additions & 0 deletions checkstyle/checks/ReturnCheck.hx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import haxe.macro.Expr;
class ReturnCheck extends Check {

public var severity:String = "INFO";
public var allowEmptyReturn:Bool = true;

override function _actualRun() {
for (td in _checker.ast.decls) {
Expand All @@ -30,6 +31,7 @@ class ReturnCheck extends Check {
if (Std.string(f.kind).indexOf("ret => TPath({ name => Void") > -1) {
_warnVoid(f.name, f.pos);
}
if (allowEmptyReturn && Std.string(f.kind).indexOf("EReturn(null)") > -1) return;
if (Std.string(f.kind).indexOf("expr => EReturn") > -1 && Std.string(f.kind).indexOf("ret => null") > -1) {
_warnNoReturnType(f.name, f.pos);
}
Expand Down
4 changes: 2 additions & 2 deletions haxelib.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
],
"description": "Automated code analysis ideal for projects that want to enforce a coding standard.",
"contributors": ["adireddy"],
"releasenote": "added ignoreRangeOperator config for SpacingCheck",
"version": "1.0.5",
"releasenote": "added allowEmptyReturn config for ReturnCheck",
"version": "1.0.6",
"url": "https://github.com/adireddy/haxe-checkstyle",
"dependencies": {

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "checkstyle",
"version": "1.0.5",
"version": "1.0.6",
"description": "Automated code analysis ideal for projects that want to enforce a coding standard.",
"repository": {
"type": "git",
Expand Down
10 changes: 8 additions & 2 deletions resources/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,12 @@
"type": "ListenerName",
"props": {
"severity": "ERROR",
"listeners": ["addEventListener", "addListener", "on", "once"]
"listeners": [
"addEventListener",
"addListener",
"on",
"once"
]
}
},
{
Expand Down Expand Up @@ -87,7 +92,8 @@
{
"type": "Return",
"props": {
"severity": "INFO"
"severity": "INFO",
"allowEmptyReturn": true
}
},
{
Expand Down
Binary file modified run.n
Binary file not shown.
16 changes: 14 additions & 2 deletions test/ReturnCheckTest.hx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,12 @@ class ReturnCheckTest extends CheckTestCase {

public function testNoReturnType() {
var msg = checkMessage(ReturnTests.TEST2, new ReturnCheck());
assertEquals(msg, 'Return type not specified when returning a value for function: test');
assertEquals(msg, 'Return type not specified when returning a value for function: test1');
}

public function testEmptyReturnType() {
var msg = checkMessage(ReturnTests.TEST3, new ReturnCheck());
assertEquals(msg, '');
}
}

Expand All @@ -23,8 +28,15 @@ class ReturnTests {

public static inline var TEST2:String =
"class Test {
public function test() {
public function test1() {
return 0;
}
}";

public static inline var TEST3:String =
"class Test {
public function test2() {
return;
}
}";
}

0 comments on commit 513b5aa

Please sign in to comment.