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] Ternary doesn't allow extended indentation

See original GitHub issue

Tell us about your environment

  • ESLint Version: whatever is on the DEMO on eslint.org, unfortunately it doesn’t show
  • Node Version: n/a
  • npm Version: m/a
  • What parser (default, Babel-ESLint, etc.) are you using? dunno, environments is set to node, es6

Please show your full configuration: indent is on

What did you do? Please include the actual source code causing the issue.

const foo = Math.random()
  ? {
      a: 3,
    }
  : {};

What did you expect to happen? No warning. What actually happened? Please include the actual, raw output from ESLint. 4:5 - Expected indentation of 2 spaces but found 4. (indent)

Issue Analytics

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

github_iconTop GitHub Comments

4reactions
xixixaocommented, Dec 10, 2016

I agree this is duplicate of #6606. We use this style pretty consistently, including with JSX and other expressions, where lint doesn’t error:

// works
const foo = Math.random()
  ? <div
      id="test",
    />
  : null;
// works
const foo = Math.random()
  ? parseInt(
      "42",
      16,
    )
  : 0;

I see that this doesn’t work as well when the indentation isn’t two spaces and don’t really have an answer for that, as I personally don’t have experience with JS using different config. Perhaps if this was a configuration flag, it would only be used by people who have indent set to 2.

0reactions
not-an-aardvarkcommented, Aug 14, 2017

Closing because this is working as intended.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to indent a long ternary condition in Php? - Stack Overflow
I have a long ternary condition in Php that exceeds the 120 hard rule. What would be the right indentation according to PSR...
Read more >
Multi-line ternary in multi-line array: Indentation problem.
ArrayIndentation) insists that when using a multi-line ternary expression ... all lines should be indented at the level of the array values.
Read more >
Linux kernel coding style
Rationale: The whole idea behind indentation is to clearly define where a block of control starts and ends. Especially when you've been looking...
Read more >
PSR-12: Extended Coding Style - PHP-FIG
2.4 Indenting¶. Code MUST use an indent of 4 spaces for each indent level, and MUST NOT use tabs for indenting. 2.5 Keywords...
Read more >
Remove braces from `if-else` where a single-line ternary could ...
I just want to (re-)open the discussion on it and also share my design insight about a block indenting design versus Rust's brace-delimited ......
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