Visualstudio-docs: Missing EditorConfig coding convention settings

Created on 3 Jun 2018  Â·  26Comments  Â·  Source: MicrosoftDocs/visualstudio-docs

It seems like there are quite a few EditorConfig coding convention settings that are supported (see 1, 2, 3, 4) but not documented. Is there a reason why they are undocumented?

After a quick check it seems like all those settings are also available in the Visual Studio options GUI (under Text Editor -> C# -> Code Style). Also, if you use the function "Generate .editorconfig file from settings" from Visual Studio 2019, those undocumented settings are included in the generated file.

The following list of undocumented settings was updated for Visual Studio 2019 version 16.1 on 2019-05-24:

# .NET code style settings
dotnet_code_quality_unused_parameters
dotnet_style_prefer_compound_assignment

# .NET refactoring settings
dotnet_style_operator_placement_when_wrapping

# C# code style settings
csharp_prefer_simple_using_statement
csharp_prefer_static_local_function
csharp_style_expression_bodied_lambdas
csharp_style_expression_bodied_local_functions
csharp_style_prefer_index_operator
csharp_style_prefer_range_operator
csharp_style_unused_value_assignment_preference
csharp_style_unused_value_expression_statement_preference
csharp_using_directive_placement

# C# formatting conventions
csharp_indent_block_contents
csharp_indent_braces
csharp_indent_case_contents_when_block
csharp_space_between_method_declaration_name_and_open_parenthesis
csharp_space_around_declaration_statements
csharp_space_before_open_square_brackets
csharp_space_between_empty_square_brackets
csharp_space_between_square_brackets
csharp_space_after_comma
csharp_space_after_dot
csharp_space_after_semicolon_in_for_statement
csharp_space_before_comma
csharp_space_before_dot
csharp_space_before_semicolon_in_for_statement

Tasks:

  • [x] dotnet_code_quality_unused_parameters
  • [x] dotnet_style_prefer_compound_assignment
  • [x] csharp_prefer_simple_using_statement (C# 8)
  • [x] csharp_prefer_static_local_function (C# 8)
  • [x] csharp_style_expression_bodied_lambdas
  • [x] csharp_style_expression_bodied_local_functions
  • [x] csharp_style_prefer_index_operator (C# 8)
  • [x] csharp_style_prefer_range_operator (C# 8)
  • [x] csharp_style_unused_value_assignment_preference
  • [x] csharp_style_unused_value_expression_statement_preference
  • [x] csharp_using_directive_placement
  • [x] csharp_indent_block_contents
  • [x] csharp_indent_braces
  • [x] csharp_indent_case_contents_when_block
  • [x] csharp_space_between_method_declaration_name_and_open_parenthesis
  • [x] csharp_space_around_declaration_statements
  • [x] csharp_space_before_open_square_brackets
  • [x] csharp_space_between_empty_square_brackets
  • [x] csharp_space_between_square_brackets
  • [x] csharp_space_after_comma
  • [x] csharp_space_after_dot
  • [x] csharp_space_after_semicolon_in_for_statement
  • [x] csharp_space_before_comma
  • [x] csharp_space_before_dot
  • [x] csharp_space_before_semicolon_in_for_statement

Document Details

⚠ Do not edit this section. It is required for docs.microsoft.com ➟ GitHub issue linking.

Pri1 visual-studio-dev1prod vs-ide-generatech

Most helpful comment

New settings from 16.1.0

csharp_prefer_simple_using_statement
csharp_prefer_static_local_function
csharp_using_directive_placement

All 26 comments

@cremor Thanks for pointing these out. @kuhlenh Kasey should these be added?

You missed:

dotnet_style_qualification_for_event = true:warning
dotnet_style_qualification_for_field = true:warning
dotnet_style_qualification_for_method = true:warning
dotnet_style_qualification_for_property = true:warning

@RehanSaeed Those are documented. See "This." and "Me." qualifiers

So they are, apologies.

I've just went through my .editorconfig and the first list in the OP seems to be reduced to

csharp_indent_braces
csharp_indent_case_contents_when_block
csharp_space_around_declaration_statements
csharp_space_before_open_square_brackets
csharp_space_between_empty_square_brackets
csharp_space_between_square_brackets
csharp_space_after_comma
csharp_space_after_dot
csharp_space_after_semicolon_in_for_statement
csharp_space_before_comma
csharp_space_before_dot
csharp_space_before_semicolon_in_for_statement

The remaining items have since found their way onto the page already.

Thanks for your update @Tragetaschen. But there is one more setting that is still not documented:

csharp_space_between_method_declaration_name_and_open_parenthesis

This has still not been addressed 9 months since it was brought to attention. It doesn't encourage the community to point out such emissions or errors. What is the point of documentation that is incomplete. Please resolve this issue, perhaps mentioning where these settings appear in visual studio settings and that the effect can be seen there too.

@tonyhallett I believe there is one remaining rule that hasn't been added to the docs. For info about setting code style in Options versus in an .EditorConfig file, does this page help? I also added cross links between that page and the .EditorConfig reference page.

I don't know why you would believe that, given that you added it to Backlog Milestone on the 9th of November.

To reiterate.

Not shown in c# Indentation Options
csharp_indent_block_contents
csharp_indent_braces
csharp_indent_case_contents_when_block

Not shown in spacing options
csharp_space_between_method_declaration_name_and_open_parenthesis
csharp_space_around_declaration_statements
csharp_space_before_open_square_brackets
csharp_space_between_empty_square_brackets
csharp_space_between_square_brackets
csharp_space_after_comma
csharp_space_after_dot
csharp_space_after_semicolon_in_for_statement
csharp_space_before_comma
csharp_space_before_dot
csharp_space_before_semicolon_in_for_statement

These strings are all used in Roslyn

@kendrahavens Do you think you'll be able to add these EditorConfig options?

Perhaps the spacing options have not been added as they are not mentioned in Rolsyn .editorconfig for any of the Visual Studio 2017 branches ( and neither in master ) whereas the indentation options were in 15.8.

Note that Visual Studio 2019 Preview 1 introduced a new button in the xaml for exporting visual studio editor settings to an .editorconfig file. There are tests for this generation that include each of the spacing options.

@kendrahavens Do you think you'll be able to add these EditorConfig options?

Not in the immediate future. @jinujoseph @sharwell FYI

With Visual Studio 2019, generating the .editorconfig file reveals some more undocumented settings, in addition to what tonyhallett mentioned.

dotnet_style_prefer_compound_assignment
dotnet_code_quality_unused_parameters
csharp_style_expression_bodied_lambdas
csharp_style_expression_bodied_local_functions
csharp_style_prefer_index_operator
csharp_style_prefer_range_operator
csharp_style_unused_value_assignment_preference
csharp_style_unused_value_expression_statement_preference

thanks
Mike

New settings from 16.1.0

csharp_prefer_simple_using_statement
csharp_prefer_static_local_function
csharp_using_directive_placement

Thanks everyone for reporting new undocumented settings. I've updated the initial comment of this issue to a list of what seems like all undocumented settings as of today.

~8000 page views/month = P0

dotnet_style_operator_placement_when_wrapping also appears to be undocumented.

Good find, thanks for mentioning it.

Seems like this is an option that only affects a refactoring quick fix. I think in the current documentation layout there wouldn't even be a good place to put it. Maybe a new page for refactoring options needs to be created.

I created a new issue for dotnet_style_operator_placement_when_wrapping since it's a little different.

The link is malformed and links to (nonexistent) anchor 3641 instead of #3641. The created ticket by gewarren is #3641.

@ite-klass Thanks, fixed it.

csharp_prefer_braces is missing

These rules have all been added now. If you find any additional missing rules going forward, please create a new issue. We also welcome public contributions. @cremor Thanks for your help in getting these documented.

There seems to be a typo:
chsarp_style_expression_bodied_local_functions in the docs should be:
csharp_style_expression_bodied_local_functions

There seems to be a typo:
chsarp_style_expression_bodied_local_functions in the docs should be:
csharp_style_expression_bodied_local_functions

Thanks, fixing this now! BTW there is an Edit button near the top-right that you can use if you want to make such fixes yourself.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

JeepNL picture JeepNL  Â·  3Comments

patrikhuber picture patrikhuber  Â·  4Comments

realbart picture realbart  Â·  3Comments

rlundy picture rlundy  Â·  3Comments

Ogglas picture Ogglas  Â·  3Comments