Roslyn: csharp_new_line_before_open_brace Not Working

Created on 21 Mar 2017  路  8Comments  路  Source: dotnet/roslyn

(Migrated from madskristensen/EditorConfigLanguage#11 on behalf of @RehanSaeed.)

Installed product versions

  • Visual Studio: 2017
  • This extension: 1.16.198

Description

The csharp_new_line_before_open_brace setting seems stuck on all. I was going to raise this in the roslyn repo but thought it might be a tooling issue in VS 2017.

Steps to recreate

  1. Add the following to .editorconfig:
[*.cs]
csharp_new_line_before_open_brace = all:warning
  1. Open a .cs file and hit Ctrl+K and Ctrl+D to format the code.
  2. The braces are formatted to use JavaScript style where they are on the same line as the class/method etc.
class Foo {
}
  1. Try values other than all and they all produce the same result.
Area-IDE Bug Resolution-By Design

Most helpful comment

@ygoe Yes that seems to work. all:warning not being allowed is the bug.

All 8 comments

This is an incorrect specification of this option.

csharp_new_line_before_open_brace = all:warning

csharp_new_line_before_open_brace can only have all or:

accessors
types
methods
properties
indexers
events
anonymous_methods
control_blocks
anonymous_types
object_collection_array_initalizers
lambdas
local_functions

The question is, what is the correct behavior in editor config when the user specifies an invalid option?

all was an item in the editorconfig VS extension's intellisense. If it's not allowed, the original issue should be reopened. What is the syntax for specifying one or more options?

@RehanSaeed Ehm, I believe @jmarolf said that "all" _is_ a valid option, but not "all:warning". Is that correct? At least that works for me. (I've set the code formatting in the VS settings otherwise and override that with the EditorConfig option for the test.)

@ygoe Yes that seems to work. all:warning not being allowed is the bug.

That is by design - we don't have an analyzer that allows warnings to be reported just for that single issue, and we probably won't.

What option to use if I don't want to have new line before open brace ?

Code example here

@dsoronda

If you don't want a newline before any open brace use the following

csharp_new_line_before_open_brace = none
csharp_new_line_before_catch = false
csharp_new_line_before_else = false
csharp_new_line_before_finally = false
csharp_new_line_before_members_in_anonymous_types = false
csharp_new_line_before_members_in_object_initializers = false

Thank you @jmarolf , it works now.

Just sidenote,
In one of your previous post here you enumerated options for csharp_new_line_before_open_brace, and value NONE is missing, as specified in documentation.

Cheers.

Was this page helpful?
0 / 5 - 0 ratings