Skip to content

Commit

Permalink
Fix: max-len will warn indented comment lines (fixes #6322)
Browse files Browse the repository at this point in the history
  • Loading branch information
kaicataldo committed Jun 5, 2016
1 parent d49ab4b commit 7809d2f
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 2 deletions.
6 changes: 4 additions & 2 deletions lib/rules/max-len.js
Expand Up @@ -157,10 +157,12 @@ module.exports = {
*/
function isFullLineComment(line, lineNumber, comment) {
var start = comment.loc.start,
end = comment.loc.end;
end = comment.loc.end,
isFirstTokenOnLine = !line.slice(0, comment.loc.start.column).trim();


return comment &&
(start.line < lineNumber || (start.line === lineNumber && start.column === 0)) &&
(start.line < lineNumber || (start.line === lineNumber && isFirstTokenOnLine)) &&
(end.line > lineNumber || end.column === line.length);
}

Expand Down
52 changes: 52 additions & 0 deletions tests/lib/rules/max-len.js
Expand Up @@ -248,6 +248,58 @@ ruleTester.run("max-len", rule, {
column: 1
}
]
}, {
code: "function foo() {\n" +
"//this is a long comment this is a long comment this is a long comment this is a long comment this is a long commentthis is a long comment this is a long comment this is a long comment this is a long comment this is a long commentthis is a long comment this is a long comment this is a long comment this is a long comment this is a long comment\n" +
"}",
options: [40, 4],
errors: [
{
message: "Line 2 exceeds the maximum line length of 40.",
type: "Program",
line: 2,
column: 1
}
]
}, {
code: "function foo() {\n" +
"//this is a long comment this is a long comment this is a long comment this is a long comment this is a long commentthis is a long comment this is a long comment this is a long comment this is a long comment this is a long commentthis is a long comment this is a long comment this is a long comment this is a long comment this is a long comment\n" +
"}",
options: [40, 4, { comments: 50 }],
errors: [
{
message: "Line 2 exceeds the maximum comment line length of 50.",
type: "Program",
line: 2,
column: 1
}
]
}, {
code: "function foo() {\n" +
" //this is a long comment this is a long comment this is a long comment this is a long comment this is a long commentthis is a long comment this is a long comment this is a long comment this is a long comment this is a long commentthis is a long comment this is a long comment this is a long comment this is a long comment this is a long comment\n" +
"}",
options: [40, 4],
errors: [
{
message: "Line 2 exceeds the maximum line length of 40.",
type: "Program",
line: 2,
column: 1
}
]
}, {
code: "function foo() {\n" +
" //this is a long comment this is a long comment this is a long comment this is a long comment this is a long commentthis is a long comment this is a long comment this is a long comment this is a long comment this is a long commentthis is a long comment this is a long comment this is a long comment this is a long comment this is a long comment\n" +
"}",
options: [40, 4, { comments: 50 }],
errors: [
{
message: "Line 2 exceeds the maximum comment line length of 50.",
type: "Program",
line: 2,
column: 1
}
]
}
]
});

0 comments on commit 7809d2f

Please sign in to comment.