Skip to content
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

CA1802 Fixes and Severity to Warning #7177

Merged
merged 6 commits into from
Jan 10, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion eng/CodeAnalysis.ruleset
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@
<Rule Id="CA1721" Action="None" /> <!-- Property names should not match get methods -->
<Rule Id="CA1724" Action="None" /> <!-- Type names should not match namespaces -->
<Rule Id="CA1801" Action="None" /> <!-- Review unused parameters -->
<Rule Id="CA1802" Action="Info" /> <!-- Use literals where appropriate -->
<Rule Id="CA1802" Action="Warning" /> <!-- Use literals where appropriate -->
<Rule Id="CA1805" Action="Info" /> <!-- Do not initialize unnecessarily -->
<Rule Id="CA1806" Action="None" />
<Rule Id="CA1810" Action="Info" /> <!-- Initialize reference type static fields inline -->
Expand Down
2 changes: 1 addition & 1 deletion src/Build.OM.UnitTests/Definition/Project_Tests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public void Dispose()
ProjectCollection.GlobalProjectCollection.GlobalProperties.ShouldBeEmpty();
}

private static readonly string ProjectWithItemGroup =
private const string ProjectWithItemGroup =
@"<Project ToolsVersion='msbuilddefaulttoolsversion' DefaultTargets='Build' xmlns='msbuildnamespace'>
<ItemGroup>
{0}
Expand Down
10 changes: 5 additions & 5 deletions src/Build.UnitTests/Graph/GraphTestingUtilities.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,21 +16,21 @@ internal static class GraphTestingUtilities
{
public static readonly ImmutableDictionary<string, string> EmptyGlobalProperties = new Dictionary<string, string> {{PropertyNames.IsGraphBuild, "true"}}.ToImmutableDictionary();

public static readonly string InnerBuildPropertyName = "InnerBuild";
public static readonly string InnerBuildPropertiesName = "InnerBuildProperties";
public const string InnerBuildPropertyName = "InnerBuild";
public const string InnerBuildPropertiesName = "InnerBuildProperties";

public static readonly string MultitargetingSpecificationPropertyGroup = $@"<PropertyGroup>
public const string MultitargetingSpecificationPropertyGroup = $@"<PropertyGroup>
<InnerBuildProperty>{InnerBuildPropertyName}</InnerBuildProperty>
<InnerBuildPropertyValues>{InnerBuildPropertiesName}</InnerBuildPropertyValues>
<{InnerBuildPropertiesName}>a;b</{InnerBuildPropertiesName}>
</PropertyGroup>";
public static readonly string HardCodedInnerBuildWithMultitargetingSpecification = $@"<PropertyGroup>
public const string HardCodedInnerBuildWithMultitargetingSpecification = $@"<PropertyGroup>
<InnerBuildProperty>{InnerBuildPropertyName}</InnerBuildProperty>
<InnerBuildPropertyValues>{InnerBuildPropertiesName}</InnerBuildPropertyValues>
<{InnerBuildPropertyName}>a</{InnerBuildPropertyName}>
</PropertyGroup>";

public static readonly string EnableTransitiveProjectReferencesPropertyGroup = @"<PropertyGroup>
public const string EnableTransitiveProjectReferencesPropertyGroup = @"<PropertyGroup>
<AddTransitiveProjectReferencesInStaticGraph>true</AddTransitiveProjectReferencesInStaticGraph>
</PropertyGroup>";

Expand Down
12 changes: 6 additions & 6 deletions src/Build.UnitTests/Graph/ProjectGraph_Tests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,15 @@ public class ProjectGraphTests : IDisposable
{
private TestEnvironment _env;

private static readonly string ProjectReferenceTargetsWithMultitargeting = @"<ItemGroup>
<!-- Item order is important to ensure outer build targets are put in front of inner build ones -->
<ProjectReferenceTargets Include='A' Targets='AHelperInner;A' />
<ProjectReferenceTargets Include='A' Targets='AHelperOuter' OuterBuild='true' />
</ItemGroup>";
private const string ProjectReferenceTargetsWithMultitargeting = @"<ItemGroup>
<!-- Item order is important to ensure outer build targets are put in front of inner build ones -->
<ProjectReferenceTargets Include='A' Targets='AHelperInner;A' />
<ProjectReferenceTargets Include='A' Targets='AHelperOuter' OuterBuild='true' />
</ItemGroup>";
private static string[] NonOuterBuildTargets = {"AHelperOuter", "AHelperInner", "A"};
private static string[] OuterBuildTargets = {"AHelperOuter"};

private static readonly string OuterBuildSpecificationWithProjectReferenceTargets = MultitargetingSpecificationPropertyGroup + ProjectReferenceTargetsWithMultitargeting;
private const string OuterBuildSpecificationWithProjectReferenceTargets = MultitargetingSpecificationPropertyGroup + ProjectReferenceTargetsWithMultitargeting;

public ProjectGraphTests(ITestOutputHelper outputHelper)
{
Expand Down
2 changes: 1 addition & 1 deletion src/Build.UnitTests/ProjectCache/ProjectCacheTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public void Dispose()
_env.Dispose();
}

private static readonly string AssemblyMockCache = nameof(AssemblyMockCache);
private const string AssemblyMockCache = nameof(AssemblyMockCache);

private static readonly Lazy<string> SamplePluginAssemblyPath =
new Lazy<string>(
Expand Down
2 changes: 2 additions & 0 deletions src/Build/Evaluation/ProjectRootElementCache.cs
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,9 @@ internal class ProjectRootElementCache : ProjectRootElementCacheBase
/// If this number is increased much higher, the datastructure may
/// need to be changed from a linked list, since it's currently O(n).
/// </remarks>
#pragma warning disable CA1802 // Use literals where appropriate
private static readonly int s_maximumStrongCacheSize = 200;
#pragma warning restore CA1802 // Use literals where appropriate

/// <summary>
/// Whether the cache should log activity to the Debug.Out stream
Expand Down
2 changes: 1 addition & 1 deletion src/Build/Graph/GraphBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ namespace Microsoft.Build.Graph
{
internal class GraphBuilder
{
internal static readonly string SolutionItemReference = "_SolutionReference";
internal const string SolutionItemReference = "_SolutionReference";

/// <summary>
/// The thread calling BuildGraph() will act as an implicit worker
Expand Down
40 changes: 40 additions & 0 deletions src/Build/Microsoft.Build.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,46 @@
<NoWarn>$(NoWarn);NU5104</NoWarn>
</PropertyGroup>

<PropertyGroup Condition="'$(Configuration)|$(TargetFramework)|$(Platform)'=='Debug|net472|AnyCPU'">
<CodeAnalysisRuleSet />
</PropertyGroup>

<PropertyGroup Condition="'$(Configuration)|$(TargetFramework)|$(Platform)'=='Debug|net472|x64'">
<CodeAnalysisRuleSet />
</PropertyGroup>

<PropertyGroup Condition="'$(Configuration)|$(TargetFramework)|$(Platform)'=='Release|net472|AnyCPU'">
<CodeAnalysisRuleSet />
</PropertyGroup>

<PropertyGroup Condition="'$(Configuration)|$(TargetFramework)|$(Platform)'=='Release|net472|x64'">
<CodeAnalysisRuleSet />
</PropertyGroup>

<PropertyGroup Condition="'$(Configuration)|$(TargetFramework)|$(Platform)'=='Debug-MONO|net472|AnyCPU'">
<CodeAnalysisRuleSet />
</PropertyGroup>

<PropertyGroup Condition="'$(Configuration)|$(TargetFramework)|$(Platform)'=='Debug-MONO|net472|x64'">
<CodeAnalysisRuleSet />
</PropertyGroup>

<PropertyGroup Condition="'$(Configuration)|$(TargetFramework)|$(Platform)'=='Release-MONO|net472|AnyCPU'">
<CodeAnalysisRuleSet />
</PropertyGroup>

<PropertyGroup Condition="'$(Configuration)|$(TargetFramework)|$(Platform)'=='Release-MONO|net472|x64'">
<CodeAnalysisRuleSet />
</PropertyGroup>

<PropertyGroup Condition="'$(Configuration)|$(TargetFramework)|$(Platform)'=='MachineIndependent|net472|AnyCPU'">
<CodeAnalysisRuleSet />
</PropertyGroup>

<PropertyGroup Condition="'$(Configuration)|$(TargetFramework)|$(Platform)'=='MachineIndependent|net472|x64'">
<CodeAnalysisRuleSet />
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="..\Framework\Microsoft.Build.Framework.csproj" />
<ProjectReference Include="..\StringTools\StringTools.csproj" />
Expand Down
4 changes: 2 additions & 2 deletions src/Shared/FileUtilitiesRegex.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ namespace Microsoft.Build.Shared
/// </summary>
internal static class FileUtilitiesRegex
{
private static readonly char _backSlash = '\\';
private static readonly char _forwardSlash = '/';
private const char _backSlash = '\\';
private const char _forwardSlash = '/';

/// <summary>
/// Indicates whether the specified string follows the pattern drive pattern (for example "C:", "D:").
Expand Down
6 changes: 3 additions & 3 deletions src/Shared/UnitTests/TypeLoader_Dependencies_Tests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ namespace Microsoft.Build.UnitTests
public class TypeLoader_Dependencies_Tests
{
private static readonly string ProjectFileFolder = Path.Combine(BuildEnvironmentHelper.Instance.CurrentMSBuildToolsDirectory, "TaskWithDependency");
private static readonly string ProjectFileName = "TaskWithDependencyTest.proj";
private static readonly string TaskDllFileName = "TaskWithDependency.dll";
private static readonly string DependencyDllFileName = "Dependency.dll";
private const string ProjectFileName = "TaskWithDependencyTest.proj";
private const string TaskDllFileName = "TaskWithDependency.dll";
private const string DependencyDllFileName = "Dependency.dll";

[Fact]
public void LoadAssemblyAndDependency_InsideProjectFolder()
Expand Down
4 changes: 2 additions & 2 deletions src/Shared/UnitTests/TypeLoader_Tests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ namespace Microsoft.Build.UnitTests
public class TypeLoader_Tests
{
private static readonly string ProjectFileFolder = Path.Combine(BuildEnvironmentHelper.Instance.CurrentMSBuildToolsDirectory, "PortableTask");
private static readonly string ProjectFileName = "portableTaskTest.proj";
private static readonly string DLLFileName = "PortableTask.dll";
private const string ProjectFileName = "portableTaskTest.proj";
private const string DLLFileName = "PortableTask.dll";

[Fact]
public void Basic()
Expand Down
4 changes: 2 additions & 2 deletions src/Tasks.UnitTests/WriteCodeFragment_Tests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -482,8 +482,8 @@ public void MultilineAttributeCSharp()
File.Delete(task.OutputFile.ItemSpec);
}

private static readonly string VBCarriageReturn = "Global.Microsoft.VisualBasic.ChrW(13)";
private static readonly string VBLineFeed = "Global.Microsoft.VisualBasic.ChrW(10)";
private const string VBCarriageReturn = "Global.Microsoft.VisualBasic.ChrW(13)";
private const string VBLineFeed = "Global.Microsoft.VisualBasic.ChrW(10)";

public static readonly string VBLineSeparator = RuntimeInformation.IsOSPlatform(OSPlatform.Windows) ? $"{VBCarriageReturn}&{VBLineFeed}" : VBLineFeed;

Expand Down