From 636b1b066cb9a647fe386b1b1f1c7942333f736a Mon Sep 17 00:00:00 2001 From: AlexHaxe Date: Wed, 2 Dec 2015 01:11:09 +0100 Subject: [PATCH] changed regex to allow comments after left curly in BlockFormatCheck and LeftCurlyCheck (see issue #33) --- checkstyle/checks/BlockFormatCheck.hx | 4 +++- checkstyle/checks/LeftCurlyCheck.hx | 4 ++-- test/BlockFormatCheckTest.hx | 18 ++++++++++++++---- test/LeftCurlyCheckTest.hx | 2 +- 4 files changed, 20 insertions(+), 8 deletions(-) diff --git a/checkstyle/checks/BlockFormatCheck.hx b/checkstyle/checks/BlockFormatCheck.hx index 803e790d..956b10d5 100644 --- a/checkstyle/checks/BlockFormatCheck.hx +++ b/checkstyle/checks/BlockFormatCheck.hx @@ -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; } diff --git a/checkstyle/checks/LeftCurlyCheck.hx b/checkstyle/checks/LeftCurlyCheck.hx index fd6f0db7..6548ecf3 100644 --- a/checkstyle/checks/LeftCurlyCheck.hx +++ b/checkstyle/checks/LeftCurlyCheck.hx @@ -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); diff --git a/test/BlockFormatCheckTest.hx b/test/BlockFormatCheckTest.hx index 4904194e..5a6ee81e 100644 --- a/test/BlockFormatCheckTest.hx +++ b/test/BlockFormatCheckTest.hx @@ -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() { @@ -99,4 +100,13 @@ class BlockFormatTests { }; } }"; + + public static inline var BLOCK_COMMENT:String = " + class Test { + public function new() { /* comment + */ + var a = { // comment + }; + } + }"; } \ No newline at end of file diff --git a/test/LeftCurlyCheckTest.hx b/test/LeftCurlyCheckTest.hx index bd1d5a64..3914d781 100644 --- a/test/LeftCurlyCheckTest.hx +++ b/test/LeftCurlyCheckTest.hx @@ -89,7 +89,7 @@ class LeftCurlyTests { if (true) { // comment return; } - else if (false) { + else if (false) { /* comment */ return; }