Skip to content

Commit

Permalink
Fix: nested indenting for offsetTernaryExpressions: true (fixes #13971)…
Browse files Browse the repository at this point in the history
… (#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>
  • Loading branch information
brodybits and sheerun committed Jan 30, 2021
1 parent 1a078b9 commit e1da90f
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
1 change: 1 addition & 0 deletions lib/rules/indent.js
Expand Up @@ -1178,6 +1178,7 @@ module.exports = {
offsets.setDesiredOffset(colonToken, firstToken, 1);

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

/*
Expand Down
20 changes: 20 additions & 0 deletions tests/lib/rules/indent.js
Expand Up @@ -2204,6 +2204,26 @@ 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`
condition1
? Promise.resolve(1)
: condition2
? Promise.resolve(2)
: Promise.resolve(3)
`,
options: [2, { offsetTernaryExpressions: true }]
},
{
code: unIndent`
condition
Expand Down

0 comments on commit e1da90f

Please sign in to comment.