templating icon indicating copy to clipboard operation
templating copied to clipboard

EditorConfig template should contain all rules

Open cremor opened this issue 3 years ago • 7 comments

The file created by dotnet new editorconfig (source) does not contain all available rules. Compared with an EditorConfig file exported by Visual Studio 2022 (via Tools - Options - Text Editor - C# - Code Style - Generate .editorconfig file from settings) it is missing some rules.

As of SDK version 7.0.302 the .editorconfig template is missing the following rules:

dotnet_style_namespace_match_folder
dotnet_style_prefer_foreach_explicit_cast_in_source

csharp_style_implicit_object_creation_when_type_is_apparent
csharp_style_namespace_declarations
csharp_style_prefer_extended_property_pattern
csharp_style_prefer_local_over_anonymous_function
csharp_style_prefer_method_group_conversion
csharp_style_prefer_null_check_over_type_check
csharp_style_prefer_readonly_struct
csharp_style_prefer_readonly_struct_member
csharp_style_prefer_top_level_statements
csharp_style_prefer_tuple_swap
csharp_style_prefer_utf8_string_literals

dotnet_style_allow_multiple_blank_lines_experimental
dotnet_style_allow_statement_immediately_after_block_experimental
csharp_style_allow_blank_line_after_colon_in_constructor_initializer_experimental
csharp_style_allow_blank_lines_between_consecutive_braces_experimental
csharp_style_allow_embedded_statements_on_same_line_experimental
csharp_style_allow_blank_line_after_token_in_arrow_expression_clause_experimental
csharp_style_allow_blank_line_after_token_in_conditional_expression_experimental

Also see dotnet/roslyn#60539 for the experimental rules.

Additionally, the .editorconfig template contains the rule csharp_style_pattern_local_over_anonymous_function. This rule doesn't exist any more. It is the old name of the rule csharp_style_prefer_local_over_anonymous_function.

cremor avatar Feb 15 '22 06:02 cremor

@cremor we are considering fixing it as part of https://github.com/dotnet/templating/issues/4126. Could you please follow that issue? Thank you.

Closing as duplicate.

vlada-shubina avatar Feb 21 '22 12:02 vlada-shubina

@vlada-shubina Please reopen this issue since it is not part of #4126 any more per your comment https://github.com/dotnet/templating/issues/4126#issuecomment-1321758675 there.

And could you please move it to dotnet/sdk? Because the .editorconfig template was moved there.

cremor avatar Nov 21 '22 11:11 cremor

Discussion notes:

  • We discussed implementing separate, additional, very basic template engine generator for that to be included to dotnet new that will run when the user does dotnet new editorconfig
    • generator will generate the editorconfig string using Roslyn API and write it to the file
    • ​concerns to address: correct line endings and encoding based on OS
  • Step 1: prepare an example of custom generator + test; ensure that multiple generators work end-2-end
  • Step 2: implement new generator in sdk repo, incorporate code to generate editorconfig content using Roslyn API in dotnet CLI
  • No parameters to generation are needed, except supporting currently existing --empty​ flag to generate empty editorconfig with root = true

vlada-shubina avatar Nov 29 '22 17:11 vlada-shubina

Example of custom generator is here: https://github.com/dotnet/templating/pull/5773

vlada-shubina avatar Dec 21 '22 13:12 vlada-shubina

@jmarolf here's the custom generator example that we spoke about in our last chat. Will you be able to take a look and SWAG out an editorconfig generator in dotnet/sdk?

baronfel avatar Jan 31 '23 15:01 baronfel

@jmarolf here's the custom generator example that we spoke about in our last chat. Will you be able to take a look and SWAG out an editorconfig generator in dotnet/sdk?

feel free to reach me if you'd need some help on understanding that. There are some features which are not available in example, as localization; but imo we can polish it later.

vlada-shubina avatar Jan 31 '23 15:01 vlada-shubina

Discussion notes:

  • We discussed implementing separate, additional, very basic template engine generator for that to be included to dotnet new that will run when the user does dotnet new editorconfig

    • generator will generate the editorconfig string using Roslyn API and write it to the file
    • ​concerns to address: correct line endings and encoding based on OS
  • Step 1: prepare an example of custom generator + test; ensure that multiple generators work end-2-end

  • Step 2: implement new generator in sdk repo, incorporate code to generate editorconfig content using Roslyn API in dotnet CLI

  • No parameters to generation are needed, except supporting currently existing --empty​ flag to generate empty editorconfig with root = true

Step 1 was done in https://github.com/dotnet/templating/pull/5773. This PR demonstrates how the custom generator can be implemented. The testing is performed - it works as expected.

The remaining work is step 2:

  • implement new generator in sdk repo, insert it as new component.
  • incorporate code to generate editorconfig content using Roslyn API (similarly to what VS is done)
  • no template parameters to generation are needed, except supporting currently existing --empty​ flag to generate empty editorconfig with root = true.

vlada-shubina avatar Jun 14 '23 05:06 vlada-shubina