-
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 | ||
dotnet_diagnostic.IDE0036.severity = warning | ||
|
||
# IDE0043: Format string contains invalid placeholder | ||
|
@@ -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 commentThe 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. |
||
file_header_template = Copyright (c) .NET Foundation. All rights reserved.\nLicensed under the Apache License, Version 2.0. See License.txt in the project root for license information. | ||
|
||
[**/{test,samples,perf}/**.{cs,vb}] | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 commentThe 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 commentThe 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 commentThe 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 commentThe reason will be displayed to describe this comment to others. Learn more.
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 commentThe 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. |
||
</PropertyGroup> | ||
|
||
<ItemGroup Condition=" '$(DotNetBuildFromSource)' != 'true' AND $(AddPublicApiAnalyzers) "> | ||
|
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)