Skip to content

Commit

Permalink
Use NetAnalyzers from SDK instead of FxCopAnalyzers (dotnet#30138)
Browse files Browse the repository at this point in the history
* Use analyzers from .NET SDK
  • Loading branch information
Youssef1313 authored Feb 19, 2021
1 parent 01982de commit 350ea5b
Show file tree
Hide file tree
Showing 52 changed files with 127 additions and 413 deletions.
31 changes: 28 additions & 3 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,32 @@ insert_final_newline = true
indent_size = 4
dotnet_sort_system_directives_first = true

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

# use int x = .. over Int32
dotnet_style_predefined_type_for_locals_parameters_members = true:suggestion

# use int.MaxValue over Int32.MaxValue
dotnet_style_predefined_type_for_member_access = true:suggestion

# Require var all the time.
csharp_style_var_for_built_in_types = true:suggestion
csharp_style_var_when_type_is_apparent = true:suggestion
csharp_style_var_elsewhere = true:suggestion

# Disallow throw expressions.
csharp_style_throw_expression = false:suggestion

# Newline settings
csharp_new_line_before_open_brace = all
csharp_new_line_before_else = true
csharp_new_line_before_catch = true
csharp_new_line_before_finally = true
csharp_new_line_before_members_in_object_initializers = true
csharp_new_line_before_members_in_anonymous_types = true

[*.{xml,config,*proj,nuspec,props,resx,targets,yml,tasks}]
indent_size = 2

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

[*.cs]
dotnet_diagnostic.CA1304.severity = error
[*.{cs,vb}]
# CA1305: Specify IFormatProvider
dotnet_diagnostic.CA1305.severity = error
dotnet_diagnostic.CA1310.severity = error
16 changes: 16 additions & 0 deletions .globalconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
is_global = true

# CA1309: Use ordinal StringComparison
# https://github.com/dotnet/aspnetcore/pull/30111#issuecomment-777817003
dotnet_diagnostic.CA1309.severity = suggestion

# CA3076: Insecure XSLT Script Execution
# Disabled due to crashing: https://github.com/dotnet/roslyn-analyzers/issues/4750
# Delete the following line when we have a working version.
dotnet_diagnostic.CA3076.severity = none

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

# CA1310: Specify StringComparison for correctness
dotnet_diagnostic.CA1310.severity = error
6 changes: 6 additions & 0 deletions Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@
<RepositoryType>git</RepositoryType>
</PropertyGroup>

<PropertyGroup>
<EnableNETAnalyzers>true</EnableNETAnalyzers>
<AnalysisLevel>latest</AnalysisLevel>
<AnalysisMode>Default</AnalysisMode>
</PropertyGroup>

<!-- Defines project type conventions. -->
<PropertyGroup>
<RepoRelativeProjectDir>$([MSBuild]::MakeRelative($(RepoRoot), $(MSBuildProjectDirectory)))</RepoRelativeProjectDir>
Expand Down
216 changes: 0 additions & 216 deletions eng/AllRulesDisabled.ruleset

This file was deleted.

1 change: 0 additions & 1 deletion eng/Dependencies.props
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,6 @@ and are generated based on the last package release.
<LatestPackageReference Include="Microsoft.AspNetCore.AzureAppServices.SiteExtension.5.0.x86" />
<LatestPackageReference Include="Microsoft.AspNetCore.Components.WebAssembly.Runtime" />
<LatestPackageReference Include="Microsoft.Bcl.AsyncInterfaces" />
<LatestPackageReference Include="Microsoft.CodeAnalysis.FxCopAnalyzers" />
<LatestPackageReference Include="Microsoft.CodeAnalysis.PublicApiAnalyzers" />
<LatestPackageReference Include="Microsoft.EntityFrameworkCore.Design" />
<LatestPackageReference Include="Microsoft.EntityFrameworkCore.InMemory" />
Expand Down
1 change: 0 additions & 1 deletion eng/Versions.props
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,6 @@
<MicrosoftCodeAnalysisCSharpVersion>3.7.0</MicrosoftCodeAnalysisCSharpVersion>
<MicrosoftCodeAnalysisCSharpWorkspacesVersion>3.7.0</MicrosoftCodeAnalysisCSharpWorkspacesVersion>
<MicrosoftCodeAnalysisPublicApiAnalyzersVersion>3.3.0</MicrosoftCodeAnalysisPublicApiAnalyzersVersion>
<MicrosoftCodeAnalysisFxCopAnalyzersVersion>3.0.0</MicrosoftCodeAnalysisFxCopAnalyzersVersion>
<MicrosoftCssParserVersion>1.0.0-20200708.1</MicrosoftCssParserVersion>
<MicrosoftIdentityModelClientsActiveDirectoryVersion>3.19.8</MicrosoftIdentityModelClientsActiveDirectoryVersion>
<MicrosoftIdentityModelLoggingVersion>6.8.0</MicrosoftIdentityModelLoggingVersion>
Expand Down
8 changes: 0 additions & 8 deletions eng/targets/CSharp.Common.props
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,6 @@
<PackageReference Include="MicroBuild.Core" Version="0.3.0" PrivateAssets="All" AllowExplicitReference="true" ExcludeAssets="All" />
</ItemGroup>

<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
4 changes: 0 additions & 4 deletions eng/tools/RepoTasks/.editorconfig

This file was deleted.

2 changes: 1 addition & 1 deletion eng/tools/RepoTasks/Uuid.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ namespace RepoTasks
/// <summary>
/// Implementation of RFC 4122 - A Universally Unique Identifier (UUID) URN Namespace.
/// </summary>
internal sealed class Uuid
internal static class Uuid
{
/// <summary>
/// Generates a version 3 UUID given a namespace UUID and name. This is based on the algorithm described in
Expand Down
3 changes: 2 additions & 1 deletion src/Analyzers/Analyzers/src/OptionsAnalyzer.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.

using System;
using System.Collections.Immutable;
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.Diagnostics;
Expand All @@ -27,7 +28,7 @@ public void AnalyzeConfigureServices(OperationBlockStartAnalysisContext context)
operation.Value.ConstantValue.HasValue &&
operation.Target is IPropertyReferenceOperation property &&
property.Property?.ContainingType?.Name != null &&
property.Property.ContainingType.Name.EndsWith("Options"))
property.Property.ContainingType.Name.EndsWith("Options", StringComparison.Ordinal))
{
options.Add(new OptionsItem(property.Property, operation.Value.ConstantValue.Value));
}
Expand Down
12 changes: 0 additions & 12 deletions src/Azure/AzureAD/AzureAD.ruleset

