Skip to content
Permalink
Browse files
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>
  • Loading branch information
brodybits and sheerun committed Jan 30, 2021
1 parent 1a078b9 commit e1da90fc414a3c9c16f52db4a5bd81bd4f9532a4
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
@@ -1178,6 +1178,7 @@ module.exports = {
offsets.setDesiredOffset(colonToken, firstToken, 1);

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

/*
@@ -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

0 comments on commit e1da90f

Please sign in to comment.