question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

New Rule Proposal: Enforce indentation of ternary expressions on multiple lines

See original GitHub issue

Please describe what the rule should do:

Enforce predictable indentation of ternary expression alternatives on separate lines.

var location = env.development
  ? 'localhost'
  : 'www.api.com'
var location = env.development
    ? 'localhost'
    : 'www.api.com'

Neither multiline-ternary nor operator-linebreak enforce such indentation.

What category of rule is this? (place an “X” next to just one item)

[X] Enforces code style [ ] Warns about a potential error [ ] Suggests an alternate way of doing something [ ] Other (please specify:)

Provide 2-3 code examples that this rule will warn about:

Less than expected indentation:

var location = env.development
? 'localhost'
: 'www.api.com'

Irregular indentation:

var location = env.development
   ? 'localhost'
       : 'www.api.com'

More than expected indentation:

var location = env.development
              ? 'localhost'
              : 'www.api.com'

Why should this rule be included in ESLint (instead of a plugin)?

The rule would fill a gap in core’s enforcement of fixed and predictable indentation.


Related: feross/eslint-config-standard#46

cc @feross @dcousens

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Reactions:3
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

6reactions
not-an-aardvarkcommented, Oct 21, 2016

Thanks for the suggestion. I think we should check for this, but in my opinion it would be better if the existing indent rule was in charge of it (either by default or with an opt-in option), rather than having a separate rule just for ternary expressions. I would say not checking ternary expressions is a bug in the indent rule, although we would have to make sure that we don’t cause too large an ecosystem impact by breaking everyone’s builds with a bugfix.

(For what it’s worth, there’s a rewrite of the indent rule in progress, which checks ternary expressions by default along with some other cases that aren’t currently checked.)

2reactions
platinumazurecommented, Oct 21, 2016

Agreed with @not-an-aardvark, this absolutely belongs in “indent”.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Enforce newlines between operands of ternary expressions if ...
This rule enforces or disallows newlines between operands of a ternary expression. Note: The location of the operators is not enforced by this ......
Read more >
multiline-ternary - ESLint - Pluggable JavaScript Linter
This rule enforces or disallows newlines between operands of a ternary expression. Note: The location of the operators is not enforced by this...
Read more >
Proposed JavaScript Coding Standards Revisions for Prettier ...
In this post, we propose several small changes of the coding ... But the parts of a ternary operator are put on the...
Read more >
eclipse - ternary formatting still broken? - Stack Overflow
I have set it to wrap every element on a new line. Sometimes auto save puts everything on one line. Sometimes the first...
Read more >
Airbnb JavaScript Style Guide()
7.15 Functions with multiline signatures, or invocations, should be indented just like every other multiline list in this guide: with each item on...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found