This file was deleted.

1 change: 0 additions & 1 deletion src/Azure/AzureAD/Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,5 @@

<PropertyGroup>
<WarningsNotAsErrors>xUnit1026:$(WarningsNotAsErrors)</WarningsNotAsErrors>
<CodeAnalysisRuleSet>$(MSBuildThisFileDirectory)AzureAD.ruleset</CodeAnalysisRuleSet>
</PropertyGroup>
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -180,15 +180,15 @@ private async Task RunPublisherAsync(IHealthCheckPublisher publisher, HealthRepo
// This is a cancellation - if the app is shutting down we want to ignore it. Otherwise, it's
// a timeout and we want to log it.
}
catch (OperationCanceledException ocex)
catch (OperationCanceledException)
{
Logger.HealthCheckPublisherTimeout(_logger, publisher, duration.GetElapsedTime());
throw ocex;
throw;
}
catch (Exception ex)
{
Logger.HealthCheckPublisherError(_logger, publisher, duration.GetElapsedTime(), ex);
throw ex;
throw;
}
}

Expand Down
30 changes: 0 additions & 30 deletions src/Mvc/.editorconfig

This file was deleted.

6 changes: 3 additions & 3 deletions src/Mvc/Directory.Build.props
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project>
<Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory)..\, Directory.Build.props))\Directory.Build.props" />

