Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Update: no-trailing-spaces false negatives after comments (fixes #12479…
- Loading branch information
Showing
with
65 additions
and
1 deletion.
-
+5
−1
lib/rules/no-trailing-spaces.js
-
+60
−0
tests/lib/rules/no-trailing-spaces.js
|
|
@@ -90,7 +90,11 @@ module.exports = { |
|
|
const lines = new Set(); |
|
|
|
|
|
comments.forEach(comment => { |
|
|
for (let i = comment.loc.start.line; i <= comment.loc.end.line; i++) { |
|
|
const endLine = comment.type === "Block" |
|
|
? comment.loc.end.line - 1 |
|
|
: comment.loc.end.line; |
|
|
|
|
|
for (let i = comment.loc.start.line; i <= endLine; i++) { |
|
|
lines.add(i); |
|
|
} |
|
|
}); |
|
|
|
|
|
@@ -86,6 +86,14 @@ ruleTester.run("no-trailing-spaces", rule, { |
|
|
{ |
|
|
code: "#!/usr/bin/env node ", |
|
|
options: [{ ignoreComments: true }] |
|
|
}, |
|
|
{ |
|
|
code: "/* \n */ // ", |
|
|
options: [{ ignoreComments: true }] |
|
|
}, |
|
|
{ |
|
|
code: "/* \n */ /* \n */", |
|
|
options: [{ ignoreComments: true }] |
|
|
} |
|
|
], |
|
|
|
|
|
@@ -448,6 +456,58 @@ ruleTester.run("no-trailing-spaces", rule, { |
|
|
} |
|
|
] |
|
|
}, |
|
|
{ |
|
|
code: "/* */ ", |
|
|
output: "/* */", |
|
|
options: [{ ignoreComments: true }], |
|
|
errors: [ |
|
|
{ |
|
|
message: "Trailing spaces not allowed.", |
|
|
type: "Program", |
|
|
line: 1, |
|
|
column: 6 |
|
|
} |
|
|
] |
|
|
}, |
|
|
{ |
|
|
code: "/* */foo ", |
|
|
output: "/* */foo", |
|
|
options: [{ ignoreComments: true }], |
|
|
errors: [ |
|
|
{ |
|
|
message: "Trailing spaces not allowed.", |
|
|
type: "Program", |
|
|
line: 1, |
|
|
column: 9 |
|
|
} |
|
|
] |
|
|
}, |
|
|
{ |
|
|
code: "/* \n */ ", |
|
|
output: "/* \n */", |
|
|
options: [{ ignoreComments: true }], |
|
|
errors: [ |
|
|
{ |
|
|
message: "Trailing spaces not allowed.", |
|
|
type: "Program", |
|
|
line: 2, |
|
|
column: 4 |
|
|
} |
|
|
] |
|
|
}, |
|
|
{ |
|
|
code: "/* \n */ foo ", |
|
|
output: "/* \n */ foo", |
|
|
options: [{ ignoreComments: true }], |
|
|
errors: [ |
|
|
{ |
|
|
message: "Trailing spaces not allowed.", |
|
|
type: "Program", |
|
|
line: 2, |
|
|
column: 8 |
|
|
} |
|
|
] |
|
|
}, |
|
|
{ |
|
|
code: "// Trailing comment test. ", |
|
|
output: "// Trailing comment test.", |
|
|
|