From 3e6cc1513f8eb30ebe7706ef3d625a43c7b30ec0 Mon Sep 17 00:00:00 2001 From: Stefan Buck Date: Mon, 16 Dec 2019 20:27:39 +0100 Subject: [PATCH] [Fix] `jsx-indent`: Fix indent handling for closing parentheses Fixes #618. --- lib/rules/jsx-indent.js | 12 ++++++++ tests/lib/rules/jsx-indent.js | 52 +++++++++++++++++++++++++++++++++-- 2 files changed, 62 insertions(+), 2 deletions(-) diff --git a/lib/rules/jsx-indent.js b/lib/rules/jsx-indent.js index fa81f8f673..ca9e82b3c5 100644 --- a/lib/rules/jsx-indent.js +++ b/lib/rules/jsx-indent.js @@ -352,6 +352,18 @@ module.exports = { } const parentNodeIndent = getNodeIndent(node.parent); checkNodesIndent(node, parentNodeIndent + indentSize); + }, + ReturnStatement(node) { + if (!node.parent) { + return; + } + + const openingIndent = getNodeIndent(node); + const closingIndent = getNodeIndent(node, true); + + if (closingIndent !== openingIndent) { + report(node, openingIndent, closingIndent); + } } }; } diff --git a/tests/lib/rules/jsx-indent.js b/tests/lib/rules/jsx-indent.js index af01578abc..834522da2a 100644 --- a/tests/lib/rules/jsx-indent.js +++ b/tests/lib/rules/jsx-indent.js @@ -956,6 +956,26 @@ const Component = () => ( } `, options: [2, {indentLogicalExpressions: true}] + }, { + code: [ + 'function App() {', + ' return (', + ' ', + ' );', + '}' + ].join('\n'), + options: [2], + parserOptions + }, { + code: [ + 'function App() {', + ' return ', + ' ', + ' ;', + '}' + ].join('\n'), + options: [2], + parserOptions }], invalid: [{ @@ -1038,7 +1058,10 @@ const Component = () => ( '}' ].join('\n'), options: [2], - errors: [{message: 'Expected indentation of 2 space characters but found 9.'}] + errors: [ + {message: 'Expected indentation of 2 space characters but found 9.'}, + {message: 'Expected indentation of 2 space characters but found 9.'} + ] }, { code: [ 'function App() {', @@ -1055,7 +1078,10 @@ const Component = () => ( '}' ].join('\n'), options: [2], - errors: [{message: 'Expected indentation of 2 space characters but found 4.'}] + errors: [ + {message: 'Expected indentation of 2 space characters but found 4.'}, + {message: 'Expected indentation of 2 space characters but found 4.'} + ] }, { code: [ 'function App() {', @@ -1883,5 +1909,27 @@ const Component = () => ( errors: [ {message: 'Expected indentation of 8 space characters but found 4.'} ] + }, { + code: [ + 'function App() {', + ' return (', + ' ', + ' );', + '}' + ].join('\n'), + options: [2], + parserOptions, + errors: [{message: 'Expected indentation of 2 space characters but found 4.'}] + }, { + code: [ + 'function App() {', + ' return (', + ' ', + ');', + '}' + ].join('\n'), + options: [2], + parserOptions, + errors: [{message: 'Expected indentation of 2 space characters but found 0.'}] }] });