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

Fix: max-len properly ignore trailing comments (fixes #11838) #11841

Merged
merged 1 commit into from Jun 18, 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
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