Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit c6a7745

Browse files
mdjermanovicbtmills
authored andcommitted
Update: no-trailing-spaces false negatives after comments (fixes #12479) (#12480)
1 parent 0bffe95 commit c6a7745

File tree

2 files changed

+65
-1
lines changed

2 files changed

+65
-1
lines changed

lib/rules/no-trailing-spaces.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,11 @@ module.exports = {
9090
const lines = new Set();
9191

9292
comments.forEach(comment => {
93-
for (let i = comment.loc.start.line; i <= comment.loc.end.line; i++) {
93+
const endLine = comment.type === "Block"
94+
? comment.loc.end.line - 1
95+
: comment.loc.end.line;
96+
97+
for (let i = comment.loc.start.line; i <= endLine; i++) {
9498
lines.add(i);
9599
}
96100
});

tests/lib/rules/no-trailing-spaces.js

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,14 @@ ruleTester.run("no-trailing-spaces", rule, {
8686
{
8787
code: "#!/usr/bin/env node ",
8888
options: [{ ignoreComments: true }]
89+
},
90+
{
91+
code: "/* \n */ // ",
92+
options: [{ ignoreComments: true }]
93+
},
94+
{
95+
code: "/* \n */ /* \n */",
96+
options: [{ ignoreComments: true }]
8997
}
9098
],
9199

@@ -448,6 +456,58 @@ ruleTester.run("no-trailing-spaces", rule, {
448456
}
449457
]
450458
},
459+
{
460+
code: "/* */ ",
461+
output: "/* */",
462+
options: [{ ignoreComments: true }],
463+
errors: [
464+
{
465+
message: "Trailing spaces not allowed.",
466+
type: "Program",
467+
line: 1,
468+
column: 6
469+
}
470+
]
471+
},
472+
{
473+
code: "/* */foo ",
474+
output: "/* */foo",
475+
options: [{ ignoreComments: true }],
476+
errors: [
477+
{
478+
message: "Trailing spaces not allowed.",
479+
type: "Program",
480+
line: 1,
481+
column: 9
482+
}
483+
]
484+
},
485+
{
486+
code: "/* \n */ ",
487+
output: "/* \n */",
488+
options: [{ ignoreComments: true }],
489+
errors: [
490+
{
491+
message: "Trailing spaces not allowed.",
492+
type: "Program",
493+
line: 2,
494+
column: 4
495+
}
496+
]
497+
},
498+
{
499+
code: "/* \n */ foo ",
500+
output: "/* \n */ foo",
501+
options: [{ ignoreComments: true }],
502+
errors: [
503+
{
504+
message: "Trailing spaces not allowed.",
505+
type: "Program",
506+
line: 2,
507+
column: 8
508+
}
509+
]
510+
},
451511
{
452512
code: "// Trailing comment test. ",
453513
output: "// Trailing comment test.",

0 commit comments

Comments
 (0)