From 5edd14f75ea518c861b25a2d6883df426c05941f Mon Sep 17 00:00:00 2001 From: not-an aardvark Date: Wed, 29 Jun 2016 22:50:22 -0400 Subject: [PATCH] Fix: false negative of `max-len` (fixes #6564) --- lib/rules/max-len.js | 2 +- tests/lib/rules/max-len.js | 15 +++++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) 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 + } + ] } ] });