Skip to content

DotNet9 #169

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

Merged
merged 5 commits into from
Nov 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
10 changes: 10 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -516,11 +516,20 @@ dotnet_diagnostic.S1135.severity = suggestion # https://github.com/atc-net
# Custom - Code Analyzers Rules
##########################################

dotnet_diagnostic.IDE0010.severity = suggestion # Populate switch
dotnet_diagnostic.IDE0021.severity = suggestion # Use expression body for constructor
dotnet_diagnostic.IDE0046.severity = suggestion # If statement can be simplified
dotnet_diagnostic.IDE0055.severity = none # Fix formatting
dotnet_diagnostic.IDE0057.severity = none # Substring can be simplified
dotnet_diagnostic.IDE0072.severity = suggestion # Populate switch
dotnet_diagnostic.IDE0130.severity = suggestion # Namespace does not match folder structure
dotnet_diagnostic.IDE0290.severity = none # Use primary constructor
dotnet_diagnostic.IDE0305.severity = suggestion # Collection initialization can be simplified

dotnet_diagnostic.SA1010.severity = none #

dotnet_diagnostic.CA1054.severity = none # URI parameters should not be strings
dotnet_diagnostic.CA1515.severity = suggestion # Because an application's API isn't typically referenced from outside the assembly, types can be made internal (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1515)
dotnet_diagnostic.CA1848.severity = none # For improved performance, use the LoggerMessage delegates instead of calling 'LoggerExtensions.LogTrace(ILogger, string, params object[])'
dotnet_diagnostic.CA1859.severity = none #
dotnet_diagnostic.CA1860.severity = none #
Expand All @@ -536,6 +545,7 @@ dotnet_diagnostic.S1172.severity = none # False positive
dotnet_diagnostic.S2589.severity = none #
dotnet_diagnostic.S2629.severity = none #
dotnet_diagnostic.S3267.severity = none #
dotnet_diagnostic.S3358.severity = none #
dotnet_diagnostic.S3878.severity = none #
dotnet_diagnostic.S4457.severity = none # Split this method into two, one handling parameters check and the other handling the asynchronous code
dotnet_diagnostic.S6602.severity = none #
Expand Down
2 changes: 1 addition & 1 deletion Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
<ImplicitUsings>enable</ImplicitUsings>
<TargetFramework>net8.0</TargetFramework>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
<NoWarn>1573,1591,1712,CA1014</NoWarn>
<NoWarn>1573,1591,1712,CA1014,NU1903</NoWarn>

<!-- Used by code coverage -->
<DebugType>full</DebugType>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public AnalyzerProviderBaseRuleData(string name)
public string Name { get; set; } = string.Empty;

[SuppressMessage("Usage", "CA2227:Collection properties should be read only", Justification = "OK.")]
public ICollection<Rule> Rules { get; set; } = new List<Rule>();
public ICollection<Rule> Rules { get; set; } = [];

public string? ExceptionMessage { get; set; }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ public override string Description
get
{
var defaultValue = new OptionsFile().ProjectTarget;
var values = Enum.GetNames(typeof(SupportedProjectTargetType))
var values = Enum.GetNames<SupportedProjectTargetType>()
.Select(enumValue => enumValue.Equals(defaultValue.ToString(), StringComparison.Ordinal)
? $"{enumValue} (default)"
: enumValue)
Expand Down
11 changes: 4 additions & 7 deletions src/Atc.CodingRules.Updater.CLI/Commands/RunCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -140,13 +140,10 @@ private static async Task<OptionsFile> GetOptionsFromFileAndUserArguments(
buildFile = settings.BuildFile.Value;
}

if (!string.IsNullOrEmpty(buildFile))
{
return buildFile.Contains(':', StringComparison.Ordinal)
return !string.IsNullOrEmpty(buildFile)
? buildFile.Contains(':', StringComparison.Ordinal)
? new FileInfo(buildFile)
: new FileInfo(Path.Combine(projectPath.FullName, buildFile));
}

return null;
: new FileInfo(Path.Combine(projectPath.FullName, buildFile))
: null;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,11 @@ public class ProjectBaseCommandSettings : BaseCommandSettings
public override ValidationResult Validate()
{
var validationResult = base.Validate();
if (!validationResult.Successful)
{
return validationResult;
}

return string.IsNullOrEmpty(ProjectPath)
? ValidationResult.Error("ProjectPath is missing.")
: ValidationResult.Success();
return !validationResult.Successful
? validationResult
: string.IsNullOrEmpty(ProjectPath)
? ValidationResult.Error("ProjectPath is missing.")
: ValidationResult.Success();
}

internal string GetOptionsPath()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ namespace Atc.CodingRules.Updater.CLI.Models.Options;
public class OptionsFolderMappings
{
[SuppressMessage("Usage", "CA2227:Collection properties should be read only", Justification = "OK.")]
public IList<string> Paths { get; set; } = new List<string>();
public IList<string> Paths { get; set; } = [];

public override string ToString()
=> $"{nameof(Paths)}.Count: {Paths.Count}";
Expand Down
30 changes: 12 additions & 18 deletions src/Atc.CodingRules.Updater.CLI/ProjectHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ is SupportedProjectTargetType.DotNetCore
or SupportedProjectTargetType.DotNet5
or SupportedProjectTargetType.DotNet6
or SupportedProjectTargetType.DotNet7
or SupportedProjectTargetType.DotNet8)
or SupportedProjectTargetType.DotNet8
or SupportedProjectTargetType.DotNet9)
{
HandleDirectoryBuildPropsFiles(logger, projectPath, options);

Expand Down Expand Up @@ -140,24 +141,17 @@ private static ProjectFrameworkType DetermineProjectFrameworkType(
Path.GetFileNameWithoutExtension(csProjFile.Name),
StringComparison.OrdinalIgnoreCase));

