Skip to content

Commit 350ea5b

Browse files
authored
Use NetAnalyzers from SDK instead of FxCopAnalyzers (dotnet#30138)
* Use analyzers from .NET SDK
1 parent 01982de commit 350ea5b

File tree

52 files changed

+127
-413
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

52 files changed

+127
-413
lines changed

.editorconfig

+28-3
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,32 @@ insert_final_newline = true
2323
indent_size = 4
2424
dotnet_sort_system_directives_first = true
2525

26+
# Don't use this. qualifier
27+
dotnet_style_qualification_for_field = false:suggestion
28+
dotnet_style_qualification_for_property = false:suggestion
29+
30+
# use int x = .. over Int32
31+
dotnet_style_predefined_type_for_locals_parameters_members = true:suggestion
32+
33+
# use int.MaxValue over Int32.MaxValue
34+
dotnet_style_predefined_type_for_member_access = true:suggestion
35+
36+
# Require var all the time.
37+
csharp_style_var_for_built_in_types = true:suggestion
38+
csharp_style_var_when_type_is_apparent = true:suggestion
39+
csharp_style_var_elsewhere = true:suggestion
40+
41+
# Disallow throw expressions.
42+
csharp_style_throw_expression = false:suggestion
43+
44+
# Newline settings
45+
csharp_new_line_before_open_brace = all
46+
csharp_new_line_before_else = true
47+
csharp_new_line_before_catch = true
48+
csharp_new_line_before_finally = true
49+
csharp_new_line_before_members_in_object_initializers = true
50+
csharp_new_line_before_members_in_anonymous_types = true
51+
2652
[*.{xml,config,*proj,nuspec,props,resx,targets,yml,tasks}]
2753
indent_size = 2
2854

@@ -43,7 +69,6 @@ end_of_line = lf
4369
[*.{razor,cshtml}]
4470
charset = utf-8-bom
4571

46-
[*.cs]
47-
dotnet_diagnostic.CA1304.severity = error
72+
[*.{cs,vb}]
73+
# CA1305: Specify IFormatProvider
4874
dotnet_diagnostic.CA1305.severity = error
49-
dotnet_diagnostic.CA1310.severity = error

.globalconfig

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
is_global = true
2+
3+
# CA1309: Use ordinal StringComparison
4+
# https://github.com/dotnet/aspnetcore/pull/30111#issuecomment-777817003
5+
dotnet_diagnostic.CA1309.severity = suggestion
6+
7+
# CA3076: Insecure XSLT Script Execution
8+
# Disabled due to crashing: https://github.com/dotnet/roslyn-analyzers/issues/4750
9+
# Delete the following line when we have a working version.
10+
dotnet_diagnostic.CA3076.severity = none
11+
12+
# CA1304: Specify CultureInfo
13+
dotnet_diagnostic.CA1304.severity = error
14+
15+
# CA1310: Specify StringComparison for correctness
16+
dotnet_diagnostic.CA1310.severity = error

Directory.Build.props

+6
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,12 @@
77
<RepositoryType>git</RepositoryType>
88
</PropertyGroup>
99

10+
<PropertyGroup>
11+
<EnableNETAnalyzers>true</EnableNETAnalyzers>
12+
<AnalysisLevel>latest</AnalysisLevel>
13+
<AnalysisMode>Default</AnalysisMode>
14+
</PropertyGroup>
15+
1016
<!-- Defines project type conventions. -->
1117
<PropertyGroup>
1218
<RepoRelativeProjectDir>$([MSBuild]::MakeRelative($(RepoRoot), $(MSBuildProjectDirectory)))</RepoRelativeProjectDir>

eng/AllRulesDisabled.ruleset

-216
This file was deleted.

eng/Dependencies.props

-1
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,6 @@ and are generated based on the last package release.
110110
<LatestPackageReference Include="Microsoft.AspNetCore.AzureAppServices.SiteExtension.5.0.x86" />
111111
<LatestPackageReference Include="Microsoft.AspNetCore.Components.WebAssembly.Runtime" />
112112
<LatestPackageReference Include="Microsoft.Bcl.AsyncInterfaces" />
113-
<LatestPackageReference Include="Microsoft.CodeAnalysis.FxCopAnalyzers" />
114113
<LatestPackageReference Include="Microsoft.CodeAnalysis.PublicApiAnalyzers" />
115114
<LatestPackageReference Include="Microsoft.EntityFrameworkCore.Design" />
116115
<LatestPackageReference Include="Microsoft.EntityFrameworkCore.InMemory" />

eng/Versions.props

-1
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,6 @@
226226
<MicrosoftCodeAnalysisCSharpVersion>3.7.0</MicrosoftCodeAnalysisCSharpVersion>
227227
<MicrosoftCodeAnalysisCSharpWorkspacesVersion>3.7.0</MicrosoftCodeAnalysisCSharpWorkspacesVersion>
228228
<MicrosoftCodeAnalysisPublicApiAnalyzersVersion>3.3.0</MicrosoftCodeAnalysisPublicApiAnalyzersVersion>
229-
<MicrosoftCodeAnalysisFxCopAnalyzersVersion>3.0.0</MicrosoftCodeAnalysisFxCopAnalyzersVersion>
230229
<MicrosoftCssParserVersion>1.0.0-20200708.1</MicrosoftCssParserVersion>
231230
<MicrosoftIdentityModelClientsActiveDirectoryVersion>3.19.8</MicrosoftIdentityModelClientsActiveDirectoryVersion>
232231
<MicrosoftIdentityModelLoggingVersion>6.8.0</MicrosoftIdentityModelLoggingVersion>

eng/targets/CSharp.Common.props

-8
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,6 @@
1212
<PackageReference Include="MicroBuild.Core" Version="0.3.0" PrivateAssets="All" AllowExplicitReference="true" ExcludeAssets="All" />
1313
</ItemGroup>
1414

15-
<ItemGroup Condition=" '$(IsTestProject)' != 'true' AND '$(DotNetBuildFromSource)' != 'true' ">
16-
<Reference Include="Microsoft.CodeAnalysis.FxCopAnalyzers" PrivateAssets="All" />
17-
</ItemGroup>
18-
19-
<PropertyGroup>
20-
<CodeAnalysisRuleSet>$(RepoRoot)eng\AllRulesDisabled.ruleset</CodeAnalysisRuleSet>
21-
</PropertyGroup>
22-
2315
<ItemGroup Condition=" '$(IsTestProject)' == 'true' ">
2416
<Reference Include="Microsoft.AspNetCore.Testing" />
2517
<Reference Include="Moq" />

eng/tools/RepoTasks/.editorconfig

-4
This file was deleted.

eng/tools/RepoTasks/Uuid.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ namespace RepoTasks
1111
/// <summary>
1212
/// Implementation of RFC 4122 - A Universally Unique Identifier (UUID) URN Namespace.
1313
/// </summary>
14-
internal sealed class Uuid
14+
internal static class Uuid
1515
{
1616
/// <summary>
1717
/// Generates a version 3 UUID given a namespace UUID and name. This is based on the algorithm described in

src/Analyzers/Analyzers/src/OptionsAnalyzer.cs

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// Copyright (c) .NET Foundation. All rights reserved.
22
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
33

4+
using System;
45
using System.Collections.Immutable;
56
using Microsoft.CodeAnalysis;
67
using Microsoft.CodeAnalysis.Diagnostics;
@@ -27,7 +28,7 @@ public void AnalyzeConfigureServices(OperationBlockStartAnalysisContext context)
2728
operation.Value.ConstantValue.HasValue &&
2829
operation.Target is IPropertyReferenceOperation property &&
2930
property.Property?.ContainingType?.Name != null &&
30-
property.Property.ContainingType.Name.EndsWith("Options"))
31+
property.Property.ContainingType.Name.EndsWith("Options", StringComparison.Ordinal))
3132
{
3233
options.Add(new OptionsItem(property.Property, operation.Value.ConstantValue.Value));
3334
}

