From 4835666c4aef3446e856fe444634bf8569b896de Mon Sep 17 00:00:00 2001 From: Mark Ridgwell Date: Fri, 19 Apr 2024 15:32:50 +0100 Subject: [PATCH] Fixed code analysis issues --- src/ChangeLog.sln.DotSettings | 3 +++ .../Credfeto.ChangeLog.Cmd.csproj | 2 ++ .../Credfeto.ChangeLog.Tests.csproj | 1 + src/Credfeto.ChangeLog/ChangeLogChecker.cs | 8 +++++--- src/Credfeto.ChangeLog/ChangeLogUpdater.cs | 18 ++++++++++-------- .../Credfeto.ChangeLog.csproj | 1 + 6 files changed, 22 insertions(+), 11 deletions(-) diff --git a/src/ChangeLog.sln.DotSettings b/src/ChangeLog.sln.DotSettings index aabe8435..a259937b 100644 --- a/src/ChangeLog.sln.DotSettings +++ b/src/ChangeLog.sln.DotSettings @@ -374,6 +374,8 @@ False <Policy Inspect="True" Prefix="" Suffix="" Style="AA_BB" /> <Policy Inspect="True" Prefix="" Suffix="" Style="AA_BB" /> + <Policy><Descriptor Staticness="Any" AccessRightKinds="Private" Description="Constant fields (private)"><ElementKinds><Kind Name="CONSTANT_FIELD" /></ElementKinds></Descriptor><Policy Inspect="True" Prefix="" Suffix="" Style="AA_BB" /></Policy> + <Policy><Descriptor Staticness="Any" AccessRightKinds="Any" Description="Enum members"><ElementKinds><Kind Name="ENUM_MEMBER" /></ElementKinds></Descriptor><Policy Inspect="True" Prefix="" Suffix="" Style="AA_BB" /></Policy> <Policy Inspect="True" Prefix="" Suffix="" Style="aaBb" /> <Policy Inspect="True" Prefix="" Suffix="" Style="aaBb" /> <Policy Inspect="True" Prefix="" Suffix="" Style="aaBb" /> @@ -424,6 +426,7 @@ True True True + True True True True diff --git a/src/Credfeto.ChangeLog.Cmd/Credfeto.ChangeLog.Cmd.csproj b/src/Credfeto.ChangeLog.Cmd/Credfeto.ChangeLog.Cmd.csproj index 2a631d4c..26eb9b80 100644 --- a/src/Credfeto.ChangeLog.Cmd/Credfeto.ChangeLog.Cmd.csproj +++ b/src/Credfeto.ChangeLog.Cmd/Credfeto.ChangeLog.Cmd.csproj @@ -4,6 +4,8 @@ true true true + true + true strict;flow-analysis true false diff --git a/src/Credfeto.ChangeLog.Tests/Credfeto.ChangeLog.Tests.csproj b/src/Credfeto.ChangeLog.Tests/Credfeto.ChangeLog.Tests.csproj index 3de3746c..2f9fbeba 100644 --- a/src/Credfeto.ChangeLog.Tests/Credfeto.ChangeLog.Tests.csproj +++ b/src/Credfeto.ChangeLog.Tests/Credfeto.ChangeLog.Tests.csproj @@ -27,6 +27,7 @@ true true + true latest diff --git a/src/Credfeto.ChangeLog/ChangeLogChecker.cs b/src/Credfeto.ChangeLog/ChangeLogChecker.cs index 8e0e59a1..4fcdee3b 100644 --- a/src/Credfeto.ChangeLog/ChangeLogChecker.cs +++ b/src/Credfeto.ChangeLog/ChangeLogChecker.cs @@ -121,12 +121,14 @@ private static bool CheckForChangesAfterFirstRelease(PatchEntryChanges change, i private static string ExtractPatchDetails(string patch) { Console.WriteLine(patch); - List lines = patch.Split('\n') - .ToList(); + List lines = + [ + ..patch.Split('\n') + ]; RemoveLastLineIfBlank(lines); - int lastHunk = lines.FindLastIndex(x => CommonRegex.GitHunkPosition.IsMatch(x)); + int lastHunk = lines.FindLastIndex(CommonRegex.GitHunkPosition.IsMatch); if (lastHunk != -1) { diff --git a/src/Credfeto.ChangeLog/ChangeLogUpdater.cs b/src/Credfeto.ChangeLog/ChangeLogUpdater.cs index b403952f..9ffd582c 100644 --- a/src/Credfeto.ChangeLog/ChangeLogUpdater.cs +++ b/src/Credfeto.ChangeLog/ChangeLogUpdater.cs @@ -35,14 +35,14 @@ public static async Task RemoveEntryAsync(string changeLogFileName, string type, private static async Task ReadChangeLogAsync(string changeLogFileName, CancellationToken cancellationToken) { - if (!File.Exists(changeLogFileName)) + if (File.Exists(changeLogFileName)) { - await CreateEmptyAsync(changeLogFileName: changeLogFileName, cancellationToken: cancellationToken); - - return TemplateFile.Initial; + return await File.ReadAllTextAsync(path: changeLogFileName, encoding: Encoding.UTF8, cancellationToken: cancellationToken); } - return await File.ReadAllTextAsync(path: changeLogFileName, encoding: Encoding.UTF8, cancellationToken: cancellationToken); + await CreateEmptyAsync(changeLogFileName: changeLogFileName, cancellationToken: cancellationToken); + + return TemplateFile.Initial; } public static string AddEntry(string changeLog, string type, string message) @@ -68,9 +68,11 @@ private static string AddEntryCommon(string changeLog, string type, string messa private static List ChangeLogAsLines(string changeLog) { - return EnsureChangelog(changeLog) - .SplitToLines() - .ToList(); + return + [ + .. EnsureChangelog(changeLog) + .SplitToLines() + ]; } public static string RemoveEntry(string changeLog, string type, string message) diff --git a/src/Credfeto.ChangeLog/Credfeto.ChangeLog.csproj b/src/Credfeto.ChangeLog/Credfeto.ChangeLog.csproj index f5f23706..45c4fd03 100644 --- a/src/Credfeto.ChangeLog/Credfeto.ChangeLog.csproj +++ b/src/Credfeto.ChangeLog/Credfeto.ChangeLog.csproj @@ -29,6 +29,7 @@ true true + true latest