Skip to content

Commit f1b4fbb

Browse files
authored
Merge pull request #169 from atc-net/feature/dotnet9
DotNet9
2 parents 95c1010 + 111c583 commit f1b4fbb

File tree

14 files changed

+47
-53
lines changed

14 files changed

+47
-53
lines changed

.editorconfig

+10
Original file line numberDiff line numberDiff line change
@@ -516,11 +516,20 @@ dotnet_diagnostic.S1135.severity = suggestion # https://github.com/atc-net
516516
# Custom - Code Analyzers Rules
517517
##########################################
518518

519+
dotnet_diagnostic.IDE0010.severity = suggestion # Populate switch
520+
dotnet_diagnostic.IDE0021.severity = suggestion # Use expression body for constructor
521+
dotnet_diagnostic.IDE0046.severity = suggestion # If statement can be simplified
522+
dotnet_diagnostic.IDE0055.severity = none # Fix formatting
519523
dotnet_diagnostic.IDE0057.severity = none # Substring can be simplified
524+
dotnet_diagnostic.IDE0072.severity = suggestion # Populate switch
525+
dotnet_diagnostic.IDE0130.severity = suggestion # Namespace does not match folder structure
526+
dotnet_diagnostic.IDE0290.severity = none # Use primary constructor
527+
dotnet_diagnostic.IDE0305.severity = suggestion # Collection initialization can be simplified
520528

521529
dotnet_diagnostic.SA1010.severity = none #
522530

523531
dotnet_diagnostic.CA1054.severity = none # URI parameters should not be strings
532+
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)
524533
dotnet_diagnostic.CA1848.severity = none # For improved performance, use the LoggerMessage delegates instead of calling 'LoggerExtensions.LogTrace(ILogger, string, params object[])'
525534
dotnet_diagnostic.CA1859.severity = none #
526535
dotnet_diagnostic.CA1860.severity = none #
@@ -536,6 +545,7 @@ dotnet_diagnostic.S1172.severity = none # False positive
536545
dotnet_diagnostic.S2589.severity = none #
537546
dotnet_diagnostic.S2629.severity = none #
538547
dotnet_diagnostic.S3267.severity = none #
548+
dotnet_diagnostic.S3358.severity = none #
539549
dotnet_diagnostic.S3878.severity = none #
540550
dotnet_diagnostic.S4457.severity = none # Split this method into two, one handling parameters check and the other handling the asynchronous code
541551
dotnet_diagnostic.S6602.severity = none #

Directory.Build.props

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
<ImplicitUsings>enable</ImplicitUsings>
2121
<TargetFramework>net8.0</TargetFramework>
2222
<GenerateDocumentationFile>true</GenerateDocumentationFile>
23-
<NoWarn>1573,1591,1712,CA1014</NoWarn>
23+
<NoWarn>1573,1591,1712,CA1014,NU1903</NoWarn>
2424

2525
<!-- Used by code coverage -->
2626
<DebugType>full</DebugType>

src/Atc.CodingRules.AnalyzerProviders/Models/AnalyzerProviderBaseRuleData.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ public AnalyzerProviderBaseRuleData(string name)
1414
public string Name { get; set; } = string.Empty;
1515

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

1919
public string? ExceptionMessage { get; set; }
2020

src/Atc.CodingRules.Updater.CLI/Commands/DescriptionAttributes/SupportedProjectTargetTypeDescriptionAttribute.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ public override string Description
88
get
99
{
1010
var defaultValue = new OptionsFile().ProjectTarget;
11-
var values = Enum.GetNames(typeof(SupportedProjectTargetType))
11+
var values = Enum.GetNames<SupportedProjectTargetType>()
1212
.Select(enumValue => enumValue.Equals(defaultValue.ToString(), StringComparison.Ordinal)
1313
? $"{enumValue} (default)"
1414
: enumValue)

src/Atc.CodingRules.Updater.CLI/Commands/RunCommand.cs

+4-7
Original file line numberDiff line numberDiff line change
@@ -140,13 +140,10 @@ private static async Task<OptionsFile> GetOptionsFromFileAndUserArguments(
140140
buildFile = settings.BuildFile.Value;
141141
}
142142

143-
if (!string.IsNullOrEmpty(buildFile))
144-
{
145-
return buildFile.Contains(':', StringComparison.Ordinal)
143+
return !string.IsNullOrEmpty(buildFile)
144+
? buildFile.Contains(':', StringComparison.Ordinal)
146145
? new FileInfo(buildFile)
147-
: new FileInfo(Path.Combine(projectPath.FullName, buildFile));
148-
}
149-
150-
return null;
146+
: new FileInfo(Path.Combine(projectPath.FullName, buildFile))
147+
: null;
151148
}
152149
}

