Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Determine the necessary editorconfig to allow enabling IDE0055 #781

Open
belav opened this issue Jan 4, 2023 · 6 comments
Open

Determine the necessary editorconfig to allow enabling IDE0055 #781

belav opened this issue Jan 4, 2023 · 6 comments
Milestone

Comments

@belav
Copy link
Owner

belav commented Jan 4, 2023

The rules under C# Formatting Options appear to all be unnecessary when using CSharpier and can cause conflicts.
The rules under .NET Formatting Options could still be useful.

It would be useful to determine what set of .editorconfig options would allow enabling IDE0055, or provide alternatives for the .NET Formatting Options

@elovelan
Copy link

elovelan commented Jun 3, 2023

This is what I've come up with so far. I'm still looking to see if there are non-IDE0055 options that are conflicting as well. These can be set to ignore if desired, but having the editor's help pre-save seems valuable. Also, I think I could write test(s) that leverage the analyzer to ensure this is correct (likely similar for R# settings).

I can't yet figure out if there's any way to control alignment via EditorConfig.

### CSharpier-compatible settings ###

# C# formatting settings - New-line options
# https://learn.microsoft.com/en-us/dotnet/fundamentals/code-analysis/style-rules/csharp-formatting-options#new-line-options
csharp_new_line_before_else = true
csharp_new_line_before_catch = true
csharp_new_line_before_finally = true
csharp_new_line_before_open_brace = all
csharp_new_line_before_members_in_anonymous_types = true
csharp_new_line_before_members_in_object_initializers = true
csharp_new_line_between_query_expression_clauses = true

# C# formatting settings - Indentation options
# https://learn.microsoft.com/en-us/dotnet/fundamentals/code-analysis/style-rules/csharp-formatting-options#indentation-options
csharp_indent_case_contents = true
csharp_indent_switch_labels = true
csharp_indent_labels = no_change
csharp_indent_block_contents = true
csharp_indent_braces = false
csharp_indent_case_contents_when_block = false

# C# formatting settings - Spacing options
# https://learn.microsoft.com/en-us/dotnet/fundamentals/code-analysis/style-rules/csharp-formatting-options#spacing-options
csharp_space_after_cast = false
csharp_space_after_keywords_in_control_flow_statements = true
csharp_space_between_parentheses = none
csharp_space_before_colon_in_inheritance_clause = true
csharp_space_after_colon_in_inheritance_clause = true
csharp_space_around_binary_operators = before_and_after
csharp_space_between_method_declaration_parameter_list_parentheses = false
csharp_space_between_method_declaration_empty_parameter_list_parentheses = false
csharp_space_between_method_declaration_name_and_open_parenthesis = false
csharp_space_between_method_call_parameter_list_parentheses = false
csharp_space_between_method_call_empty_parameter_list_parentheses = false
csharp_space_between_method_call_name_and_opening_parenthesis = false
csharp_space_after_comma = true
csharp_space_before_comma = false
csharp_space_after_dot = false
csharp_space_before_dot = false
csharp_space_after_semicolon_in_for_statement = true
csharp_space_before_semicolon_in_for_statement = false
csharp_space_around_declaration_statements = false
csharp_space_before_open_square_brackets = false
csharp_space_between_empty_square_brackets = false
csharp_space_between_square_brackets = false

# C# formatting settings - Wrap options
# https://learn.microsoft.com/en-us/dotnet/fundamentals/code-analysis/style-rules/csharp-formatting-options#wrap-options
csharp_preserve_single_line_blocks = true
csharp_preserve_single_line_statements = false

# undocumented
dotnet_style_operator_placement_when_wrapping = beginning_of_line

@elovelan
Copy link

elovelan commented Jun 3, 2023

Also, these seem to be the only (documented) IDE0055 settings that aren't applicable:

dotnet_sort_system_directives_first = true
dotnet_separate_import_directive_groups = false

@elovelan
Copy link

elovelan commented Jun 3, 2023

There are also some experimental settings that may be applicable that Visual Studio seems to know about (at least in the preview version, I haven't checked the RTM version yet) that I have yet to investigate since they're undocumented.

@belav
Copy link
Owner Author

belav commented Jun 30, 2023

Thanks for digging into this. I tested it out on a large repo and ran into a couple things.

With csharp_new_line_before_open_brace = all

It is unhappy with braces being on the same line as a ) in some cases

    public void Method(
        string someLongName
    ) { }

    if (ex is HttpRequestException) { }

    // this is fine
    public void Method() { }

Switching to csharp_new_line_before_open_brace = none causes a lot more complaints.

It is also unhappy with this statement

return from prp in this.DataProvider.LinqQuery<ProductRelatedProduct>()
    join p in this.GetTable() on prp.RelatedProductId equals p.Id
    where
        prp.ProductId == productId
        && prp.SystemListValue.Name == type
        && p.ActivateOn < DateTimeProvider.Current.Now
        && (p.DeactivateOn ?? DateTimeOffset.MaxValue) > DateTimeProvider.Current.Now
    select p;

// it wants
return from prp in this.DataProvider.LinqQuery<ProductRelatedProduct>()
       join p in this.GetTable() on prp.RelatedProductId equals p.Id
       where
           prp.ProductId == productId
           && prp.SystemListValue.Name == type
           && p.ActivateOn < DateTimeProvider.Current.Now
           && (p.DeactivateOn ?? DateTimeOffset.MaxValue) > DateTimeProvider.Current.Now
       select p;

I didn't see any way to disable or ignore either of these. And I'm not sure if we want to make the changes to get IDE0055 happy, but if #661 is implemented, and also puts System first, then it may not be necessary to figure this out. We've started enforcing sorted usings at work, and having CSharpier do it for me would make life a bit easier

@belav belav modified the milestones: 0.25.0, 0.26.0, 0.27.0 Sep 2, 2023
@belav belav modified the milestones: 0.27.0, Planned Jan 2, 2024
@sirphilliptubell
Copy link

Would love to see this, csharp_new_line_before_open_brace = none is a must for our code bases and csharipier doesn't seem to respect it at all.

@belav
Copy link
Owner Author

belav commented Dec 16, 2024

Would love to see this, csharp_new_line_before_open_brace = none is a must for our code bases and csharipier doesn't seem to respect it at all.

The goal of this ticket is not for CSharpier to support csharp_new_line_before_open_brace, it is to determine what editorconfig settings allow IDE0055 to be enabled and enforced and possibly tweak csharpier's styling to align with it.

After looking at this again I don't know how useful it is to enable IDE0055 anymore. The only thing it used to add that CSharpier did not deal with was sorting using.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants