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.

Make 'indent' rule configurable w.r.t ternary conditions

See original GitHub issue

ESLint version 3.0.0, babel-eslint parser

Rule: http://eslint.org/docs/rules/indent

Problem: Ternaries can be formatted better when used for multi-line conditionals, ‘indent’ rule currently does not allow this.

Example of the formatting pattern:

const object = cond
  ? {
      foo: 'bar'
    }
  : {
      baz: 'qux'
    }

Notice how the braces line up and are easy to visually scan compared to this, which is what the ‘indent’ rule currently expects:

const object = cond
  ? {
    foo: 'bar'
  }
  : {
    baz: 'qux'
  }

This goes for parenthetical expressions, multi-line function calls, and array literals as well.

Solution: I propose a new option for ‘indent’ called "multilineTernary" that defaults to level 1 like the other opinionated ‘indent’ options, and which enforces the above pattern rather than the below.

Issue Analytics

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

github_iconTop GitHub Comments

4reactions
jonvuricommented, Aug 2, 2016

If it’s a matter of time commitment, I’d be happy to make a pull request. It sounds like those who weighed in so far wouldn’t use this multi-line style to begin with, so changing the behavior of lines following infix-operator-begun lines wouldn’t affect them anyway. Can we instead have the discussion from the standpoint of assuming this style (which is valid), and then what indentation should be enforced for that style?

2reactions
idbartoszcommented, Dec 7, 2017

@Naoto-Ida Dirty fix is disabling rules with inline comments

/* eslint-disable indent */
const object = cond
  ? {
      foo: 'bar'
    }
  : {
      baz: 'qux'
    } 
/* eslint-enable */

I look forward for this indentation syntax, maybe in 2018 😅

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to indent a long ternary condition in Php? - Stack Overflow
This is my ternary condition. The condition is a bit long, so the function call exceeds the 120 rule. $variable = (condition) ?...
Read more >
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 >
eslint/eslint - Gitter
I am trying to set up linting for a project. The same set up worked a couple of weeks ago. There might be...
Read more >
Untitled
... to 1.10.8 release - Fix race condition when cancelling a flash operation (rh ... (development) - core: make ipv6.addr-gen-mode default configurable (rh ......
Read more >
https://perldoc.perl.org/5.6.1/B::Deparse.txt
configurable syntax highlighting: ANSI color, HTML, TeX, etc. ... $cx); } sub indent { my $self = shift; my $txt = shift; my...
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