dotnet/roslyn

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

Open

#21,138 opened on Jul 26, 2017

View on GitHub
 (15 comments) (0 reactions) (0 assignees)C# (20,414 stars) (4,257 forks)batch import
Area-IDEBugIDE-Formatterhelp wanted

Description

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

Contributor guide