diff --git a/lib/rules/max-len.js b/lib/rules/max-len.js index b379835792b..b5813bbfaa7 100644 --- a/lib/rules/max-len.js +++ b/lib/rules/max-len.js @@ -162,7 +162,7 @@ module.exports = { return comment && (start.line < lineNumber || (start.line === lineNumber && isFirstTokenOnLine)) && - (end.line > lineNumber || end.column === line.length); + (end.line > lineNumber || (end.line === lineNumber && end.column === line.length)); } /** diff --git a/tests/lib/rules/max-len.js b/tests/lib/rules/max-len.js index 6624eed5310..fab774136f1 100644 --- a/tests/lib/rules/max-len.js +++ b/tests/lib/rules/max-len.js @@ -394,6 +394,21 @@ ruleTester.run("max-len", rule, { column: 1 } ] + }, + + // check comments with the same length as non-comments - https://github.com/eslint/eslint/issues/6564 + { + code: "// This commented line has precisely 51 characters.\n" + + "var x = 'This line also has exactly 51 characters';", + options: [20, { ignoreComments: true }], + errors: [ + { + message: "Line 2 exceeds the maximum line length of 20.", + type: "Program", + line: 2, + column: 1 + } + ] } ] });