8000 Fix: nested indenting for offsetTernaryExpressions: true (fixes #1397… · eslint/eslint@e1da90f · GitHub
[go: up one dir, main page]

Skip to content

Commit e1da90f

Browse files
Chris Brodysheerun
andauthored
Fix: nested indenting for offsetTernaryExpressions: true (fixes #13971) (#13972)
* reproduce extra nested ternary indentation with a test * add a similar test with proper indenting of nested ternary * apply condition to avoid extra indenting with offsetTernaryExpressions Co-authored-by: Adam Stankiewicz <sheerun@sher.pl> Co-authored-by: Adam Stankiewicz <sheerun@sher.pl>
1 parent 1a078b9 commit e1da90f

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed

lib/rules/indent.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1178,6 +1178,7 @@ module.exports = {
11781178
offsets.setDesiredOffset(colonToken, firstToken, 1);
11791179

11801180
offsets.setDesiredOffset(firstConsequentToken, firstToken,
1181+
firstConsequentToken.type === "Punctuator" &&
11811182
options.offsetTernaryExpressions ? 2 : 1);
11821183

11831184
/*

tests/lib/rules/indent.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2204,6 +2204,26 @@ ruleTester.run("indent", rule, {
22042204
`,
22052205
options: [4, { offsetTernaryExpressions: true }]
22062206
},
2207+
{
2208+
code: unIndent`
2209+
condition1
2210+
? condition2
2211+
? Promise.resolve(1)
2212+
: Promise.resolve(2)
2213+
: Promise.resolve(3)
2214+
`,
2215+
options: [2, { offsetTernaryExpressions: true }]
2216+
},
2217+
{
2218+
code: unIndent`
2219+
condition1
2220+
? Promise.resolve(1)
2221+
: condition2
2222+
? Promise.resolve(2)
2223+
: Promise.resolve(3)
2224+
`,
2225+
options: [2, { offsetTernaryExpressions: true }]
2226+
},
22072227
{
22082228
code: unIndent`
22092229
condition

0 commit comments

Comments
 (0)
0