Skip to content

Commit e7d31bc

Browse files
author
Per Kops
committed
feat: change code to conform to coding-rules after update to dotnet 8
1 parent 90be3fc commit e7d31bc

File tree

7 files changed

+52
-60
lines changed

7 files changed

+52
-60
lines changed

src/Atc.CodingRules.AnalyzerProviders/Providers/MicrosoftCodeAnalysisNetAnalyzersProvider.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ protected override async Task ReCollect(
5858
var sa = aHrefNode.InnerText.Split(":");
5959
if (sa.Length != 2)
6060
{
61-
sa = aHrefNode.InnerText.Split(new[] { ' ' }, 2);
61+
sa = aHrefNode.InnerText.Split([' '], 2);
6262
if (sa.Length != 2)
6363
{
6464
continue;

src/Atc.CodingRules.Updater.CLI/Extensions/CommandAppExtensions.cs

Lines changed: 34 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -21,35 +21,33 @@ public static void ConfigureCommands(this CommandApp<RootCommand> app)
2121
private static void ConfigureRunCommand(IConfigurator config)
2222
=> config.AddCommand<RunCommand>(NameCommandConstants.Run)
2323
.WithDescription("Update the project folder with ATC coding rules and configurations")
24-
.WithExample(new[] { ".", CreateEquivalentToRun(8) })
25-
.WithExample(new[] { NameCommandConstants.Run, ".", CreateEquivalentToRun(4), })
26-
.WithExample(new[] { NameCommandConstants.Run, CreateArgumentProjectPathWithDot(), CreateEquivalentToRun(1) })
27-
.WithExample(new[] { NameCommandConstants.Run, CreateArgumentProjectPathWithTestFolder() })
24+
.WithExample([".", CreateEquivalentToRun(8)])
25+
.WithExample([NameCommandConstants.Run, ".", CreateEquivalentToRun(4)])
26+
.WithExample([NameCommandConstants.Run, CreateArgumentProjectPathWithDot(), CreateEquivalentToRun(1)])
27+
.WithExample([NameCommandConstants.Run, CreateArgumentProjectPathWithTestFolder()])
2828
.WithExample(
29-
new[]
30-
{
31-
NameCommandConstants.Run,
32-
CreateArgumentProjectPathWithTestFolder(),
33-
CreateArgumentProjectTarget(SupportedProjectTargetType.DotNetCore),
34-
ArgumentCommandConstants.LongUseTemporarySuppressions,
35-
ArgumentCommandConstants.LongOrganizationName, "MyCompany",
36-
ArgumentCommandConstants.LongRepositoryName, "MyRepo",
37-
CommandConstants.ArgumentShortVerbose,
38-
});
29+
[
30+
NameCommandConstants.Run,
31+
CreateArgumentProjectPathWithTestFolder(),
32+
CreateArgumentProjectTarget(SupportedProjectTargetType.DotNetCore),
33+
ArgumentCommandConstants.LongUseTemporarySuppressions,
34+
ArgumentCommandConstants.LongOrganizationName, "MyCompany",
35+
ArgumentCommandConstants.LongRepositoryName, "MyRepo",
36+
CommandConstants.ArgumentShortVerbose
37+
]);
3938

4039
private static void ConfigureSanityCheckCommand(IConfigurator config)
4140
=> config.AddCommand<SanityCheckCommand>(NameCommandConstants.SanityCheck)
4241
.WithDescription("Sanity check the project files")
43-
.WithExample(new[] { NameCommandConstants.SanityCheck, ".", CreateEquivalentToSanityCheck(8) })
44-
.WithExample(new[] { NameCommandConstants.SanityCheck, CreateArgumentProjectPathWithTestFolder() })
42+
.WithExample([NameCommandConstants.SanityCheck, ".", CreateEquivalentToSanityCheck(8)])
43+
.WithExample([NameCommandConstants.SanityCheck, CreateArgumentProjectPathWithTestFolder()])
4544
.WithExample(
46-
new[]
47-
{
48-
NameCommandConstants.SanityCheck,
45+
[
46+
NameCommandConstants.SanityCheck,
4947
CreateArgumentProjectPathWithTestFolder(),
5048
CreateArgumentProjectTarget(SupportedProjectTargetType.DotNetCore),
51-
CommandConstants.ArgumentShortVerbose,
52-
});
49+
CommandConstants.ArgumentShortVerbose
50+
]);
5351

5452
private static Action<IConfigurator<CommandSettings>> ConfigureOptionsFileCommands()
5553
=> node =>
@@ -59,15 +57,15 @@ private static Action<IConfigurator<CommandSettings>> ConfigureOptionsFileComman
5957
node
6058
.AddCommand<OptionsFileCreateCommand>(CommandConstants.NameOptionsFileCreate)
6159
.WithDescription("Create default options file 'atc-coding-rules-updater.json' if it doesn't exist")
62-
.WithExample(new[] { CreateArgumentCommandsOptionsFileWithCreate(), ".", CreateEquivalentToOptionsFileCreate(6), })
63-
.WithExample(new[] { CreateArgumentCommandsOptionsFileWithCreate(), CreateArgumentProjectPathWithDot(), CreateEquivalentToOptionsFileCreate(3), })
64-
.WithExample(new[] { CreateArgumentCommandsOptionsFileWithCreate(), CreateArgumentProjectPathWithTestFolder(), });
60+
.WithExample([CreateArgumentCommandsOptionsFileWithCreate(), ".", CreateEquivalentToOptionsFileCreate(6)])
61+
.WithExample([CreateArgumentCommandsOptionsFileWithCreate(), CreateArgumentProjectPathWithDot(), CreateEquivalentToOptionsFileCreate(3)])
62+
.WithExample([CreateArgumentCommandsOptionsFileWithCreate(), CreateArgumentProjectPathWithTestFolder()]);
6563

6664
node
6765
.AddCommand<OptionsFileValidateCommand>(CommandConstants.NameOptionsFileValidate)
6866
.WithDescription("Validate the options file 'atc-coding-rules-updater.json'")
69-
.WithExample(new[] { CreateArgumentCommandsOptionsFileWithValidate(), ".", CreateEquivalentToOptionsFileValidate(4), })
70-
.WithExample(new[] { CreateArgumentCommandsOptionsFileWithValidate(), CreateArgumentProjectPathWithTestFolder() });
67+
.WithExample([CreateArgumentCommandsOptionsFileWithValidate(), ".", CreateEquivalentToOptionsFileValidate(4)])
68+
.WithExample([CreateArgumentCommandsOptionsFileWithValidate(), CreateArgumentProjectPathWithTestFolder()]);
7169
};
7270

