Skip to content

Conversation

@vlada-shubina
Copy link
Member

@vlada-shubina vlada-shubina commented Jan 23, 2023

Related to #7174

Context

While working in the repo different code style issues are observed

Changes Made

  • enabled IDE code style checks as warning, set the rules that are currently violated to suggestion
  • auto-fixed IDE0011 - add braces to statement
  • auto-fixed IDE0036 - modifiers are not ordered
  • auto-fixed IDE0040 - accessibility modifiers required
  • auto-fixed IDE0050 - fix formatting, manual disabling was needed for the code in regions compiled for full/core framework
  • auto-fixed SA1110 and SA1111 - parenthesis formatting, manual disabling was needed for the parameters with conditional compilation.
  • auto-fixed IDE0073 - A source file contains a header that does not match the required text. Disabled SA1633 as it is same check but required separate config.

All the work was done in separate commits to facilitate easier review.

Testing

Notes

The following checks to be added to #7174 to be gradually fixed:

# Cast is redundant
dotnet_diagnostic.IDE0004.severity = suggestion

# IDE0005: Remove unnecessary usings/imports
dotnet_diagnostic.IDE0005.severity = warning

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

# Populate switch
dotnet_diagnostic.IDE0010.severity = suggestion

# Null check can be simplified
dotnet_diagnostic.IDE0016.severity = suggestion

# Object initialization can be simplified
dotnet_diagnostic.IDE0017.severity = suggestion

# Variable declaration can be inlined
dotnet_diagnostic.IDE0018.severity = suggestion

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

# Use expression body for constructor
dotnet_diagnostic.IDE0021.severity = suggestion

# Use expression body for method
dotnet_diagnostic.IDE0022.severity = suggestion

# Use expression body for conversion operator
dotnet_diagnostic.IDE0023.severity = suggestion

# Use block body for operator
dotnet_diagnostic.IDE0024.severity = suggestion

# Use expression body for property
dotnet_diagnostic.IDE0025.severity = suggestion

# Use expression body for indexer
dotnet_diagnostic.IDE0026.severity = suggestion

# Use expression body for accessor
dotnet_diagnostic.IDE0027.severity = suggestion

# Collection initialization can be simplified
dotnet_diagnostic.IDE0028.severity = suggestion

# Null check can be simplified
dotnet_diagnostic.IDE0031.severity = suggestion

# Use auto property
dotnet_diagnostic.IDE0032.severity = suggestion

# 'default' expression can be simplified
dotnet_diagnostic.IDE0034.severity = suggestion

# Member name can be simplified
dotnet_diagnostic.IDE0037.severity = suggestion

# Use local function
dotnet_diagnostic.IDE0039.severity = suggestion

# Null check can be simplified
dotnet_diagnostic.IDE0041.severity = suggestion

# Variable declaration can be deconstructed
dotnet_diagnostic.IDE0042.severity = suggestion

# Made field readonly
dotnet_diagnostic.IDE0044.severity = suggestion

# 'if' statement can be simplified
dotnet_diagnostic.IDE0045.severity = suggestion
dotnet_diagnostic.IDE0046.severity = suggestion

# Parentheses can be removed
dotnet_diagnostic.IDE0047.severity = suggestion

# Parentheses should be added for clarity
dotnet_diagnostic.IDE0048.severity = suggestion

# Member name can be simplified
dotnet_diagnostic.IDE0049.severity = suggestion

# Use compound assignment
dotnet_diagnostic.IDE0054.severity = suggestion

# Indexing can be simplified
dotnet_diagnostic.IDE0056.severity = suggestion

# Slice can be simplified
dotnet_diagnostic.IDE0057.severity = suggestion

# Expression value is never used
dotnet_diagnostic.IDE0058.severity = suggestion

# Unnecessary assignment of a value
dotnet_diagnostic.IDE0059.severity = suggestion

# Remove unused parameter
dotnet_diagnostic.IDE0060.severity = suggestion

# Use expression body for a local function
dotnet_diagnostic.IDE0061.severity = suggestion

# Local function can be made static
dotnet_diagnostic.IDE0062.severity = suggestion

# Using directives must be placed outside of a namespace declaration
dotnet_diagnostic.IDE0065.severity = suggestion

# Use 'switch' expression
dotnet_diagnostic.IDE0066.severity = suggestion

# 'GetHashCode' implementation can be simplified
dotnet_diagnostic.IDE0070.severity = suggestion

# Interpolation can be simplified
dotnet_diagnostic.IDE0071.severity = suggestion

# Populate switch
dotnet_diagnostic.IDE0072.severity = suggestion

# Use compound assignment
dotnet_diagnostic.IDE0074.severity = suggestion

# Conditional expression can be simplified
dotnet_diagnostic.IDE0075.severity = suggestion

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

# 'typeof' can be converted to 'nameof'
dotnet_diagnostic.IDE0082.severity = suggestion

