Skip to content

Commit 1da13e6

Browse files
authored
Enable FxCop Analyzers for the repo (#23709)
All rules are currently disabled, except for one that I enabled for src/Http via a new ".editorconfig" file I added there. Other changes: * Allow editorconfigs in MVC and Razor to flow to the root * Consolidate a few editorconfig settings * Tweak Ruleset config in Azure/AzureAD where it clashed. Addresses the beginning of #9620, but it's a fair chunk of work to enable most rules through the whole repo. That can be done directory by directory and rule by rule by dropping .editorconfig files though.
1 parent f83ce07 commit 1da13e6

File tree

9 files changed

+260
-52
lines changed

9 files changed

+260
-52
lines changed

.editorconfig

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,10 @@ dotnet_sort_system_directives_first = true
2626
[*.{xml,config,*proj,nuspec,props,resx,targets,yml,tasks}]
2727
indent_size = 2
2828

29+
# Xml config files
30+
[*.{props,targets,ruleset,config,nuspec,resx,vsixmanifest,vsct}]
31+
indent_size = 2
32+
2933
[*.json]
3034
indent_size = 2
3135

eng/AllRulesDisabled.ruleset

Lines changed: 216 additions & 0 deletions
Large diffs are not rendered by default.

eng/Dependencies.props

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@ and are generated based on the last package release.
111111
<LatestPackageReference Include="Microsoft.AspNetCore.AzureAppServices.SiteExtension.3.1.x86" Version="$(MicrosoftAspNetCoreAzureAppServicesSiteExtension31PackageVersion)" />
112112
<LatestPackageReference Include="Microsoft.AspNetCore.Components.WebAssembly.Runtime" Version="$(MicrosoftAspNetCoreComponentsWebAssemblyRuntimePackageVersion)" />
113113
<LatestPackageReference Include="Microsoft.Bcl.AsyncInterfaces" Version="$(MicrosoftBclAsyncInterfacesPackageVersion)" />
114+
<LatestPackageReference Include="Microsoft.CodeAnalysis.FxCopAnalyzers" Version="$(MicrosoftCodeAnalysisFxCopAnalyzersVersion)" />
114115
<LatestPackageReference Include="Microsoft.EntityFrameworkCore.InMemory" Version="$(MicrosoftEntityFrameworkCoreInMemoryPackageVersion)" />
115116
<LatestPackageReference Include="Microsoft.EntityFrameworkCore.Relational" Version="$(MicrosoftEntityFrameworkCoreRelationalPackageVersion)" />
116117
<LatestPackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="$(MicrosoftEntityFrameworkCoreSqlitePackageVersion)" />

eng/Versions.props

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,7 @@
188188
<MicrosoftCodeAnalysisCommonPackageVersion>3.7.0-4.20351.7</MicrosoftCodeAnalysisCommonPackageVersion>
189189
<MicrosoftCodeAnalysisCSharpPackageVersion>3.7.0-4.20351.7</MicrosoftCodeAnalysisCSharpPackageVersion>
190190
<MicrosoftCodeAnalysisCSharpWorkspacesPackageVersion>3.7.0-4.20351.7</MicrosoftCodeAnalysisCSharpWorkspacesPackageVersion>
191+
<MicrosoftCodeAnalysisFxCopAnalyzersVersion>3.0.0</MicrosoftCodeAnalysisFxCopAnalyzersVersion>
191192
<MicrosoftCssParserPackageVersion>1.0.0-20200708.1</MicrosoftCssParserPackageVersion>
192193
<MicrosoftIdentityModelClientsActiveDirectoryPackageVersion>3.19.8</MicrosoftIdentityModelClientsActiveDirectoryPackageVersion>
193194
<MicrosoftIdentityModelLoggingPackageVersion>5.5.0</MicrosoftIdentityModelLoggingPackageVersion>

eng/targets/CSharp.Common.props

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,14 @@
3333
<Import Project="$(RepoRoot)src\Razor\Microsoft.NET.Sdk.Razor\src\build\netstandard2.0\Microsoft.NET.Sdk.Razor.props" />
3434
</ImportGroup>
3535

36+
<ItemGroup Condition=" '$(IsTestProject)' != 'true' AND '$(DotNetBuildFromSource)' != 'true' ">
37+
<Reference Include="Microsoft.CodeAnalysis.FxCopAnalyzers" PrivateAssets="All" />
38+
</ItemGroup>
39+
40+
<PropertyGroup>
41+
<CodeAnalysisRuleSet>$(RepoRoot)eng\AllRulesDisabled.ruleset</CodeAnalysisRuleSet>
42+
</PropertyGroup>
43+
3644
<ItemGroup Condition=" '$(IsTestProject)' == 'true' ">
3745
<Reference Include="Microsoft.AspNetCore.Testing" />
3846
<Reference Include="Moq" />

src/Azure/AzureAD/AzureAD.ruleset

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<RuleSet Name="Rules for AzureAD tests" Description="Code analysis rules for AzureAD tests" ToolsVersion="15.0">
3+
4+
<Include Path="..\..\..\eng\AllRulesDisabled.ruleset" Action="Default" />
5+
36
<Rules AnalyzerId="xunit.analyzers" RuleNamespace="xunit.analyzers">
47
<!--
58
This code is produced when theory parameters that are unused. Normally, this is a warning which causes our build to fail.

src/Http/.editorconfig

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# Description: All Globalization Rules are enabled with default severity.
2+
3+
# Code files
4+
[*.{cs,vb}]
5+
6+
# Globalization Rules
7+
8+
# CA1303: Do not pass literals as localized parameters
9+
#dotnet_diagnostic.CA1303.severity = warning
10+
11+
# CA1304: Specify CultureInfo
12+
#dotnet_diagnostic.CA1304.severity = warning
13+
14+
# CA1305: Specify IFormatProvider
15+
#dotnet_diagnostic.CA1305.severity = warning
16+
17+
# CA1307: Specify StringComparison
18+
#dotnet_diagnostic.CA1307.severity = warning
19+
20+
# CA1308: Normalize strings to uppercase
21+
#dotnet_diagnostic.CA1308.severity = warning
22+
23+
# CA1309: Use ordinal stringcomparison
24+
dotnet_diagnostic.CA1309.severity = warning
25+
26+
# CA2101: Specify marshaling for P/Invoke string arguments
27+
#dotnet_diagnostic.CA2101.severity = warning

src/Mvc/.editorconfig

Lines changed: 0 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,7 @@
11
# EditorConfig is awesome:http://EditorConfig.org
22

3-
# top-most EditorConfig file
4-
root = true
5-
6-
# Don't use tabs for indentation.
7-
[*]
8-
indent_style = space
9-
# (Please don't specify an indent_size here; that has too many unintended consequences.)
10-
11-
# Code files
12-
[*.{cs,csx,vb,vbx}]
13-
indent_size = 4
14-
15-
# Xml project files
16-
[*.{csproj,vbproj,vcxproj,vcxproj.filters,proj,projitems,shproj}]
17-
indent_size = 2
18-
19-
# Xml config files
20-
[*.{props,targets,ruleset,config,nuspec,resx,vsixmanifest,vsct}]
21-
indent_size = 2
22-
23-
# JSON files
24-
[*.json]
25-
indent_size = 2
26-
273
# Dotnet code style settings:
284
[*.cs]
29-
# Sort using and Import directives with System.* appearing first
30-
dotnet_sort_system_directives_first = true
315

326
# Don't use this. qualifier
337
dotnet_style_qualification_for_field = false:suggestion

src/Razor/.editorconfig

Lines changed: 0 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,7 @@
11
# EditorConfig is awesome:http://EditorConfig.org
22

3-
# top-most EditorConfig file
4-
root = true
5-
6-
# Don't use tabs for indentation.
7-
[*]
8-
indent_style = space
9-
# (Please don't specify an indent_size here; that has too many unintended consequences.)
10-
11-
# Code files
12-
[*.{cs,csx,vb,vbx}]
13-
indent_size = 4
14-
15-
# Xml project files
16-
[*.{csproj,vbproj,vcxproj,vcxproj.filters,proj,projitems,shproj}]
17-
indent_size = 2
18-
19-
# Xml config files
20-
[*.{props,targets,ruleset,config,nuspec,resx,vsixmanifest,vsct}]
21-
indent_size = 2
22-
23-
# JSON files
24-
[*.json]
25-
indent_size = 2
26-
273
# Dotnet code style settings:
284
[*.cs]
29-
# Sort using and Import directives with System.* appearing first
30-
dotnet_sort_system_directives_first = true
315

326
# Don't use this. qualifier
337
dotnet_style_qualification_for_field = false:suggestion

0 commit comments

Comments
 (0)