Skip to content

Commit

Permalink
Enable FxCop Analyzers for the repo
Browse files Browse the repository at this point in the history
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 dotnet#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.
  • Loading branch information
Pilchie committed Jul 6, 2020
1 parent a97746b commit 0c13c02
Show file tree
Hide file tree
Showing 9 changed files with 260 additions and 52 deletions.
4 changes: 4 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ dotnet_sort_system_directives_first = true
[*.{xml,config,*proj,nuspec,props,resx,targets,yml,tasks}]
indent_size = 2

# Xml config files
[*.{props,targets,ruleset,config,nuspec,resx,vsixmanifest,vsct}]
indent_size = 2

[*.json]
indent_size = 2

Expand Down
216 changes: 216 additions & 0 deletions eng/AllRulesDisabled.ruleset

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions eng/Dependencies.props
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ and are generated based on the last package release.
<LatestPackageReference Include="Microsoft.AspNetCore.AzureAppServices.SiteExtension.3.1.x86" Version="$(MicrosoftAspNetCoreAzureAppServicesSiteExtension31PackageVersion)" />
<LatestPackageReference Include="Microsoft.AspNetCore.Components.WebAssembly.Runtime" Version="$(MicrosoftAspNetCoreComponentsWebAssemblyRuntimePackageVersion)" />
<LatestPackageReference Include="Microsoft.Bcl.AsyncInterfaces" Version="$(MicrosoftBclAsyncInterfacesPackageVersion)" />
<LatestPackageReference Include="Microsoft.CodeAnalysis.FxCopAnalyzers" Version="$(MicrosoftCodeAnalysisFxCopAnalyzersVersion)" />
<LatestPackageReference Include="Microsoft.EntityFrameworkCore.InMemory" Version="$(MicrosoftEntityFrameworkCoreInMemoryPackageVersion)" />
<LatestPackageReference Include="Microsoft.EntityFrameworkCore.Relational" Version="$(MicrosoftEntityFrameworkCoreRelationalPackageVersion)" />
<LatestPackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="$(MicrosoftEntityFrameworkCoreSqlitePackageVersion)" />
Expand Down
1 change: 1 addition & 0 deletions eng/Versions.props
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,7 @@
<MicrosoftBuildUtilitiesCorePackageVersion>15.8.166</MicrosoftBuildUtilitiesCorePackageVersion>
<MicrosoftCodeAnalysisCommonPackageVersion>3.4.0</MicrosoftCodeAnalysisCommonPackageVersion>
<MicrosoftCodeAnalysisCSharpPackageVersion>3.4.0</MicrosoftCodeAnalysisCSharpPackageVersion>
<MicrosoftCodeAnalysisFxCopAnalyzersVersion>3.0.0</MicrosoftCodeAnalysisFxCopAnalyzersVersion>
<MicrosoftCodeAnalysisCSharpWorkspacesPackageVersion>3.4.0</MicrosoftCodeAnalysisCSharpWorkspacesPackageVersion>
<MicrosoftIdentityModelClientsActiveDirectoryPackageVersion>3.19.8</MicrosoftIdentityModelClientsActiveDirectoryPackageVersion>
<MicrosoftIdentityModelLoggingPackageVersion>5.5.0</MicrosoftIdentityModelLoggingPackageVersion>
Expand Down
8 changes: 8 additions & 0 deletions eng/targets/CSharp.Common.props
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,14 @@
<Import Project="$(RepoRoot)src\Razor\Microsoft.NET.Sdk.Razor\src\build\netstandard2.0\Microsoft.NET.Sdk.Razor.props" />
</ImportGroup>

<ItemGroup Condition=" '$(IsTestProject)' != 'true' AND '$(DotNetBuildFromSource)' != 'true' ">
<Reference Include="Microsoft.CodeAnalysis.FxCopAnalyzers" PrivateAssets="All" />
</ItemGroup>

