templating
                                
                                 templating copied to clipboard
                                
                                    templating copied to clipboard
                            
                            
                            
                        EditorConfig template should contain all rules
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 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 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.
Discussion notes:
- We discussed implementing separate, additional, very basic template engine generator for that to be included to dotnet newthat will run when the user doesdotnet new editorconfig- generator will generate the editorconfigstring using Roslyn API and write it to the file
- concerns to address: correct line endings and encoding based on OS
 
- generator will generate the 
- 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 editorconfigcontent using Roslyn API indotnetCLI
- No parameters to generation are needed, except supporting currently existing --emptyflag to generate emptyeditorconfigwithroot = true
Example of custom generator is here: https://github.com/dotnet/templating/pull/5773
@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?
@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.
Discussion notes:
We discussed implementing separate, additional, very basic template engine generator for that to be included to
dotnet newthat will run when the user doesdotnet new editorconfig
- generator will generate the
editorconfigstring 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
editorconfigcontent using Roslyn API indotnetCLI
No parameters to generation are needed, except supporting currently existing
--emptyflag to generate emptyeditorconfigwithroot = 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 editorconfigcontent using Roslyn API (similarly to what VS is done)
- no template parameters to generation are needed, except supporting currently existing --emptyflag to generate emptyeditorconfigwithroot = true.