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.

Incorrect indentation for single line if/for/while/etc, multiline chaining statements etc

See original GitHub issue

I am experiencing some weird indentation issues. Not using any plugins to prettify or similar.

if (condition) {
    return; // <-- correct indentation
}
if(condition)
return; // <-- incorrect indentation

Some ppl claim this should be avoided. I don’t agree. Using pair of { } for simple early exits messes up code. Putting the return on the end of the same line can be hard to read if the condition is long. This is not exclusive to return. Applies to all single lines.

same problems apply to for, while, etc.

var transformedValues =
originalValues <-- incorrect should be indented one level.
.where(condition) <-- incorrect, should be indented two levels.
.select(transform); <-- incorrect, should be indented two levels. 

function someFunction() {
    callToSomeOtherFunction(
         variableWithLongNameWhichRequiresASeparateLine,
         anotherVariableWithLongNameWhichRequiresASeparateLine);
    }  <-- incorrect should not be indented.
    function ... <-- incorrect the rest of the file is indented. 

Issue Analytics

  • State:open
  • Created 6 years ago
  • Reactions:33
  • Comments:52 (4 by maintainers)

github_iconTop GitHub Comments

11reactions
Spongmancommented, Jan 15, 2020

yet another trivial error:

return true ? {
} : {
	};

i don’t understand why this is labeled feature-request and not bug.

9reactions
ciabaroscommented, May 29, 2020

I’ve seen developers argue that this is not a bug, and others argue that you should use braces, and never single line indented statements (which is all wrong or absurdly opinionated).

The bizarre part is that every single other editor with auto indentation seems to do it right, including all versions of full Visual Studio, since beginning of time. I don’t get it… why can’t you just do what VS (full) does?

Yes, I can use another editor, and no, my problem isn’t lack of effort by the devs for a free product, it’s the mind blowing attitude that this is not a problem or not one worth fixing for like 5 years now.

I’m used to VS Code and otherwise love it, but it has now become second nature to fix indentation after all single-line if/else/while/for/etc. – why is this so hard to finally fix??

Read more comments on GitHub >

github_iconTop Results From Across the Web

Auto-indent lines feature wrongly indents multiline chained ...
prefetch_related( statements have the wrong indent. The gray underline appears, and the tooltip warns: "PEP8: continuation line unaligned for hanging indent".
Read more >
C# at Google Style Guide | styleguide
Developed from Google Java style. A maximum of one statement per line. A maximum of one assignment per statement. Indentation of 2 spaces,...
Read more >
What is the proper way to format a multi-line dict in Python?
I use #3. Same for long lists, tuples, etc. It doesn't require adding any extra spaces beyond the indentations. As always, be consistent....
Read more >
Visual Studio Code: Formatting Java Method Chaining
Incorrect indentation for single line if/for/while/etc multiline chaining statements etc #43244 Line after braceless if statement doesn't autoindent #41702 ...
Read more >
D95168 [clang-format] Add Insert/Remove Braces option - LLVM
InsertBraces will insert braces for single line control flow statements (currently if/else/for). It currently accepts the following options:.
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