Skip to content

Commit

Permalink
changed regex to allow comments after left curly in BlockFormatCheck …
Browse files Browse the repository at this point in the history
…and LeftCurlyCheck (see issue #33)
  • Loading branch information
AlexHaxe committed Dec 2, 2015
1 parent 5df14a9 commit 636b1b0
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 8 deletions.
4 changes: 3 additions & 1 deletion checkstyle/checks/BlockFormatCheck.hx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@ class BlockFormatCheck extends Check {

public function new() {
super();
firstLineRE = ~/\{[\/*]?\s*$/;
// allow whitespace and comments after left curly
// (trailing whitespace is handled in a separate check)
firstLineRE = ~/\{\s*(\/\/.*|\/\*.*|)$/;
lastLineRE = ~/^\s*\}[,;\/*]?/;
option = EMPTY;
}
Expand Down
4 changes: 2 additions & 2 deletions checkstyle/checks/LeftCurlyCheck.hx
Original file line number Diff line number Diff line change
Expand Up @@ -233,8 +233,8 @@ class LeftCurlyCheck extends Check {
var lineLength:Int = line.length;

// must have at least one non whitespace character before curly
// and only whitespace, } or // + comment after curly
var curlyAtEOL:Bool = ~/^\s*\S.*\{\}?\s*(|\/\/.*)$/.match(line);
// and only whitespace, }, /* + comment or // + comment after curly
var curlyAtEOL:Bool = ~/^\s*\S.*\{\}?\s*(|\/\*.*|\/\/.*)$/.match(line);
// must have only whitespace before curly
var curlyOnNL:Bool = ~/^\s*\{\}?/.match(line);

Expand Down
18 changes: 14 additions & 4 deletions test/BlockFormatCheckTest.hx
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,14 @@ import checkstyle.checks.BlockFormatCheck;
class BlockFormatCheckTest extends CheckTestCase {

public function testCorrectBlockFormat() {
var msg = checkMessage(BlockFormatTests.TEST, new BlockFormatCheck());
assertEquals(msg, '');
var check:BlockFormatCheck = new BlockFormatCheck();
assertMsg(check, BlockFormatTests.TEST, '');
assertMsg(check, BlockFormatTests.BLOCK_COMMENT, '');
}

public function testWrongBlockFormat() {
var msg = checkMessage(BlockFormatTests.TEST1, new BlockFormatCheck());
assertEquals(msg, 'Empty block should be written as {}');
var check:BlockFormatCheck = new BlockFormatCheck();
assertMsg(check, BlockFormatTests.TEST1, 'Empty block should be written as {}');
}

public function testBlockFormatFirstLine() {
Expand Down Expand Up @@ -99,4 +100,13 @@ class BlockFormatTests {
};
}
}";

public static inline var BLOCK_COMMENT:String = "
class Test {
public function new() { /* comment
*/
var a = { // comment
};
}
}";
}
2 changes: 1 addition & 1 deletion test/LeftCurlyCheckTest.hx
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ class LeftCurlyTests {
if (true) { // comment
return;
}
else if (false) {
else if (false) { /* comment */
return;
}
Expand Down

0 comments on commit 636b1b0

Please sign in to comment.