Skip to content

Commit 652b3df

Browse files
seraku24Gama11
authored andcommitted
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.
1 parent 3769783 commit 652b3df

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

src/checkstyle/checks/whitespace/EmptyLinesCheck.hx

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,13 @@ class EmptyLinesCheck extends LineCheckBase {
3838
for (i in 0...checker.lines.length) {
3939
var line = checker.lines[i];
4040
var ranges = getRanges(line);
41-
if (ranges.length == 1 && ranges[0].type != TEXT) continue;
41+
if (ranges.length == 1) {
42+
switch (ranges[0].type) {
43+
case TEXT:
44+
case COMMENT(isBlock): if (isBlock) continue;
45+
case STRING(isInterpolated): continue;
46+
}
47+
}
4248

4349
if (~/^\s*$/.match(line)) {
4450
if (!inGroup) {

test/checks/whitespace/EmptyLinesCheckTest.hx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ abstract EmptyLinesCheckTests(String) to String {
126126
var TEST4 =
127127
"class Test {
128128
129-
// comments
129+
// comments (with text before)
130130
131131
public function new() {
132132
var b:Int;
@@ -136,7 +136,7 @@ abstract EmptyLinesCheckTests(String) to String {
136136
var TEST5 =
137137
"class Test {
138138
139-
// comments
139+
// comments (with no text before)
140140
141141
var a:Int;
142142
}";

0 commit comments

Comments
 (0)