dotnet / roslyn

The Roslyn .NET compiler provides C# and Visual Basic languages with rich code analysis APIs.
https://docs.microsoft.com/dotnet/csharp/roslyn-sdk/
MIT License
19.1k stars 4.04k forks source link

EditorConfig IntelliCode inference wrong comment for csharp_space_between_method_declaration_parameter_list_parentheses #50433

Open petrroll opened 3 years ago

petrroll commented 3 years ago

Version Used: Version 16.8.4

Steps to Reproduce:

  1. Have codebase that doesn' place space character between open/close parenthesis of method's declar. param. list
  2. Infer EditorConfig

Expected Behavior:

#remove space within empty parameter list parentheses for a method declaration
csharp_space_between_method_declaration_empty_parameter_list_parentheses = false
#do not place a space character after the opening parenthesis and before the closing parenthesis of a method declaration parameter list.
csharp_space_between_method_declaration_parameter_list_parentheses = false

Actual Behavior:

#remove space within empty parameter list parentheses for a method declaration
csharp_space_between_method_declaration_empty_parameter_list_parentheses = false
#place a space character after the opening parenthesis and before the closing parenthesis of a method declaration parameter list.
csharp_space_between_method_declaration_parameter_list_parentheses = false

Description I assume the comments should correspond to what value was inferred. I.e. when csharp_space_between_method_declaration_parameter_list_parentheses = false is inferred, the comment should say "do not place a space" or "remove a space".

E.g. programm:

using System;

class Program
{
    static void Main(string[] args)
    {
    }

    private static void MethodWithUnused() => Console.WriteLine($"");
}

Whole relevant editorconfig:

# Rules in this file were initially inferred by Visual Studio IntelliCode from the C:\Users\houskape\source\repos\ConsoleApp1 codebase based on best match to current usage at 13-Jan-21
# You can modify the rules from these initially generated values to suit your own policies
# You can learn more about editorconfig here: https://docs.microsoft.com/en-us/visualstudio/ide/editorconfig-code-style-settings-reference
[*.cs]

#Core editorconfig formatting - indentation

#use soft tabs (spaces) for indentation
indent_style = space

#Formatting - spacing options

#do not place space characters after the opening parenthesis and before the closing parenthesis of a method call
csharp_space_between_method_call_parameter_list_parentheses = false
#place a space character after the opening parenthesis and before the closing parenthesis of a method declaration parameter list.
csharp_space_between_method_declaration_parameter_list_parentheses = false

#Style - expression bodied member options

#prefer expression-bodied members for methods
csharp_style_expression_bodied_methods = true:suggestion

#Style - language keyword and framework type options

#prefer the language keyword for local variables, method parameters, and class members, instead of the type name, for types that have a keyword to represent them
dotnet_style_predefined_type_for_locals_parameters_members = true:suggestion

#Style - modifier options

#do not prefer accessibility modifiers to be specified
dotnet_style_require_accessibility_modifiers = never:suggestion

#Style - Modifier preferences

#when this rule is set to a list of modifiers, prefer the specified ordering.
csharp_preferred_modifier_order = static,private:suggestion

Note: Apologies if this is not the correct repo.

petrroll commented 3 years ago

Similarly, this got inferred in our codebase:

#require braces to be on a new line for properties, accessors, methods, control_blocks, types, and object_collection_array_initializers (also known as "Allman" style)
csharp_new_line_before_open_brace = properties, accessors, methods, control_blocks, types, object_collection_array_initializers

Even though it's not Allman style, at least according to docs (note e.g. anonymous_methods missing): https://docs.microsoft.com/en-us/dotnet/fundamentals/code-analysis/style-rules/formatting-rules#csharp_new_line_before_open_brace

On this note, I think the IntelliCode inference is actually wrong and should've inferred all. But don't have concrete data to back-it up (happy to provide codebase in question interanlly).