7371
private static Action<IConfigurator<CommandSettings>> ConfigureAnalyzerProvidersCommands()
@@ -78,22 +76,21 @@ private static Action<IConfigurator<CommandSettings>> ConfigureAnalyzerProviders
7876
node
7977
.AddCommand<AnalyzerProvidersCollectCommand>(NameCommandConstants.AnalyzerProvidersCollect)
8078
.WithDescription("Collect base rules metadata from all Analyzer providers")
81-
.WithExample(new[] { CreateArgumentCommandsAnalyzerProvidersWithCollect(), ".", CreateEquivalentToAnalyzerProvidersCollect(6), })
82-
.WithExample(new[] { CreateArgumentCommandsAnalyzerProvidersWithCollect(), CreateArgumentProjectPathWithDot(), CreateEquivalentToAnalyzerProvidersCollect(3) })
83-
.WithExample(new[] { CreateArgumentCommandsAnalyzerProvidersWithCollect(), CreateArgumentProjectPathWithTestFolder() })
79+
.WithExample([CreateArgumentCommandsAnalyzerProvidersWithCollect(), ".", CreateEquivalentToAnalyzerProvidersCollect(6)])
80+
.WithExample([CreateArgumentCommandsAnalyzerProvidersWithCollect(), CreateArgumentProjectPathWithDot(), CreateEquivalentToAnalyzerProvidersCollect(3)])
81+
.WithExample([CreateArgumentCommandsAnalyzerProvidersWithCollect(), CreateArgumentProjectPathWithTestFolder()])
8482
.WithExample(
85-
new[]
86-
{
87-
CreateArgumentCommandsAnalyzerProvidersWithCollect(),
88-
CreateArgumentProjectPathWithTestFolder(),
89-
CreateArgumentFetchMode(ProviderCollectingMode.ReCollect),
90-
CommandConstants.ArgumentShortVerbose,
91-
});
83+
[
84+
CreateArgumentCommandsAnalyzerProvidersWithCollect(),
85+
CreateArgumentProjectPathWithTestFolder(),
86+
CreateArgumentFetchMode(ProviderCollectingMode.ReCollect),
87+
CommandConstants.ArgumentShortVerbose
88+
]);
9289

