diff --git a/lib/rules/max-len.js b/lib/rules/max-len.js index 35ac803b65e..5a6eaa72f1e 100644 --- a/lib/rules/max-len.js +++ b/lib/rules/max-len.js @@ -213,7 +213,8 @@ module.exports = { * @returns {ASTNode[]} An array of string nodes. */ function getAllStrings() { - return sourceCode.ast.tokens.filter(token => token.type === "String"); + return sourceCode.ast.tokens.filter(token => (token.type === "String" || + (token.type === "JSXText" && sourceCode.getNodeByRangeIndex(token.range[0] - 1).type === "JSXAttribute"))); } /** diff --git a/tests/lib/rules/max-len.js b/tests/lib/rules/max-len.js index 4180a887950..caa5f3d5639 100644 --- a/tests/lib/rules/max-len.js +++ b/tests/lib/rules/max-len.js @@ -109,6 +109,11 @@ ruleTester.run("max-len", rule, { code: "var str = \"this is a very long string\\\nwith continuation\\\nand with another very very long continuation\\\nand ending\";", options: [29, 4, { ignoreStrings: true }] }, + { + code: "var foo =
;", + options: [29, 4, { ignoreStrings: true }], + parserOptions: { ecmaFeatures: { jsx: true } } + }, { code: "var foo = veryLongIdentifier;\nvar bar = `this is a very long string`;", options: [29, 4, { ignoreTemplateLiterals: true }], @@ -553,6 +558,19 @@ ruleTester.run("max-len", rule, { } ] }, + { + code: "var foo =
this is a very very very long string
;", + options: [29, 4, { ignoreStrings: true }], + parserOptions: { ecmaFeatures: { jsx: true } }, + errors: [ + { + message: "Line 1 exceeds the maximum line length of 29.", + type: "Program", + line: 1, + column: 1 + } + ] + }, // Multi-code-point unicode glyphs {