Skip to content

Commit

Permalink
Update: no-trailing-spaces false negatives after comments (fixes #12479
Browse files Browse the repository at this point in the history
…) (#12480)
  • Loading branch information
mdjermanovic authored and btmills committed Oct 25, 2019
1 parent 0bffe95 commit c6a7745
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 1 deletion.
6 changes: 5 additions & 1 deletion lib/rules/no-trailing-spaces.js
Expand Up @@ -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);
}
});
Expand Down
60 changes: 60 additions & 0 deletions tests/lib/rules/no-trailing-spaces.js
Expand Up @@ -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 }]
}
],

Expand Down Expand Up @@ -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.",
Expand Down

0 comments on commit c6a7745

Please sign in to comment.