Skip to content

Commit

Permalink
Fix false positive with EmptyLinesCheck. (#310)
Browse files Browse the repository at this point in the history
The logic incorrectly skipped over lines that had single-line comments filling the entire line.  Fixed issue and updated unit tests to prevent regression.
  • Loading branch information
seraku24 authored and Gama11 committed Nov 7, 2016
1 parent 3769783 commit 652b3df
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
8 changes: 7 additions & 1 deletion src/checkstyle/checks/whitespace/EmptyLinesCheck.hx
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,13 @@ class EmptyLinesCheck extends LineCheckBase {
for (i in 0...checker.lines.length) {
var line = checker.lines[i];
var ranges = getRanges(line);
if (ranges.length == 1 && ranges[0].type != TEXT) continue;
if (ranges.length == 1) {
switch (ranges[0].type) {
case TEXT:
case COMMENT(isBlock): if (isBlock) continue;
case STRING(isInterpolated): continue;
}
}

if (~/^\s*$/.match(line)) {
if (!inGroup) {
Expand Down
4 changes: 2 additions & 2 deletions test/checks/whitespace/EmptyLinesCheckTest.hx
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ abstract EmptyLinesCheckTests(String) to String {
var TEST4 =
"class Test {
// comments
// comments (with text before)
public function new() {
var b:Int;
Expand All @@ -136,7 +136,7 @@ abstract EmptyLinesCheckTests(String) to String {
var TEST5 =
"class Test {
// comments
// comments (with no text before)
var a:Int;
}";
Expand Down

0 comments on commit 652b3df

Please sign in to comment.