diff --git a/lib/rules/max-len.js b/lib/rules/max-len.js index 70e4ae867f66..45b02f351178 100644 --- a/lib/rules/max-len.js +++ b/lib/rules/max-len.js @@ -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; } diff --git a/tests/lib/rules/max-len.js b/tests/lib/rules/max-len.js index 6b95e45c147c..99822ccaef07 100644 --- a/tests/lib/rules/max-len.js +++ b/tests/lib/rules/max-len.js @@ -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;", { @@ -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 }]