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.

Please include the ability to configure indent on conditional expressions

See original GitHub issue

What rule do you want to change? indent

Does this change cause the rule to produce more or fewer warnings? more

How will the change be implemented? (New option, new default behavior, etc.)? new option

Please provide some example code that this change will affect:

Existing:

        'indent': [
            'error',
            4,
            {
                'CallExpression': {
                    'arguments': 2,
                },
                'FunctionDeclaration': {
                    'body': 1,
                    'parameters': 2,
                },
                'FunctionExpression': {
                    'body': 1,
                    'parameters': 2,
                },
                'MemberExpression': 2,
                'ObjectExpression': 1,
                'SwitchCase': 1,
                'ignoredNodes': [
                    'ConditionalExpression',
                ],
            },
        ],

Desired (Example):

        'indent': [
            'error',
            4,
            {
                'CallExpression': {
                    'arguments': 2,
                },
                'FunctionDeclaration': {
                    'body': 1,
                    'parameters': 2,
                },
                'FunctionExpression': {
                    'body': 1,
                    'parameters': 2,
                },
                'MemberExpression': 2,
                'ObjectExpression': 1,
                'SwitchCase': 1,
                'ConditionalExpression: 1,
            },
        ],

What does the rule currently do for this code? The only way to configure indent behavior for conditional (ternary) expressions is to ignore them completely

What will the rule do after it’s changed? Conditional expressions will be configurable, just as every other kind of expression. At the very least, it should be possible to automatically bring conditional expressions into conformance with the rest of the code base, which it does not currently seem to do.

Are you willing to submit a pull request to implement this change? I have no idea how to do that. Maybe if you can give me enough of a description on how to make it happen, I could give it a shot, but I am not familiar at all with JS, so my code might be less than great.

Issue Analytics

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

github_iconTop GitHub Comments

5reactions
kaicataldocommented, Dec 18, 2019

These seem like two separate issues to me - do you mind creating a separate issue for the latter one?

I don’t think we’re quite on the same page. The indent rule enforces indentation but doesn’t add newlines. You can see an example here.

It sounds like what you’re looking for is the following:

/*eslint indent: ["error", 4, { "ConditionalExpression": 2 }]*/

// Incorrect
foo ?
    bar => {
        function();
    } :
    baz;

// Correct
foo ?
        bar => {
            function();
        } :
        baz;
/*eslint indent: ["error", 4, { "ConditionalExpression": 2, "flatTernaryExpressions": false }]*/

// Incorrect
var a =
    foo ? bar :
    baz ? qux :
    boop;


// Correct
var a =
    foo ? bar :
            baz ? qux :
                    boop;
/*eslint indent: ["error", 4, { "ConditionalExpression": 2, "flatTernaryExpressions": true }]*/

// Inorrect
var a =
    foo ? bar :
            baz ? qux :
                    boop;

// Correct
var a =
        foo ? bar :
        baz ? qux :
        boop;
0reactions
eslint-deprecated[bot]commented, Jan 18, 2020

Unfortunately, it looks like there wasn’t enough interest from the team or community to implement this change. While we wish we’d be able to accommodate everyone’s requests, we do need to prioritize. We’ve found that issues failing to reach accepted status after 21 days tend to never be accepted, and as such, we close those issues. This doesn’t mean the idea isn’t interesting or useful, just that it’s not something the team can commit to.

Thanks for contributing to ESLint and we appreciate your understanding.

Read more comments on GitHub >

github_iconTop Results From Across the Web

indent: add option for multiline [assignment] statement #12248
kaicataldo mentioned this issue on Dec 16, 2019. Please include the ability to configure indent on conditional expressions #12674.
Read more >
Indenting C Programs
Always indent the body (bodies) of a statement a uniform amount from the first character of the statement. The "body" of a statement...
Read more >
4. Conditionals and loops — Beginning Python Programming ...
Conditional statements give us this ability. The simplest form is the if statement, ... Each statement inside the block must have the same...
Read more >
Conditional execution - PY4E - Python for Everybody
If the logical condition is true, then the indented statement gets executed. If the logical condition is false, the indented statement is skipped....
Read more >
How do you indent preprocessor statements? - Stack Overflow
In visual studio go to options search for indent and select your language. In my case it is c++. As you toggle between...
Read more >

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