Skip to content

Commit 56d3434

Browse files
committed
added emptyBlockCheck config for BlockFormatCheck
1 parent f8fba74 commit 56d3434

File tree

6 files changed

+21
-5
lines changed

6 files changed

+21
-5
lines changed

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;

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

58 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)