From 1dc0f0fdc9e1998d35fab26506c3a91e9f1c3b17 Mon Sep 17 00:00:00 2001 From: "Christopher J. Brody" Date: Thu, 31 Dec 2020 19:44:06 -0500 Subject: [PATCH 1/3] reproduce extra nested ternary indentation with a test --- tests/lib/rules/indent.js | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/tests/lib/rules/indent.js b/tests/lib/rules/indent.js index ad35ad09c70..5a71a68c06a 100644 --- a/tests/lib/rules/indent.js +++ b/tests/lib/rules/indent.js @@ -2204,6 +2204,16 @@ ruleTester.run("indent", rule, { `, options: [4, { offsetTernaryExpressions: true }] }, + { + code: unIndent` + condition1 + ? condition2 + ? Promise.resolve(1) + : Promise.resolve(2) + : Promise.resolve(3) + `, + options: [2, { offsetTernaryExpressions: true }] + }, { code: unIndent` condition From 266a06d01bcd6ff81cc8ccaf2731e4ec31862113 Mon Sep 17 00:00:00 2001 From: "Christopher J. Brody" Date: Thu, 31 Dec 2020 19:47:58 -0500 Subject: [PATCH 2/3] add a similar test with proper indenting of nested ternary --- tests/lib/rules/indent.js | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/tests/lib/rules/indent.js b/tests/lib/rules/indent.js index 5a71a68c06a..e7ad6074c49 100644 --- a/tests/lib/rules/indent.js +++ b/tests/lib/rules/indent.js @@ -2214,6 +2214,16 @@ ruleTester.run("indent", rule, { `, options: [2, { offsetTernaryExpressions: true }] }, + { + code: unIndent` + condition1 + ? Promise.resolve(1) + : condition2 + ? Promise.resolve(2) + : Promise.resolve(3) + `, + options: [2, { offsetTernaryExpressions: true }] + }, { code: unIndent` condition From 8ed37bb1f2d0e340aa0636e9bcb7285eb50c891f Mon Sep 17 00:00:00 2001 From: "Christopher J. Brody" Date: Fri, 29 Jan 2021 14:41:01 -0500 Subject: [PATCH 3/3] apply condition to avoid extra indenting with offsetTernaryExpressions Co-authored-by: Adam Stankiewicz --- lib/rules/indent.js | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/rules/indent.js b/lib/rules/indent.js index 1c0dccc5c98..8f4079d31f9 100644 --- a/lib/rules/indent.js +++ b/lib/rules/indent.js @@ -1178,6 +1178,7 @@ module.exports = { offsets.setDesiredOffset(colonToken, firstToken, 1); offsets.setDesiredOffset(firstConsequentToken, firstToken, + firstConsequentToken.type === "Punctuator" && options.offsetTernaryExpressions ? 2 : 1); /*