<PropertyGroup>
<CodeAnalysisRuleSet>$(RepoRoot)eng\AllRulesDisabled.ruleset</CodeAnalysisRuleSet>
</PropertyGroup>

<ItemGroup Condition=" '$(IsTestProject)' == 'true' ">
<Reference Include="Microsoft.AspNetCore.Testing" />
<Reference Include="Moq" />
Expand Down
3 changes: 3 additions & 0 deletions src/Azure/AzureAD/AzureAD.ruleset
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<RuleSet Name="Rules for AzureAD tests" Description="Code analysis rules for AzureAD tests" ToolsVersion="15.0">

<Include Path="..\..\..\eng\AllRulesDisabled.ruleset" Action="Default" />

<Rules AnalyzerId="xunit.analyzers" RuleNamespace="xunit.analyzers">
<!--
This code is produced when theory parameters that are unused. Normally, this is a warning which causes our build to fail.
Expand Down
27 changes: 27 additions & 0 deletions src/Http/.editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# Description: All Globalization Rules are enabled with default severity.

# Code files
[*.{cs,vb}]

# Globalization Rules

# CA1303: Do not pass literals as localized parameters
#dotnet_diagnostic.CA1303.severity = warning

# CA1304: Specify CultureInfo
#dotnet_diagnostic.CA1304.severity = warning

# CA1305: Specify IFormatProvider
#dotnet_diagnostic.CA1305.severity = warning

# CA1307: Specify StringComparison
#dotnet_diagnostic.CA1307.severity = warning

# CA1308: Normalize strings to uppercase
#dotnet_diagnostic.CA1308.severity = warning

# CA1309: Use ordinal stringcomparison
dotnet_diagnostic.CA1309.severity = warning

# CA2101: Specify marshaling for P/Invoke string arguments
#dotnet_diagnostic.CA2101.severity = warning
26 changes: 0 additions & 26 deletions src/Mvc/.editorconfig
Original file line number Diff line number Diff line change
@@ -1,33 +1,7 @@
# EditorConfig is awesome:http://EditorConfig.org

# top-most EditorConfig file
root = true

# Don't use tabs for indentation.
[*]
indent_style = space
# (Please don't specify an indent_size here; that has too many unintended consequences.)

# Code files
[*.{cs,csx,vb,vbx}]
indent_size = 4

# Xml project files
[*.{csproj,vbproj,vcxproj,vcxproj.filters,proj,projitems,shproj}]
indent_size = 2

# Xml config files
[*.{props,targets,ruleset,config,nuspec,resx,vsixmanifest,vsct}]
indent_size = 2

# JSON files
[*.json]
indent_size = 2

# Dotnet code style settings:
[*.cs]
# Sort using and Import directives with System.* appearing first
dotnet_sort_system_directives_first = true

# Don't use this. qualifier
dotnet_style_qualification_for_field = false:suggestion
Expand Down
26 changes: 0 additions & 26 deletions src/Razor/.editorconfig
Original file line number Diff line number Diff line change
@@ -1,33 +1,7 @@
# EditorConfig is awesome:http://EditorConfig.org

# top-most EditorConfig file
root = true

# Don't use tabs for indentation.
[*]
indent_style = space
# (Please don't specify an indent_size here; that has too many unintended consequences.)

# Code files
[*.{cs,csx,vb,vbx}]
indent_size = 4

# Xml project files
[*.{csproj,vbproj,vcxproj,vcxproj.filters,proj,projitems,shproj}]
indent_size = 2

# Xml config files
[*.{props,targets,ruleset,config,nuspec,resx,vsixmanifest,vsct}]
indent_size = 2

# JSON files
[*.json]
indent_size = 2

# Dotnet code style settings:
[*.cs]
# Sort using and Import directives with System.* appearing first
dotnet_sort_system_directives_first = true

# Don't use this. qualifier
dotnet_style_qualification_for_field = false:suggestion
Expand Down

0 comments on commit 0c13c02

Please sign in to comment.