src/Azure/AzureAD/AzureAD.ruleset

-12
This file was deleted.

src/Azure/AzureAD/Directory.Build.props

-1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,5 @@
33

44
<PropertyGroup>
55
<WarningsNotAsErrors>xUnit1026:$(WarningsNotAsErrors)</WarningsNotAsErrors>
6-
<CodeAnalysisRuleSet>$(MSBuildThisFileDirectory)AzureAD.ruleset</CodeAnalysisRuleSet>
76
</PropertyGroup>
87
</Project>

src/HealthChecks/HealthChecks/src/HealthCheckPublisherHostedService.cs

+3-3
Original file line numberDiff line numberDiff line change
@@ -180,15 +180,15 @@ private async Task RunPublisherAsync(IHealthCheckPublisher publisher, HealthRepo
180180
// This is a cancellation - if the app is shutting down we want to ignore it. Otherwise, it's
181181
// a timeout and we want to log it.
182182
}
183-
catch (OperationCanceledException ocex)
183+
catch (OperationCanceledException)
184184
{
185185
Logger.HealthCheckPublisherTimeout(_logger, publisher, duration.GetElapsedTime());
186-
throw ocex;
186+
throw;
187187
}
188188
catch (Exception ex)
189189
{
190190
Logger.HealthCheckPublisherError(_logger, publisher, duration.GetElapsedTime(), ex);
191-
throw ex;
191+
throw;
192192
}
193193
}
194194