<PropertyGroup Condition=" '$(IsTestProject)' == 'true' ">
<CodeAnalysisRuleSet>$(MSBuildThisFileDirectory)MvcTests.ruleset</CodeAnalysisRuleSet>
</PropertyGroup>
<ItemGroup>
<EditorConfigFiles Include="$(MSBuildThisFileDirectory)MvcTests.globalconfig" />
</ItemGroup>
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ private static Dictionary<int, string> GetStatusCodeConstants(INamedTypeSymbol s
{
if (member is IFieldSymbol field &&
field.Type.SpecialType == SpecialType.System_Int32 &&
field.Name.StartsWith("Status") &&
field.Name.StartsWith("Status", StringComparison.Ordinal) &&
field.HasConstantValue &&
field.ConstantValue is int statusCode)
{
Expand Down
3 changes: 3 additions & 0 deletions src/Mvc/MvcTests.globalconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
is_global = true

dotnet_diagnostic.xUnit1026.severity = suggestion
9 changes: 0 additions & 9 deletions src/Mvc/MvcTests.ruleset

This file was deleted.

30 changes: 0 additions & 30 deletions src/Razor/.editorconfig

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ internal bool IsViewComponent(INamedTypeSymbol symbol)
return false;
}

return symbol.Name.EndsWith(ViewComponentTypes.ViewComponentSuffix) ||
return symbol.Name.EndsWith(ViewComponentTypes.ViewComponentSuffix, StringComparison.Ordinal) ||
AttributeIsDefined(symbol, _viewComponentAttribute);
}

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

using System;
using System.Diagnostics;
using Microsoft.AspNetCore.Razor.Language;
using Microsoft.AspNetCore.Razor.Language.Intermediate;
Expand Down Expand Up @@ -90,7 +91,7 @@ private static string ConvertToViewEnginePath(string relativePath)
}

// Checking for both / and \ because a \ will become a /.
if (!relativePath.StartsWith("/") && !relativePath.StartsWith("\\"))
if (!relativePath.StartsWith("/", StringComparison.Ordinal) && !relativePath.StartsWith("\\", StringComparison.Ordinal))
{
relativePath = "/" + relativePath;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.

using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.CodeAnalysis;
Expand Down Expand Up @@ -64,7 +65,7 @@ internal bool IsViewComponent(INamedTypeSymbol symbol)
return false;
}

return symbol.Name.EndsWith(ViewComponentTypes.ViewComponentSuffix) ||
return symbol.Name.EndsWith(ViewComponentTypes.ViewComponentSuffix, StringComparison.Ordinal) ||
AttributeIsDefined(symbol, _viewComponentAttribute);
}

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

using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.CodeAnalysis;
Expand Down Expand Up @@ -64,7 +65,7 @@ internal bool IsViewComponent(INamedTypeSymbol symbol)
return false;
}

return symbol.Name.EndsWith(ViewComponentTypes.ViewComponentSuffix) ||
return symbol.Name.EndsWith(ViewComponentTypes.ViewComponentSuffix, StringComparison.Ordinal) ||
AttributeIsDefined(symbol, _viewComponentAttribute);
}

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

using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
Expand Down Expand Up @@ -496,7 +497,7 @@ private bool TryParseBindAttribute(BindEntry bindEntry, out string valueAttribut
return true;
}

if (!attributeName.StartsWith("bind-"))
if (!attributeName.StartsWith("bind-", StringComparison.Ordinal))
{
return false;
}
Expand Down Expand Up @@ -548,7 +549,7 @@ private bool TryComputeAttributeNames(
if (bindEntry.BindEventNode == null)
{
// @bind:event not specified
changeAttributeName ??= node.TagHelper.GetChangeAttributeName();
changeAttributeName = node.TagHelper.GetChangeAttributeName();
}
else if (TryExtractEventNodeStaticText(bindEntry.BindEventNode, out var text))
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public AllowedChildTagDescriptor Build()
var descriptor = new DefaultAllowedChildTagDescriptor(
Name,
displayName,
diagnostics?.ToArray() ?? Array.Empty<RazorDiagnostic>());
diagnostics.ToArray());

return descriptor;
}
Expand Down
Loading

0 comments on commit 350ea5b

Please sign in to comment.