Skip to content

Commit

Permalink
Merge pull request #75 from Gama11/separateCommentTypes
Browse files Browse the repository at this point in the history
EmptyLinesCheck: separate options for single and multi line comments
  • Loading branch information
adireddy committed Mar 1, 2016
2 parents 5050cff + 6e53d6d commit 75d914a
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 13 deletions.
17 changes: 12 additions & 5 deletions checkstyle/checks/EmptyLinesCheck.hx
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,14 @@ import checkstyle.LintMessage.SeverityLevel;
class EmptyLinesCheck extends Check {

public var max:Int;
public var allowEmptyLineAfterComment:Bool;
public var allowEmptyLineAfterSingleLineComment:Bool;
public var allowEmptyLineAfterMultiLineComment:Bool;

public function new() {
super();
max = 1;
allowEmptyLineAfterComment = true;
allowEmptyLineAfterSingleLineComment = true;
allowEmptyLineAfterMultiLineComment = true;
}

override function actualRun() {
Expand All @@ -29,9 +31,8 @@ class EmptyLinesCheck extends Check {
}
end = i;

if (i > 0 && !allowEmptyLineAfterComment && ~/^(\/\/).*|^(\/\*).*|(\*\/)$/.match(StringTools.trim(checker.lines[i - 1]))) {
log('Empty line not allowed after comment(s)', start, 0, null, Reflect.field(SeverityLevel, severity));
}
if (!allowEmptyLineAfterSingleLineComment) checkComment(i, start, ~/^(\/\/).*$/);
if (!allowEmptyLineAfterMultiLineComment) checkComment(i, start, ~/^^(\/\*).*|(\*\/)$/);
}
else {
if (inGroup) {
Expand All @@ -47,6 +48,12 @@ class EmptyLinesCheck extends Check {
}
}

function checkComment(i, start, regex) {
if (i > 0 && regex.match(StringTools.trim(checker.lines[i - 1]))) {
log('Empty line not allowed after comment(s)', start, 0, null, Reflect.field(SeverityLevel, severity));
}
}

function logInfo(pos) {
log('Too many consecutive empty lines (> ${max})', pos, 0, null, Reflect.field(SeverityLevel, severity));
}
Expand Down
19 changes: 11 additions & 8 deletions test/EmptyLinesCheckTest.hx
Original file line number Diff line number Diff line change
Expand Up @@ -22,22 +22,19 @@ class EmptyLinesCheckTest extends CheckTestCase {

public function testEmptyLineAfterSingleLineComment() {
var check = new EmptyLinesCheck();
check.allowEmptyLineAfterComment = false;
check.allowEmptyLineAfterSingleLineComment = false;

var msg = checkMessage(EmptyLinesTests.TEST4, check);
assertEquals(msg, 'Empty line not allowed after comment(s)');

msg = checkMessage(EmptyLinesTests.TEST5, check);
assertEquals(msg, 'Empty line not allowed after comment(s)');

msg = checkMessage(EmptyLinesTests.TEST6, check);
assertEquals(msg, 'Empty line not allowed after comment(s)');
}

public function testEmptyLineAfterMultiLineComment() {
var check = new EmptyLinesCheck();
check.allowEmptyLineAfterComment = false;
check.allowEmptyLineAfterMultiLineComment = false;

var msg = checkMessage(EmptyLinesTests.TEST6, check);
assertEquals(msg, 'Empty line not allowed after comment(s)');

Expand All @@ -47,10 +44,16 @@ class EmptyLinesCheckTest extends CheckTestCase {

public function testAllowEmptyLineAfterComment() {
var check = new EmptyLinesCheck();


var msg = checkMessage(EmptyLinesTests.TEST4, check);
assertEquals(msg, '');

var msg = checkMessage(EmptyLinesTests.TEST5, check);
assertEquals(msg, '');

var msg = checkMessage(EmptyLinesTests.TEST6, check);
assertEquals(msg, '');

msg = checkMessage(EmptyLinesTests.TEST7, check);
assertEquals(msg, '');
}
Expand Down

0 comments on commit 75d914a

Please sign in to comment.