src/Mvc/.editorconfig

-30
This file was deleted.

src/Mvc/Directory.Build.props

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<Project>
22
<Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory)..\, Directory.Build.props))\Directory.Build.props" />
33

4-
<PropertyGroup Condition=" '$(IsTestProject)' == 'true' ">
5-
<CodeAnalysisRuleSet>$(MSBuildThisFileDirectory)MvcTests.ruleset</CodeAnalysisRuleSet>
6-
</PropertyGroup>
4+
<ItemGroup>
5+
<EditorConfigFiles Include="$(MSBuildThisFileDirectory)MvcTests.globalconfig" />
6+
</ItemGroup>
77
</Project>

src/Mvc/Mvc.Api.Analyzers/src/AddResponseTypeAttributeCodeFixAction.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ private static Dictionary<int, string> GetStatusCodeConstants(INamedTypeSymbol s
176176
{
177177
if (member is IFieldSymbol field &&
178178
field.Type.SpecialType == SpecialType.System_Int32 &&
179-
field.Name.StartsWith("Status") &&
179+
field.Name.StartsWith("Status", StringComparison.Ordinal) &&
180180
field.HasConstantValue &&
181181
field.ConstantValue is int statusCode)
182182
{

src/Mvc/MvcTests.globalconfig

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
is_global = true
2+
3+
dotnet_diagnostic.xUnit1026.severity = suggestion

src/Mvc/MvcTests.ruleset

-9
This file was deleted.

src/Razor/.editorconfig

-30
This file was deleted.

src/Razor/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version1_X/src/ViewComponentTypeVisitor.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ internal bool IsViewComponent(INamedTypeSymbol symbol)
6262
return false;
6363
}
6464

65-
return symbol.Name.EndsWith(ViewComponentTypes.ViewComponentSuffix) ||
65+
return symbol.Name.EndsWith(ViewComponentTypes.ViewComponentSuffix, StringComparison.Ordinal) ||
6666
AttributeIsDefined(symbol, _viewComponentAttribute);
6767
}
6868

src/Razor/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version2_X/src/AssemblyAttributeInjectionPass.cs

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// Copyright (c) .NET Foundation. All rights reserved.
22
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
33

4+
using System;
45
using System.Diagnostics;
56
using Microsoft.AspNetCore.Razor.Language;
67
using Microsoft.AspNetCore.Razor.Language.Intermediate;
@@ -90,7 +91,7 @@ private static string ConvertToViewEnginePath(string relativePath)
9091
}
9192

