From 625010a70af2ab83398c7d1ee591fbe0fcd98d4c Mon Sep 17 00:00:00 2001 From: Jordan Harband Date: Fri, 25 Feb 2022 12:22:43 -0800 Subject: [PATCH] [Fix] `jsx-indent`: properly report on returned ternaries with jsx Fixes #3222 --- CHANGELOG.md | 1 + lib/rules/jsx-indent.js | 5 ++++- tests/lib/rules/jsx-indent.js | 10 ++++++++++ 3 files changed, 15 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0f02a3c3cd..59a693f1cc 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,7 @@ This change log adheres to standards from [Keep a CHANGELOG](https://keepachange ### Fixed * [`jsx-curly-brace-presence`]: avoid warning on curlies containing quote characters ([#3214][] @ljharb) * [`jsx-indent`]: do not report on non-jsx-returning ternaries that contain null ([#3222][] @ljharb) +* [`jsx-indent`]: properly report on returned ternaries with jsx ([#3222][] @ljharb) [#3222]: https://github.com/yannickcr/eslint-plugin-react/issues/3222 [#3214]: https://github.com/yannickcr/eslint-plugin-react/issues/3214 diff --git a/lib/rules/jsx-indent.js b/lib/rules/jsx-indent.js index ed636b4dcb..88d177d30e 100644 --- a/lib/rules/jsx-indent.js +++ b/lib/rules/jsx-indent.js @@ -415,7 +415,10 @@ module.exports = { JSXText: handleLiteral, ReturnStatement(node) { - if (!node.parent) { + if ( + !node.parent + || !jsxUtil.isJSX(node.argument) + ) { return; } diff --git a/tests/lib/rules/jsx-indent.js b/tests/lib/rules/jsx-indent.js index bfad110947..ce4733d8fa 100644 --- a/tests/lib/rules/jsx-indent.js +++ b/tests/lib/rules/jsx-indent.js @@ -1219,6 +1219,16 @@ const Component = () => ( `, options: [99], }, + { + code: ` + function test (foo) { + return foo != null + ?
foo
+ :
bar
+ } + `, + options: [2], + }, ]), invalid: parsers.all([].concat(