indent flatTernaryExpressions is broken when conditions and values are on the same line
See original GitHub issue- ESLint Version: 4.0.0-alpha.0
- default parser
/*eslint indent: [2, 4, {"flatTernaryExpressions": true}] */
var foo =
d >= 10 ? 10 :
d >= 5 ? 5 :
d >= 2 ? 2 :
d >= 1 ? 1 : 0;
What did you expect to happen? No errors.
What actually happened?
5:1 error Expected indentation of 8 spaces but found 4 indent
6:1 error Expected indentation of 8 spaces but found 4 indent
7:1 error Expected indentation of 8 spaces but found 4 indent
ESLint suggest the following formatting, which doesn’t make sense:
var foo =
d >= 10 ? 10 :
d >= 5 ? 5 :
d >= 2 ? 2 :
d >= 1 ? 1 : 0;
BTW, I strongly believe that flatTernaryExpressions
should be true
by default. I’ve never in my life seen this zigzag-style ternary formatting in any projects, while the flat style is pretty much everywhere.
Thanks a lot! Apart from this nitpick, the new indent rule is really awesome! Worked great on a 40k-line project I maintain.
Issue Analytics
- State:
- Created 6 years ago
- Comments:11 (11 by maintainers)
Top Results From Across the Web
indent - ESLint - Pluggable JavaScript Linter
A pluggable and configurable linter tool for identifying and reporting on patterns in JavaScript. Maintain your code quality with ease.
Read more >Cannot fix eslint rule on indenting case statements in switch ...
According to the docs, it is the correct way to set the desired indent for switch statements. "SwitchCase" (default: 0) enforces indentation ......
Read more >eslint | Yarn - Package Manager
ESLint is a tool for identifying and reporting on patterns found in ECMAScript/JavaScript code. In many ways, it is similar to JSLint and...
Read more >griebnitz/node_modules/eslint/CHANGELOG.md - GitLab
6cb63fd Update: Add iife to padding-line-between-statements (fixes ... 3418479a Update: improve indent of flatTernaryExpressions (fixes ...
Read more >vue/html-indent
The multiplier of indentation for right brackets of start tags ( <div/> ). Default is 0 . alignAttributesVertically ( boolean ) ... Condition...
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
I know indentation is very complex… I will get time in the next week, a long vacation in Japan, so I will investigate this.
I think the case 3 is a special case. The initializer expression body has own indentation level of the object literal, so people probably want to avoid over indentation. However, I think initializer expressions have one indentation basically.