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.

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.

cc @not-an-aardvark @mysticatea

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:11 (11 by maintainers)

github_iconTop GitHub Comments

2reactions
mysticateacommented, Apr 25, 2017

I know indentation is very complex… I will get time in the next week, a long vacation in Japan, so I will investigate this.

0reactions
mysticateacommented, Apr 25, 2017
// case 3
var foo = {
    ok: true
};

// case 4
var foo =
    {
        ok: true
    };

// case 5
var foo = {
        ok: true
    },
    bar = 3;

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.

Read more comments on GitHub >

github_iconTop 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 >

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