Skip to content

Better ternary operator support #329

Closed
@ksmithbaylor

Description

@ksmithbaylor

I use ternary expressions a lot, as part of a more functional "assign-once" style. But I always have to manually adjust my indentation and make sure to never accidentally auto-indent the parts of my code that use them. Here's the indentation I would like to use:

// single-line values
const foo = condition ?
  trueValue :
  falseValue;
nextLineOfCode();
// alternate style
const foo = condition
  ? trueValue
  : falseValue;
nextLineOfCode();
// multi-line values
const foo = condition ? (
  moreComplex(
    multiLineStatement
  )
) : (
  otherMultilineStatement(
    ohNo
  )
);

However, the current implementation indents this code like so:

// single-line values
const foo = condition ?
  trueValue :
    falseValue;
    nextLineOfCode();
// alternate style
const foo = condition
  ? trueValue
  : falseValue;
  nextLineOfCode();
// multi-line values
const foo = condition ? (
  moreComplex(
    multiLineStatement
  )
) : (
otherMultilineStatement(
  ohNo
)
);

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions