dotnet/roslyn

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

Ouverte

#21 138 ouverte le 26 juil. 2017

 (15 commentaires) (0 réaction) (0 personne assignée)C# (4 257 forks)batch import
Area-IDEBugIDE-Formatterhelp wanted

Métriques du dépôt

Stars
 (20 414 étoiles)
Métriques de merge PR
 (Merge moyen 6j 17h) (256 PRs mergées en 30 j)

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

Guide contributeur