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

[Analyzers] Update .editorconfig with rules to relax IDE errors #36095

Merged
merged 13 commits into from
Dec 4, 2024
Merged
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
200 changes: 187 additions & 13 deletions src/.editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -46,32 +46,28 @@ dotnet_naming_rule.non_field_members_should_be_pascal_case.style = pascal_case

dotnet_naming_symbols.interface.applicable_kinds = interface
dotnet_naming_symbols.interface.applicable_accessibilities = public, internal, private, protected, protected_internal, private_protected
dotnet_naming_symbols.interface.required_modifiers =
dotnet_naming_symbols.interface.required_modifiers =

dotnet_naming_symbols.types.applicable_kinds = class, struct, interface, enum
dotnet_naming_symbols.types.applicable_accessibilities = public, internal, private, protected, protected_internal, private_protected
dotnet_naming_symbols.types.required_modifiers =
dotnet_naming_symbols.types.required_modifiers =

dotnet_naming_symbols.non_field_members.applicable_kinds = property, event, method
dotnet_naming_symbols.non_field_members.applicable_accessibilities = public, internal, private, protected, protected_internal, private_protected
dotnet_naming_symbols.non_field_members.required_modifiers =
dotnet_naming_symbols.non_field_members.required_modifiers =

# Naming styles

dotnet_naming_style.begins_with_i.required_prefix = I
dotnet_naming_style.begins_with_i.required_suffix =
dotnet_naming_style.begins_with_i.word_separator =
dotnet_naming_style.begins_with_i.required_suffix =
dotnet_naming_style.begins_with_i.word_separator =
dotnet_naming_style.begins_with_i.capitalization = pascal_case

dotnet_naming_style.pascal_case.required_prefix =
dotnet_naming_style.pascal_case.required_suffix =
dotnet_naming_style.pascal_case.word_separator =
dotnet_naming_style.pascal_case.required_prefix =
dotnet_naming_style.pascal_case.required_suffix =
dotnet_naming_style.pascal_case.word_separator =
dotnet_naming_style.pascal_case.capitalization = pascal_case

dotnet_naming_style.pascal_case.required_prefix =
dotnet_naming_style.pascal_case.required_suffix =
dotnet_naming_style.pascal_case.word_separator =
dotnet_naming_style.pascal_case.capitalization = pascal_case
dotnet_style_coalesce_expression = true:suggestion
dotnet_style_null_propagation = true:suggestion
dotnet_style_prefer_is_null_check_over_reference_equality_method = true:suggestion
Expand All @@ -96,4 +92,182 @@ end_of_line = crlf
dotnet_diagnostic.IDE0065.severity = none

# IDE0009: Add this or Me qualification
dotnet_diagnostic.IDE0009.severity = none
dotnet_diagnostic.IDE0009.severity = none

# IDE-based code analysis rules
# IDE0005: Remove unnecessary import
dotnet_diagnostic.IDE0005.severity = suggestion

# IDE0008: Use explicit type instead of 'var'
dotnet_diagnostic.IDE0008.severity = silent

# IDE0016: Use throw expression
dotnet_diagnostic.IDE0016.severity = suggestion

# IDE0018: Inline variable declaration
dotnet_diagnostic.IDE0018.severity = suggestion

# IDE0019: Use pattern matching
dotnet_diagnostic.IDE0019.severity = suggestion

# IDE0021: Use expression body for constructors
dotnet_diagnostic.IDE0021.severity = silent

# IDE0022: Use expression body for methods
dotnet_diagnostic.IDE0022.severity = silent

# IDE0023: Use expression body for conversion operators
dotnet_diagnostic.IDE0023.severity = silent

# IDE0025: Use expression body for properties
dotnet_diagnostic.IDE0025.severity = silent

# IDE0027: Use expression body for accessors
dotnet_diagnostic.IDE0027.severity = silent

# IDE0028: Use collection initializers
dotnet_diagnostic.IDE0028.severity = suggestion

# IDE0029: Null check can be simplified
dotnet_diagnostic.IDE0029.severity = suggestion

# IDE0031: Use null propagation
dotnet_diagnostic.IDE0031.severity = suggestion

# IDE0032: Use auto property
dotnet_diagnostic.IDE0032.severity = suggestion

# IDE0034: Simplify default expression
dotnet_diagnostic.IDE0034.severity = suggestion

# IDE0036: Order modifiers
dotnet_diagnostic.IDE0036.severity = suggestion

# IDE0039: Use local function instead of lambda
dotnet_diagnostic.IDE0039.severity = suggestion

# IDE0042: Deconstruct variable declaration
dotnet_diagnostic.IDE0042.severity = suggestion

# IDE0044: Add readonly modifier
dotnet_diagnostic.IDE0044.severity = suggestion

# IDE0045: Use conditional expression for assignment
dotnet_diagnostic.IDE0045.severity = suggestion

# IDE0046: Use conditional expression for return
dotnet_diagnostic.IDE0046.severity = suggestion

# IDE0047: Remove unnecessary parentheses
dotnet_diagnostic.IDE0047.severity = suggestion

# IDE0051: Remove unused private member
dotnet_diagnostic.IDE0051.severity = suggestion

# IDE0052: Remove unread private member
dotnet_diagnostic.IDE0052.severity = suggestion

# IDE0054: Use compound assignment
dotnet_diagnostic.IDE0054.severity = suggestion

