Skip to content

Commit

Permalink
Fix: max-len properly ignore trailing comments (fixes eslint#11838)
Browse files Browse the repository at this point in the history
  • Loading branch information
ZYSzys committed Jun 15, 2019
1 parent aef8ea1 commit b91cab8
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
7 changes: 7 additions & 0 deletions lib/rules/max-len.js
Expand Up @@ -315,6 +315,13 @@ module.exports = {
textToMeasure = line;
} else if (ignoreTrailingComments && isTrailingComment(line, lineNumber, comment)) {
textToMeasure = stripTrailingComment(line, comment);

// ignore multiple trailing comments in the same line
let lastIndex = commentsIndex;

while (isTrailingComment(textToMeasure, lineNumber, comments[--lastIndex])) {
textToMeasure = stripTrailingComment(textToMeasure, comments[lastIndex]);
}
} else {
textToMeasure = line;
}
Expand Down
6 changes: 6 additions & 0 deletions tests/lib/rules/max-len.js
Expand Up @@ -51,6 +51,9 @@ ruleTester.run("max-len", rule, {
}, {
code: "// really long comment on its own line sitting here",
options: [40, 4, { ignoreComments: true }]
}, {
code: "var foo = module.exports = {}; /* inline some other comments */ //more",
options: [40, 4, { ignoreComments: true }]
},
"var /*inline-comment*/ i = 1;",
{
Expand Down Expand Up @@ -87,6 +90,9 @@ ruleTester.run("max-len", rule, {
}, {
code: "var foo = module.exports = {}; // really long trailing comment",
options: [40, 4, { ignoreTrailingComments: true }]
}, {
code: "var foo = module.exports = {}; /* inline some other comments */ //more",
options: [40, 4, { ignoreTrailingComments: true }]
}, {
code: "var foo = module.exports = {}; // really long trailing comment",
options: [40, 4, { ignoreComments: true, ignoreTrailingComments: false }]
Expand Down

0 comments on commit b91cab8

Please sign in to comment.