src/Atc.CodingRules.Updater.CLI/Commands/Settings/ProjectBaseCommandSettings.cs

+5-8
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,11 @@ public class ProjectBaseCommandSettings : BaseCommandSettings
1414
public override ValidationResult Validate()
1515
{
1616
var validationResult = base.Validate();
17-
if (!validationResult.Successful)
18-
{
19-
return validationResult;
20-
}
21-
22-
return string.IsNullOrEmpty(ProjectPath)
23-
? ValidationResult.Error("ProjectPath is missing.")
24-
: ValidationResult.Success();
17+
return !validationResult.Successful
18+
? validationResult
19+
: string.IsNullOrEmpty(ProjectPath)
20+
? ValidationResult.Error("ProjectPath is missing.")
21+
: ValidationResult.Success();
2522
}
2623

2724
internal string GetOptionsPath()

src/Atc.CodingRules.Updater.CLI/Models/Options/OptionsFolderMappings.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ namespace Atc.CodingRules.Updater.CLI.Models.Options;
33
public class OptionsFolderMappings
44
{
55
[SuppressMessage("Usage", "CA2227:Collection properties should be read only", Justification = "OK.")]
6-
public IList<string> Paths { get; set; } = new List<string>();
6+
public IList<string> Paths { get; set; } = [];
77

88
public override string ToString()
99
=> $"{nameof(Paths)}.Count: {Paths.Count}";

src/Atc.CodingRules.Updater.CLI/ProjectHelper.cs

+12-18
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,8 @@ is SupportedProjectTargetType.DotNetCore
3333
or SupportedProjectTargetType.DotNet5
3434
or SupportedProjectTargetType.DotNet6
3535
or SupportedProjectTargetType.DotNet7
36-
or SupportedProjectTargetType.DotNet8)
36+
or SupportedProjectTargetType.DotNet8
37+
or SupportedProjectTargetType.DotNet9)
3738
{
3839
HandleDirectoryBuildPropsFiles(logger, projectPath, options);
3940

@@ -140,24 +141,17 @@ private static ProjectFrameworkType DetermineProjectFrameworkType(
140141
Path.GetFileNameWithoutExtension(csProjFile.Name),
141142
StringComparison.OrdinalIgnoreCase));
142143

143-
if (optionsProjectFrameworkMapping is not null)
144+
projectFrameworkType = optionsProjectFrameworkMapping?.Type ?? projectType switch
144145
{
145-
projectFrameworkType = optionsProjectFrameworkMapping.Type;
146-
}
147-
else
148-
{
149-
projectFrameworkType = projectType switch
150-
{
151-
DotnetProjectType.AzureFunctionApp => ProjectFrameworkType.AzureFunctions,
152-
DotnetProjectType.BlazorServerApp or DotnetProjectType.BlazorWAsmApp => ProjectFrameworkType.Blazor,
153-
DotnetProjectType.CliApp => ProjectFrameworkType.Cli,
154-
DotnetProjectType.MauiApp => ProjectFrameworkType.Maui,
155-
DotnetProjectType.WinFormApp => ProjectFrameworkType.WinForms,
156-
DotnetProjectType.WpfApp or DotnetProjectType.WpfLibrary => ProjectFrameworkType.Wpf,
157-
DotnetProjectType.WebApi => ProjectFrameworkType.WebApi,
158-
_ => projectFrameworkType,
159-
};
160-
}
146+
DotnetProjectType.AzureFunctionApp => ProjectFrameworkType.AzureFunctions,
147+
DotnetProjectType.BlazorServerApp or DotnetProjectType.BlazorWAsmApp => ProjectFrameworkType.Blazor,
148+
DotnetProjectType.CliApp => ProjectFrameworkType.Cli,
149+
DotnetProjectType.MauiApp => ProjectFrameworkType.Maui,
150+
DotnetProjectType.WinFormApp => ProjectFrameworkType.WinForms,
151+
DotnetProjectType.WpfApp or DotnetProjectType.WpfLibrary => ProjectFrameworkType.Wpf,
152+
DotnetProjectType.WebApi => ProjectFrameworkType.WebApi,
153+
_ => projectFrameworkType,
154+
};
161155

