From 652b3dfa9be0c126e6744c2c329ab43e3ba0504f Mon Sep 17 00:00:00 2001 From: Aaron Hill Date: Mon, 7 Nov 2016 05:48:33 -0800 Subject: [PATCH] Fix false positive with EmptyLinesCheck. (#310) The logic incorrectly skipped over lines that had single-line comments filling the entire line. Fixed issue and updated unit tests to prevent regression. --- src/checkstyle/checks/whitespace/EmptyLinesCheck.hx | 8 +++++++- test/checks/whitespace/EmptyLinesCheckTest.hx | 4 ++-- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/src/checkstyle/checks/whitespace/EmptyLinesCheck.hx b/src/checkstyle/checks/whitespace/EmptyLinesCheck.hx index 8cb6cb14..60af77a3 100644 --- a/src/checkstyle/checks/whitespace/EmptyLinesCheck.hx +++ b/src/checkstyle/checks/whitespace/EmptyLinesCheck.hx @@ -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) { diff --git a/test/checks/whitespace/EmptyLinesCheckTest.hx b/test/checks/whitespace/EmptyLinesCheckTest.hx index 503899ba..6bb03de0 100644 --- a/test/checks/whitespace/EmptyLinesCheckTest.hx +++ b/test/checks/whitespace/EmptyLinesCheckTest.hx @@ -126,7 +126,7 @@ abstract EmptyLinesCheckTests(String) to String { var TEST4 = "class Test { - // comments + // comments (with text before) public function new() { var b:Int; @@ -136,7 +136,7 @@ abstract EmptyLinesCheckTests(String) to String { var TEST5 = "class Test { - // comments +// comments (with no text before) var a:Int; }";