diff --git a/lib/rules/jsx-closing-bracket-location.js b/lib/rules/jsx-closing-bracket-location.js index 51fc3cf9b2..c2a08906c3 100644 --- a/lib/rules/jsx-closing-bracket-location.js +++ b/lib/rules/jsx-closing-bracket-location.js @@ -57,7 +57,7 @@ module.exports = function(context) { if (typeof tokens.lastProp === 'undefined') { location = 'after-tag'; // Is always after the last prop if this one is on the same line as the opening bracket - } else if (tokens.opening.line === tokens.lastProp.line) { + } else if (tokens.opening.line === tokens.lastProp.firstLine) { location = 'after-props'; // Else use configuration dependent on selfClosing property } else { @@ -97,7 +97,7 @@ module.exports = function(context) { case 'after-tag': return tokens.tag.line === tokens.closing.line; case 'after-props': - return tokens.lastProp.line === tokens.closing.line; + return tokens.lastProp.lastLine === tokens.closing.line; case 'props-aligned': case 'tag-aligned': case 'line-aligned': @@ -124,7 +124,8 @@ module.exports = function(context) { lastProp = node.attributes[node.attributes.length - 1]; lastProp = { column: sourceCode.getFirstToken(lastProp).loc.start.column, - line: sourceCode.getLastToken(lastProp).loc.end.line + firstLine: sourceCode.getFirstToken(lastProp).loc.start.line, + lastLine: sourceCode.getLastToken(lastProp).loc.end.line }; } var openingLine = sourceCode.lines[opening.line - 1]; @@ -170,7 +171,7 @@ module.exports = function(context) { if (correctColumn !== null) { expectedNextLine = tokens.lastProp && - (tokens.lastProp.line === tokens.closing.line); + (tokens.lastProp.lastLine === tokens.closing.line); data.details = ' (expected column ' + (correctColumn + 1) + (expectedNextLine ? ' on the next line)' : ')'); } diff --git a/tests/lib/rules/jsx-closing-bracket-location.js b/tests/lib/rules/jsx-closing-bracket-location.js index 8c4e374235..92db8a299c 100644 --- a/tests/lib/rules/jsx-closing-bracket-location.js +++ b/tests/lib/rules/jsx-closing-bracket-location.js @@ -186,6 +186,38 @@ ruleTester.run('jsx-closing-bracket-location', rule, { ].join('\n'), options: [{location: 'line-aligned'}], parserOptions: parserOptions + }, { + code: [ + '' + ].join('\n'), + options: [{location: 'after-props'}], + parserOptions: parserOptions + }, { + code: [ + '' + ].join('\n'), + options: [{location: 'props-aligned'}], + parserOptions: parserOptions + }, { + code: [ + '' + ].join('\n'), + options: [{location: 'tag-aligned'}], + parserOptions: parserOptions + }, { + code: [ + '' + ].join('\n'), + options: [{location: 'line-aligned'}], + parserOptions: parserOptions }, { code: [ '',