162156
return projectFrameworkType;
163157
}

src/Atc.CodingRules.Updater/EditorConfigHelper.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -333,7 +333,7 @@ private static List<Tuple<string, List<string>>> ExtractContentCustomParts(
333333
}
334334

335335
workingOnCustomHeader = nextLine.Substring(CustomSectionHeaderPrefix.Length).Trim();
336-
workingOnCustomLines = new List<string>();
336+
workingOnCustomLines = [];
337337
}
338338
}
339339

src/Atc.CodingRules.Updater/Extensions/StringExtensions.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ namespace System;
44

55
public static class StringExtensions
66
{
7-
private static readonly string[] LineBreaks = { "\r\n", "\r", "\n" };
7+
private static readonly string[] LineBreaks = ["\r\n", "\r", "\n"];
88

99
public static string TrimEndForEmptyLines(
1010
this string value)
@@ -25,7 +25,7 @@ public static string TrimEndForEmptyLines(
2525
public static Collection<KeyValueItem> GetKeyValues(
2626
this string value)
2727
=> string.IsNullOrEmpty(value)
28-
? new Collection<KeyValueItem>()
28+
? []
2929
: value
3030
.Split(LineBreaks, StringSplitOptions.RemoveEmptyEntries)
3131
.GetKeyValues();

src/Atc.CodingRules.Updater/FileHelper.cs

+2-8
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
// ReSharper disable ConvertIfStatementToReturnStatement
21
namespace Atc.CodingRules.Updater;
32

43
public static class FileHelper
@@ -83,13 +82,8 @@ public static bool AreFilesEqual(
8382
return false;
8483
}
8584

86-
if (headerLinesA.Find(x => x.StartsWith("# Distribution", StringComparison.CurrentCultureIgnoreCase)) !=
87-
headerLinesB.Find(x => x.StartsWith("# Distribution", StringComparison.CurrentCultureIgnoreCase)))
88-
{
89-
return false;
90-
}
91-
92-
return true;
85+
return headerLinesA.Find(x => x.StartsWith("# Distribution", StringComparison.CurrentCultureIgnoreCase)) ==
86+
headerLinesB.Find(x => x.StartsWith("# Distribution", StringComparison.CurrentCultureIgnoreCase));
9387
}
9488

9589
public static bool ContainsEditorConfigFile(

src/Atc.CodingRules.Updater/ProjectSanityCheckHelper.cs

+1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ public static void CheckFiles(
1919
case SupportedProjectTargetType.DotNet6:
2020
case SupportedProjectTargetType.DotNet7:
2121
case SupportedProjectTargetType.DotNet8:
22+
case SupportedProjectTargetType.DotNet9:
2223
HasTargetFrameworkAndImplicitUsings(throwIf, logger, projectPath, "netcoreapp3.1");
2324
break;
2425
}

src/Atc.CodingRules.Updater/SupportedProjectTargetType.cs

+5-4
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,9 @@ namespace Atc.CodingRules.Updater;
33
public enum SupportedProjectTargetType
44
{
55
DotNetCore,
6-
DotNet5,
7-
DotNet6,
8-
DotNet7,
9-
DotNet8,
6+
DotNet5, // STS
7+
DotNet6, // LTS
8+
DotNet7, // STS
9+
DotNet8, // LTS
10+
DotNet9, // STS
1011
}

test/Atc.CodingRules.AnalyzerProviders.Tests/Providers/MicrosoftCompilerErrorsProviderTests.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,6 @@ public async Task CollectBaseRules(ProviderCollectingMode providerCollectingMode
2121
Assert.NotNull(actual.Name);
2222
Assert.Equal(MicrosoftCompilerErrorsProvider.Name, actual.Name);
2323
Assert.NotNull(actual.Rules);
24-
Assert.True(actual.Rules.Count >= 910);
24+
Assert.True(actual.Rules.Count >= 850);
2525
}
2626
}

0 commit comments

Comments
 (0)