# 'new' expression can be simplified
dotnet_diagnostic.IDE0090.severity = suggestion

# Simplify LINQ expression
dotnet_diagnostic.IDE0120.severity = suggestion

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

# Null check can be clarified
dotnet_diagnostic.IDE0150.severity = suggestion

# Convert to block scoped namespaces
dotnet_diagnostic.IDE0160.severity = suggestion

# Simplify property pattern
dotnet_diagnostic.IDE0170.severity = suggestion

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

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

# Lambda expression can be removed
dotnet_diagnostic.IDE0200.severity = suggestion

# Convert to top-level statements
dotnet_diagnostic.IDE0210.severity = suggestion

# 'foreach' statement implicitly converts
dotnet_diagnostic.IDE0220.severity = suggestion

# Use UTF-8 string literal
dotnet_diagnostic.IDE0230.severity = suggestion

# Nullable directives
dotnet_diagnostic.IDE0240.severity = suggestion
dotnet_diagnostic.IDE0241.severity = suggestion

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

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

# naming rule violation
dotnet_diagnostic.IDE1006.severity = suggestion

@vlada-shubina vlada-shubina marked this pull request as ready for review January 23, 2023 08:32
@vlada-shubina vlada-shubina marked this pull request as draft January 23, 2023 08:34
Copy link
Member

@JanKrivanek JanKrivanek left a comment

Choose a reason for hiding this comment

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

Overall I love this!

I just want to have extra caution around the license header

@vlada-shubina vlada-shubina marked this pull request as ready for review January 23, 2023 10:33
@vlada-shubina vlada-shubina force-pushed the analyzers branch 2 times, most recently from 4a9dc2c to 67bfb7d Compare January 23, 2023 15:17
@MichalPavlik MichalPavlik merged commit 56087a9 into dotnet:main Jan 26, 2023
rainersigwald added a commit to rainersigwald/msbuild that referenced this pull request Jan 26, 2023
Recent changes dotnet#8336 and dotnet#8350 collided to produce a build break
on just-introduced formatting.
rainersigwald added a commit that referenced this pull request Jan 26, 2023
Recent changes #8336 and #8350 collided to produce a build break
on just-introduced formatting.
dotnet_diagnostic.IDE0005.severity = warning

# Use explicit type instead of 'var'
dotnet_diagnostic.IDE0008.severity = suggestion
Copy link
Contributor

Choose a reason for hiding this comment

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

built-in: suggestion
apparent: suggestion
everything else: warning

Copy link
Member

@rainersigwald rainersigwald left a comment

Choose a reason for hiding this comment

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

Comments from core team discussion.

dotnet_diagnostic.IDE0008.severity = suggestion

# Populate switch
dotnet_diagnostic.IDE0010.severity = suggestion
Copy link
Member

Choose a reason for hiding this comment

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

warning

dotnet_diagnostic.IDE0010.severity = suggestion

# Null check can be simplified
dotnet_diagnostic.IDE0016.severity = suggestion
Copy link
Member

Choose a reason for hiding this comment

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

leave suggestion, but open to moving to warning if an autofixer is available

dotnet_diagnostic.IDE0016.severity = suggestion

# Object initialization can be simplified
dotnet_diagnostic.IDE0017.severity = suggestion
Copy link
Member

Choose a reason for hiding this comment

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

suggestion

dotnet_diagnostic.IDE0017.severity = suggestion

# Variable declaration can be inlined
dotnet_diagnostic.IDE0018.severity = suggestion
Copy link
Member

Choose a reason for hiding this comment

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

warning

dotnet_diagnostic.IDE0018.severity = suggestion

# Use pattern matching
dotnet_diagnostic.IDE0019.severity = suggestion
Copy link
Member

Choose a reason for hiding this comment

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

warning

dotnet_diagnostic.IDE0041.severity = suggestion

# Variable declaration can be deconstructed
dotnet_diagnostic.IDE0042.severity = suggestion
Copy link
Member

Choose a reason for hiding this comment

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

none

dotnet_diagnostic.IDE0042.severity = suggestion

# Made field readonly
dotnet_diagnostic.IDE0044.severity = suggestion
Copy link
Member

Choose a reason for hiding this comment

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

warning

Comment on lines +280 to +281
dotnet_diagnostic.IDE0045.severity = suggestion
dotnet_diagnostic.IDE0046.severity = suggestion
Copy link
Member

Choose a reason for hiding this comment

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

suggestion

dotnet_diagnostic.IDE0046.severity = suggestion

# Parentheses can be removed
dotnet_diagnostic.IDE0047.severity = suggestion
Copy link
Member

Choose a reason for hiding this comment

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

none

# Parentheses can be removed
dotnet_diagnostic.IDE0047.severity = suggestion

# Parentheses should be added for clarity
Copy link
Member

Choose a reason for hiding this comment

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

***** start here for follow up

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

Successfully merging this pull request may close these issues.

7 participants