# IDE0055: Fix formatting
dotnet_diagnostic.IDE0055.severity = suggestion

# IDE0056: Use index operator
dotnet_diagnostic.IDE0056.severity = suggestion

# IDE0057: Use range operator
dotnet_diagnostic.IDE0057.severity = suggestion

# IDE0059: Remove unnecessary value assignment
dotnet_diagnostic.IDE0059.severity = suggestion

# IDE0060: Remove unused parameter
dotnet_diagnostic.IDE0060.severity = suggestion

# IDE0061: Use expression body for local functions
dotnet_diagnostic.IDE0061.severity = silent

# IDE0063: Use simple 'using' statement
dotnet_diagnostic.IDE0063.severity = suggestion

# IDE0071: Simplify interpolation
dotnet_diagnostic.IDE0071.severity = suggestion

# IDE0073: Use file header
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Warning/error? Don't we want to ensure this is the case for best practices with having headers on our files for licensing as an opensource project?

Copy link
Collaborator Author

@snickler snickler Nov 27, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good find. This one can be pulled out and shouldn't have been added. I went through and grouped all the warning/errors that magically started appearing in the IDE that weren't previously.

The IDE0073 shows up due to the ImageResizer files having the file header of the original author

// Copyright (c) Brice Lambson
// The Brice Lambson licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information. Code forked from Brice Lambson's https://github.com/bricelam/ImageResizer/

Should we go ahead and change these to the proper header? Or do a suppression on just the ImageResizer related ones?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ooo, good question. I think if they're the original source that we're including as-is, it should remain with the original header. I think if we've modified anything, then it should have both headers... but I'm not 100% sure on this. I assume this code is called out in a third-party notice somewhere in the root at least too, eh?

For now, probably good to suppress these from getting warnings about the header, and we can follow-up with Clint on the best practice here. I feel like we need a playbook/doc somewhere that calls out all these header/license scenarios, does one exist? 😅

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@michael-hawker I've made changes to resolve these 😎

dotnet_diagnostic.IDE0073.severity = suggestion

# IDE0074: Use coalesce compound assignment
dotnet_diagnostic.IDE0074.severity = suggestion

# IDE0075: Simplify conditional expression
dotnet_diagnostic.IDE0075.severity = suggestion

# IDE0077: Avoid legacy format target in global 'SuppressMessageAttribute'
dotnet_diagnostic.IDE0077.severity = suggestion

# IDE0078: Use pattern matching
dotnet_diagnostic.IDE0078.severity = suggestion

# IDE0083: Use pattern matching ('not' operator)
dotnet_diagnostic.IDE0083.severity = suggestion

# IDE0090: Simplify 'new' expression
dotnet_diagnostic.IDE0090.severity = suggestion

# IDE0100: Remove unnecessary equality operator
dotnet_diagnostic.IDE0100.severity = suggestion

# IDE0130: Namespace does not match folder structure
dotnet_diagnostic.IDE0130.severity = suggestion

# IDE0160: Use block-scoped namespace
dotnet_diagnostic.IDE0160.severity = silent

# IDE0180: Use tuple to swap values
dotnet_diagnostic.IDE0180.severity = suggestion

# IDE0200: Remove unnecessary lambda expression
dotnet_diagnostic.IDE0200.severity = suggestion

# IDE0240: Nullable directive is redundant
dotnet_diagnostic.IDE0240.severity = suggestion

# IDE0250: Struct can be made 'readonly'
dotnet_diagnostic.IDE0250.severity = suggestion

# IDE0251: Member can be made 'readonly''
dotnet_diagnostic.IDE0251.severity = suggestion

# IDE0260: Use pattern matching
dotnet_diagnostic.IDE0260.severity = suggestion

# IDE0270: Null check can be simplified
dotnet_diagnostic.IDE0270.severity = suggestion

# IDE0290: Use primary constructor
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This one's bit me a bit already, maybe silent? It's a nice pattern in some circumstances, but a lot trickier to do well if adapting from an existing class.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah this can be a silenced instead of suggested. I was thinking that suggestion was needed in order for it to exist as a potential suggestion.

dotnet_diagnostic.IDE0290.severity = suggestion

# IDE0300: Use collection expression for array
dotnet_diagnostic.IDE0300.severity = suggestion

# IDE0301: Use collection expression for empty
dotnet_diagnostic.IDE0301.severity = suggestion

# IDE0305: Use collection expression for fluent
dotnet_diagnostic.IDE0305.severity = suggestion

# IDE1005: Use conditional delegate call
dotnet_diagnostic.IDE1005.severity = suggestion

# IDE1006: Naming rule violation: Interface should begin with 'I'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking here we have no cases where this isn't the case currently. Should this be a warning or error then as this is a common convention I don't think we'd want to stray from?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's only about 8 or so instances where this affects anything, so this is another one that can be ripped out. Seriously, thanks again for reviewing ^_^.

image

dotnet_diagnostic.IDE1006.severity = suggestion

# CA1859: Use concrete types when possible for improved performance
dotnet_diagnostic.CA1859.severity = suggestion

# CA2202: Avoid inexact read with Stream.Read
dotnet_diagnostic.CA2022.severity = suggestion

# CA2263: Prefer generic overload when type is known
dotnet_diagnostic.CA2263.severity = suggestion
Loading