-
Notifications
You must be signed in to change notification settings - Fork 10.4k
Enable build time warnings for IDE code analysis rules #34215
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
Conversation
pranavkm
commented
Jul 8, 2021
- Enables build time warnings for readonly, modifier ordering and const
- Fixes all of the warnings
@@ -195,6 +195,7 @@ dotnet_diagnostic.CA2208.severity = warning | |||
dotnet_diagnostic.IDE0035.severity = warning | |||
|
|||
# IDE0036: Order modifiers | |||
csharp_preferred_modifier_order = public,private,protected,internal,static,extern,new,virtual,abstract,sealed,override,readonly,unsafe,volatile,async:suggestion |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Based on https://github.com/dotnet/runtime/blob/main/.editorconfig#L42 (also what the analyzer defaults to)
@@ -204,7 +205,7 @@ dotnet_diagnostic.IDE0043.severity = warning | |||
dotnet_diagnostic.IDE0044.severity = warning | |||
|
|||
# IDE0073: File header | |||
dotnet_diagnostic.IDE0073.severity = warning | |||
dotnet_diagnostic.IDE0073.severity = suggestion |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This trips on files from the runtime repo (that have an MIT license) as well as some other code that's copied from that repo. Skipping for now since it seems low value for now.
How did you fix all these? Is there a command line tool to do this now? |
@@ -27,6 +27,9 @@ | |||
'$(ISBenchmarkProject)' == 'true' OR | |||
'$(IsSampleProject)' == 'true' OR | |||
'$(IsMicrobenchmarksProject)' == 'true'">$(NoWarn);CA1416</NoWarn> | |||
|
|||
<!-- Enable .NET code style analysis during build for src projects. --> | |||
<EnforceCodeStyleInBuild Condition="'$(EnforceCodeStyleInBuild)' == ''">true</EnforceCodeStyleInBuild> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@BrennanConroy this enables these rules to run on the CLI.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This fixes them when it finds them?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, just makes it appear as errors. I used VS to apply the code fix. But presumably once we go thru a few passes of enabling and fixing warnings for individual rules, it's not going to be a big issue. Building in the IDE and on the CLI should produce these errors and they would be localized to new code.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I used VS to apply the code fix.
How long did this take you? Did you have to go project by project?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tried applying it on the sln file but the fixes wouldn't stick. I was however able to get pretty much all of it covered by opening the MVC and Middleware slnfs, and having it load all transitive dependencies. There were a few strays that the build would catch, but not many.
I'm sure there's a better way to go about it, but it's not super painful.
* Enables build time warnings for readonly, modifier ordering and const * Fixes all of the warnings
4bb4bbb
to
da39793
Compare
src/Middleware/ConcurrencyLimiter/test/PolicyTests/ResettableBooleanCompletionSourceTests.cs
Outdated
Show resolved
Hide resolved
src/Middleware/ConcurrencyLimiter/test/PolicyTests/ResettableBooleanCompletionSourceTests.cs
Outdated
Show resolved
Hide resolved
src/Middleware/ConcurrencyLimiter/test/PolicyTests/ResettableBooleanCompletionSourceTests.cs
Outdated
Show resolved
Hide resolved
Co-authored-by: Chris Ross <[email protected]>
@@ -14,8 +14,7 @@ namespace Microsoft.AspNetCore.ApiAuthorization.IdentityServer | |||
public class ClientBuilder | |||
{ | |||
private const string NativeAppClientRedirectUri = "urn:ietf:wg:oauth:2.0:oob"; | |||
|
|||
Client _client; | |||
readonly Client _client; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Visibility modifier?
private readonly SignInManager<TUser> _signInManager; | ||
ILogger<ResetAuthenticatorModel> _logger; | ||
readonly ILogger<ResetAuthenticatorModel> _logger; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Visibility
@@ -573,7 +573,7 @@ internal struct HTTP_SERVER_AUTHENTICATION_INFO | |||
internal bool DisableNTLMCredentialCaching; | |||
internal ulong ExFlags; | |||
HTTP_SERVER_AUTHENTICATION_DIGEST_PARAMS DigestParams; | |||
HTTP_SERVER_AUTHENTICATION_BASIC_PARAMS BasicParams; | |||
readonly HTTP_SERVER_AUTHENTICATION_BASIC_PARAMS BasicParams; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
revert, we should leave the structs alone.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll clean this up in a follow up.
readonly ushort RealmLength; | ||
readonly char* Realm; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
revert