9390
node
9491
.AddCommand<AnalyzerProvidersCacheCleanupCommand>(NameCommandConstants.AnalyzerProvidersCleanupCache)
9592
.WithDescription("Cleanup cache from Analyzer providers")
96-
.WithExample(new[] { CreateArgumentCommandsAnalyzerProvidersWithCleanupCache() });
93+
.WithExample([CreateArgumentCommandsAnalyzerProvidersWithCleanupCache()]);
9794
};
9895

9996
private static string CreateArgumentProjectPathWithDot()

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ private static bool TryResolvePathIfNeeded(
6262
var di = new DirectoryInfo(orgPath);
6363
if (di.FullName.Contains("Atc.CodingRules.Updater.CLI", StringComparison.Ordinal))
6464
{
65-
if (orgPath.IndexOfAny(new[] { '.', '/', '\\' }) == -1)
65+
if (orgPath.IndexOfAny(['.', '/', '\\']) == -1)
6666
{
6767
newPath = Path.Combine(projectPath.FullName, orgPath);
6868
return true;
@@ -75,15 +75,15 @@ private static bool TryResolvePathIfNeeded(
7575
return true;
7676
}
7777

78-
if (orgPath.IndexOfAny(new[] { '/', '\\' }) != -1)
78+
if (orgPath.IndexOfAny(['/', '\\']) != -1)
7979
{
8080
var s = orgPath.Replace("/", "\\", StringComparison.Ordinal);
8181
newPath = Path.Combine(projectPath.FullName, s);
8282
return true;
8383
}
8484
}
8585

86-
if (orgPath.StartsWith("\\", StringComparison.Ordinal))
86+
if (orgPath.StartsWith('\\'))
8787
{
8888
var s = orgPath.Substring(1).Replace("/", "\\", StringComparison.Ordinal);
8989
newPath = Path.Combine(projectPath.FullName, s);

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

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ private static async Task HandleTemporarySuppressions(
204204
var errorTypes = buildResult
205205
.Where(x => x.Key.StartsWith("MSB", StringComparison.Ordinal))
206206
.Select(x => x.Key)
207-
.OrderBy(x => x)
207+
.OrderBy(x => x, StringComparer.Ordinal)
208208
.ToList();
209209

210210
logger.LogWarning($" MSB-errors ({string.Join(',', errorTypes)}) was found, please correct them manually first and try again.");
@@ -214,7 +214,7 @@ private static async Task HandleTemporarySuppressions(
214214
var errorTypes = buildResult
215215
.Where(x => x.Key.StartsWith("NU", StringComparison.Ordinal))
216216
.Select(x => x.Key)
217-
.OrderBy(x => x)
217+
.OrderBy(x => x, StringComparer.Ordinal)
218218
.ToList();
219219

220220
logger.LogWarning($" NU-errors ({string.Join(',', errorTypes)}) was found, please correct them manually first and try again.");
@@ -288,14 +288,10 @@ private static async Task<bool> BuildAndCollectErrorsAgainAndUpdateFile(
288288
hasFoundNewErrors = buildResultNextRun.Count > 0;
289289
foreach (var (key, value) in buildResultNextRun)
290290
{
291-
if (buildResult.ContainsKey(key))
291+
if (!buildResult.TryAdd(key, value))
292292
{
293293
buildResult[key] += value;
294294
}
295-
else
296-
{
297-
buildResult.Add(key, value);
298-
}
299295
}
300296
}
301297
catch (DataException ex)
@@ -332,7 +328,7 @@ private static void DeleteSuppressionsFileInTempPath(
332328
}
333329
}
334330

335-
private static Task CreateSuppressionsFileInTempPath(
331+
private static async Task CreateSuppressionsFileInTempPath(
336332
ILogger logger,
337333
DirectoryInfo temporarySuppressionsPath,
338334
bool temporarySuppressionAsExcel,
@@ -371,15 +367,14 @@ private static Task CreateSuppressionsFileInTempPath(
371367
worksheet.View.FreezePanes(2, 1);
372368

373369
logger.LogDebug($"{EmojisConstants.FileUpdated} {temporarySuppressionsFile} updated");
374-
375-
return excelPackage.SaveAsAsync(new FileInfo(temporarySuppressionsFile));
370+
await excelPackage.SaveAsAsync(new FileInfo(temporarySuppressionsFile));
376371
}
377372

378373
var suppressionsText = CreateSuppressionsText(suppressionLinesPrAnalyzer);
379374

380375
logger.LogDebug($"{EmojisConstants.FileUpdated} {temporarySuppressionsFile} updated");
381376

382-
return Helpers.FileHelper.WriteAllTextAsync(new FileInfo(temporarySuppressionsFile), suppressionsText);
377+
await Helpers.FileHelper.WriteAllTextAsync(new FileInfo(temporarySuppressionsFile), suppressionsText);
383378
}
384379

385380
private static int AddSuppressionLinesToWorksheet(
@@ -476,7 +471,7 @@ private static List<Tuple<string, List<string>>> GetSuppressionLines(
476471
var groupedSuppressionLines = suppressionLines
477472
.GroupBy(x => x.Item1, StringComparer.Ordinal)
478473
.Select(group => new { AnalyzerName = group.Key, Values = group.Select(x => x.Item2).ToList() })
479-
.OrderBy(x => x.AnalyzerName)
474+
.OrderBy(x => x.AnalyzerName, StringComparer.Ordinal)
480475
.ToList();
481476

482477
return groupedSuppressionLines.Select(x => Tuple.Create(x.AnalyzerName, x.Values)).ToList();
@@ -488,7 +483,7 @@ private static void HandleSuppressionLinesForKnownAnalyzerRules(
488483
ICollection<Tuple<string, string>> suppressionLines,
489484
ICollection<string> handledCodes)
490485
{
491-
foreach (var (code, count) in buildResult.OrderBy(x => x.Key))
486+
foreach (var (code, count) in buildResult.OrderBy(x => x.Key, StringComparer.Ordinal))
492487
{
493488
foreach (var analyzerProvider in analyzerProviderBaseRules)
494489
{
@@ -511,7 +506,7 @@ private static void HandleSuppressionLinesForUnknownAnalyzerRules(
511506
ICollection<Tuple<string, string>> suppressionLines,
512507
ICollection<string> handledCodes)
513508
{
514-
foreach (var (code, count) in buildResult.OrderBy(x => x.Key))
509+
foreach (var (code, count) in buildResult.OrderBy(x => x.Key, StringComparer.Ordinal))
515510
{
516511
if (handledCodes.Contains(code, StringComparer.Ordinal))
517512
{

src/Atc.CodingRules.Updater/DirectoryBuildPropsHelper.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ public static bool HasFileInsertPlaceholderElement(
9999

100100
var fileContent = FileHelper.ReadAllText(file);
101101
var searchText = $"<{elementName}><!-- {elementValue} --></{elementName}>";
102-
return fileContent.IndexOf(searchText, StringComparison.Ordinal) != -1;
102+
return fileContent.Contains(searchText, StringComparison.Ordinal);
103103
}
104104

105105
public static void UpdateFileInsertPlaceholderElement(
@@ -119,7 +119,7 @@ public static void UpdateFileInsertPlaceholderElement(
119119

120120
var fileContent = FileHelper.ReadAllText(file);
121121
var searchText = $"<{elementName}><!-- {elementValue} --></{elementName}>";
122-
if (fileContent.IndexOf(searchText, StringComparison.Ordinal) != -1)
122+
if (fileContent.Contains(searchText, StringComparison.Ordinal))
123123
{
124124
fileContent = fileContent.Replace(
125125
searchText,

src/Atc.CodingRules.Updater/FileHelper.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ public static Collection<FileInfo> SearchAllForElement(
3131
searchText = $"<{elementName}>{elementValue}</{elementName}>";
3232
}
3333

34-
if (fileContent.IndexOf(searchText, stringComparison) != -1)
34+
if (fileContent.Contains(searchText, stringComparison))
3535
{
3636
result.Add(new FileInfo(file));
3737
}

src/Atc.CodingRules.Updater/ProjectSanityCheckHelper.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,12 @@ public static void CheckFiles(
1414
switch (projectTarget)
1515
{
1616
case SupportedProjectTargetType.DotNet5:
17-
HasEnableNetAnalyzers(throwIf, logger, projectPath, projectTarget);
17+
HasEnableNetAnalyzers(throwIf, logger, projectPath, projectTarget); // TODO: XXX
1818
break;
1919
case SupportedProjectTargetType.DotNet6:
2020
case SupportedProjectTargetType.DotNet7:
2121
case SupportedProjectTargetType.DotNet8:
22-
HasTargetFrameworkAndImplicitUsings(throwIf, logger, projectPath, "netcoreapp3.1");
22+
HasTargetFrameworkAndImplicitUsings(throwIf, logger, projectPath, "netcoreapp3.1"); // TODO: XXX
2323
break;
2424
}
2525
}

0 commit comments

Comments
 (0)