New Rule Proposal: Enforce indentation of ternary expressions on multiple lines
See original GitHub issuePlease 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
Issue Analytics
- State:
- Created 7 years ago
- Reactions:3
- Comments:5 (3 by maintainers)
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
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.)
Agreed with @not-an-aardvark, this absolutely belongs in “indent”.