Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update: no-trailing-spaces false negatives after comments (fixes #12479) #12480

Merged
merged 1 commit into from Oct 25, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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