dotnet/roslyn

Visual Studio only formats if/while(...) when contents of (...) requires formatting

Aperta

#21.138 aperta il 26 lug 2017

 (15 commenti) (0 reazioni) (0 assegnatari)C# (4257 fork)batch import
Area-IDEBugIDE-Formatterhelp wanted

Metriche repository

Star
 (20.414 stelle)
Metriche merge PR
 (Merge medio 6g 17h) (256 PR mergiate in 30 g)

Descrizione

Version Used:

Visual Studio 2015 - 2017 (15.2)

Steps to Reproduce:

  1. Enter if(true == false){ or while(true == false){ in the Visual Studio editor.

Expected Behavior:

I'd expect this to be formatted to while (true == false) { }.

Actual Behavior:

It is actually formatted to while(true == false) { }. (note the missing after the while(.

If you enter while(true==false){, it gets formatted to while (true == false) { as I'd expect. if(true){ also becomes if (true) {.

It's actually different with for(var x=0;x<10;x++){, which becomes for(var x = 0; x < 10; x++) { }. In this case no is inserted in the for( despite the contents of (...) being formatted.

image

Because this behavior is inconsistent between (true) and (true == false), I'm constantly getting tripped up by it. 😭

See Twitter thread here: https://twitter.com/jcansdale/status/890186489912545282

Guida contributor