9293
// Checking for both / and \ because a \ will become a /.
93-
if (!relativePath.StartsWith("/") && !relativePath.StartsWith("\\"))
94+
if (!relativePath.StartsWith("/", StringComparison.Ordinal) && !relativePath.StartsWith("\\", StringComparison.Ordinal))
9495
{
9596
relativePath = "/" + relativePath;
9697
}

src/Razor/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version2_X/src/ViewComponentTypeVisitor.cs

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// Copyright (c) .NET Foundation. All rights reserved.
22
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
33

4+
using System;
45
using System.Collections.Generic;
56
using System.Linq;
67
using Microsoft.CodeAnalysis;
@@ -64,7 +65,7 @@ internal bool IsViewComponent(INamedTypeSymbol symbol)
6465
return false;
6566
}
6667

67-
return symbol.Name.EndsWith(ViewComponentTypes.ViewComponentSuffix) ||
68+
return symbol.Name.EndsWith(ViewComponentTypes.ViewComponentSuffix, StringComparison.Ordinal) ||
6869
AttributeIsDefined(symbol, _viewComponentAttribute);
6970
}
7071

src/Razor/Microsoft.AspNetCore.Mvc.Razor.Extensions/src/ViewComponentTypeVisitor.cs

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// Copyright (c) .NET Foundation. All rights reserved.
22
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
33

4+
using System;
45
using System.Collections.Generic;
56
using System.Linq;
67
using Microsoft.CodeAnalysis;
@@ -64,7 +65,7 @@ internal bool IsViewComponent(INamedTypeSymbol symbol)
6465
return false;
6566
}
6667

67-
return symbol.Name.EndsWith(ViewComponentTypes.ViewComponentSuffix) ||
68+
return symbol.Name.EndsWith(ViewComponentTypes.ViewComponentSuffix, StringComparison.Ordinal) ||
6869
AttributeIsDefined(symbol, _viewComponentAttribute);
6970
}
7071

src/Razor/Microsoft.AspNetCore.Razor.Language/src/Components/ComponentBindLoweringPass.cs

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// Copyright (c) .NET Foundation. All rights reserved.
22
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
33

4+
using System;
45
using System.Collections.Generic;
56
using System.Globalization;
67
using System.Linq;
@@ -496,7 +497,7 @@ private bool TryParseBindAttribute(BindEntry bindEntry, out string valueAttribut
496497
return true;
497498
}
498499

499-
if (!attributeName.StartsWith("bind-"))
500+
if (!attributeName.StartsWith("bind-", StringComparison.Ordinal))
500501
{
501502
return false;
502503
}
@@ -548,7 +549,7 @@ private bool TryComputeAttributeNames(
548549
if (bindEntry.BindEventNode == null)
549550
{
550551
// @bind:event not specified
551-
changeAttributeName ??= node.TagHelper.GetChangeAttributeName();
552+
changeAttributeName = node.TagHelper.GetChangeAttributeName();
552553
}
553554
else if (TryExtractEventNodeStaticText(bindEntry.BindEventNode, out var text))
554555
{

src/Razor/Microsoft.AspNetCore.Razor.Language/src/Components/ComponentMarkupEncodingPass.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright (c) .NET Foundation. All rights reserved.
1+
// Copyright (c) .NET Foundation. All rights reserved.
22
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
33

44
using System;
@@ -171,7 +171,7 @@ private bool TryGetHtmlEntity(string content, int position, out string entity, o
171171
if (endPosition != -1)
172172
{
173173
entity = content.Substring(position, endPosition - position + 1);
174-
if (entity.StartsWith("&#"))
174+
if (entity.StartsWith("&#", StringComparison.Ordinal))
175175
{
176176
// Extract the codepoint and map it to an entity.
177177

src/Razor/Microsoft.AspNetCore.Razor.Language/src/DefaultAllowedChildTagDescriptorBuilder.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ public AllowedChildTagDescriptor Build()
4747
var descriptor = new DefaultAllowedChildTagDescriptor(
4848
Name,
4949
displayName,
50-
diagnostics?.ToArray() ?? Array.Empty<RazorDiagnostic>());
50+
diagnostics.ToArray());
5151

5252
return descriptor;
5353
}

0 commit comments

Comments
 (0)