if (optionsProjectFrameworkMapping is not null)
projectFrameworkType = optionsProjectFrameworkMapping?.Type ?? projectType switch
{
projectFrameworkType = optionsProjectFrameworkMapping.Type;
}
else
{
projectFrameworkType = projectType switch
{
DotnetProjectType.AzureFunctionApp => ProjectFrameworkType.AzureFunctions,
DotnetProjectType.BlazorServerApp or DotnetProjectType.BlazorWAsmApp => ProjectFrameworkType.Blazor,
DotnetProjectType.CliApp => ProjectFrameworkType.Cli,
DotnetProjectType.MauiApp => ProjectFrameworkType.Maui,
DotnetProjectType.WinFormApp => ProjectFrameworkType.WinForms,
DotnetProjectType.WpfApp or DotnetProjectType.WpfLibrary => ProjectFrameworkType.Wpf,
DotnetProjectType.WebApi => ProjectFrameworkType.WebApi,
_ => projectFrameworkType,
};
}
DotnetProjectType.AzureFunctionApp => ProjectFrameworkType.AzureFunctions,
DotnetProjectType.BlazorServerApp or DotnetProjectType.BlazorWAsmApp => ProjectFrameworkType.Blazor,
DotnetProjectType.CliApp => ProjectFrameworkType.Cli,
DotnetProjectType.MauiApp => ProjectFrameworkType.Maui,
DotnetProjectType.WinFormApp => ProjectFrameworkType.WinForms,
DotnetProjectType.WpfApp or DotnetProjectType.WpfLibrary => ProjectFrameworkType.Wpf,
DotnetProjectType.WebApi => ProjectFrameworkType.WebApi,
_ => projectFrameworkType,
};

return projectFrameworkType;
}
Expand Down
2 changes: 1 addition & 1 deletion src/Atc.CodingRules.Updater/EditorConfigHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -333,7 +333,7 @@ private static List<Tuple<string, List<string>>> ExtractContentCustomParts(
}

workingOnCustomHeader = nextLine.Substring(CustomSectionHeaderPrefix.Length).Trim();
workingOnCustomLines = new List<string>();
workingOnCustomLines = [];
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/Atc.CodingRules.Updater/Extensions/StringExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ namespace System;

public static class StringExtensions
{
private static readonly string[] LineBreaks = { "\r\n", "\r", "\n" };
private static readonly string[] LineBreaks = ["\r\n", "\r", "\n"];

public static string TrimEndForEmptyLines(
this string value)
Expand All @@ -25,7 +25,7 @@ public static string TrimEndForEmptyLines(
public static Collection<KeyValueItem> GetKeyValues(
this string value)
=> string.IsNullOrEmpty(value)
? new Collection<KeyValueItem>()
? []
: value
.Split(LineBreaks, StringSplitOptions.RemoveEmptyEntries)
.GetKeyValues();
Expand Down
10 changes: 2 additions & 8 deletions src/Atc.CodingRules.Updater/FileHelper.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
// ReSharper disable ConvertIfStatementToReturnStatement
namespace Atc.CodingRules.Updater;

public static class FileHelper
Expand Down Expand Up @@ -83,13 +82,8 @@ public static bool AreFilesEqual(
return false;
}

if (headerLinesA.Find(x => x.StartsWith("# Distribution", StringComparison.CurrentCultureIgnoreCase)) !=
headerLinesB.Find(x => x.StartsWith("# Distribution", StringComparison.CurrentCultureIgnoreCase)))
{
return false;
}

return true;
return headerLinesA.Find(x => x.StartsWith("# Distribution", StringComparison.CurrentCultureIgnoreCase)) ==
headerLinesB.Find(x => x.StartsWith("# Distribution", StringComparison.CurrentCultureIgnoreCase));
}

public static bool ContainsEditorConfigFile(
Expand Down
1 change: 1 addition & 0 deletions src/Atc.CodingRules.Updater/ProjectSanityCheckHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ public static void CheckFiles(
case SupportedProjectTargetType.DotNet6:
case SupportedProjectTargetType.DotNet7:
case SupportedProjectTargetType.DotNet8:
case SupportedProjectTargetType.DotNet9:
HasTargetFrameworkAndImplicitUsings(throwIf, logger, projectPath, "netcoreapp3.1");
break;
}
Expand Down
9 changes: 5 additions & 4 deletions src/Atc.CodingRules.Updater/SupportedProjectTargetType.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@ namespace Atc.CodingRules.Updater;
public enum SupportedProjectTargetType
{
DotNetCore,
DotNet5,
DotNet6,
DotNet7,
DotNet8,
DotNet5, // STS
DotNet6, // LTS
DotNet7, // STS
DotNet8, // LTS
DotNet9, // STS
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,6 @@ public async Task CollectBaseRules(ProviderCollectingMode providerCollectingMode
Assert.NotNull(actual.Name);
Assert.Equal(MicrosoftCompilerErrorsProvider.Name, actual.Name);
Assert.NotNull(actual.Rules);
Assert.True(actual.Rules.Count >= 910);
Assert.True(actual.Rules.Count >= 850);
}
}