From d1851373c410b20f0bda12f934ed7ac6abac0d82 Mon Sep 17 00:00:00 2001 From: David Kallesen Date: Wed, 29 Nov 2023 21:15:38 +0100 Subject: [PATCH] fix: Some CA rules --- src/Atc.DotNet/DotnetBuildHelper.cs | 6 +----- .../ParametersNamingMatchHelper.cs | 2 +- src/Atc/Extensions/BaseTypes/DecimalExtensions.cs | 4 ++-- src/Atc/Extensions/DataTableExtensions.cs | 6 +----- src/Atc/Extensions/StringExtensions.cs | 14 +++++++------- src/Atc/Helpers/CultureHelper.cs | 14 +++----------- src/Atc/Serialization/DynamicJson.cs | 2 +- 7 files changed, 16 insertions(+), 32 deletions(-) diff --git a/src/Atc.DotNet/DotnetBuildHelper.cs b/src/Atc.DotNet/DotnetBuildHelper.cs index 2741dd8c..1e739439 100644 --- a/src/Atc.DotNet/DotnetBuildHelper.cs +++ b/src/Atc.DotNet/DotnetBuildHelper.cs @@ -214,14 +214,10 @@ private static Dictionary ParseBuildOutputHelper( ? matchGroups[1].Value : keyPrefix + matchGroups[1].Value; - if (errors.ContainsKey(key)) + if (!errors.TryAdd(key, 1)) { errors[key] += 1; } - else - { - errors.Add(key, 1); - } } return errors; diff --git a/src/Atc.XUnit/Internal/AbstractSyntaxTree/ParametersNamingMatchHelper.cs b/src/Atc.XUnit/Internal/AbstractSyntaxTree/ParametersNamingMatchHelper.cs index 66585a27..f7309e73 100644 --- a/src/Atc.XUnit/Internal/AbstractSyntaxTree/ParametersNamingMatchHelper.cs +++ b/src/Atc.XUnit/Internal/AbstractSyntaxTree/ParametersNamingMatchHelper.cs @@ -185,7 +185,7 @@ private static bool ParameterCheckForMemberReferenceExpression(ParameterInfo par return true; } - if (astNodeTypeName.IndexOf("Constants", StringComparison.Ordinal) != -1) + if (astNodeTypeName.Contains("Constants", StringComparison.Ordinal)) { return true; } diff --git a/src/Atc/Extensions/BaseTypes/DecimalExtensions.cs b/src/Atc/Extensions/BaseTypes/DecimalExtensions.cs index a35b682d..c6afcadf 100644 --- a/src/Atc/Extensions/BaseTypes/DecimalExtensions.cs +++ b/src/Atc/Extensions/BaseTypes/DecimalExtensions.cs @@ -72,13 +72,13 @@ public static bool IsEqual(this decimal a, decimal b, int decimalPrecision) } sa = string.Format(CultureInfo.InvariantCulture, "{0}.{1}", saa[0], sad); - while (sa.EndsWith("0", StringComparison.Ordinal)) + while (sa.EndsWith('0')) { sa = sa.Substring(0, sa.Length - 1); } sb = string.Format(CultureInfo.InvariantCulture, "{0}.{1}", sab[0], sbd); - while (sb.EndsWith("0", StringComparison.Ordinal)) + while (sb.EndsWith('0')) { sb = sb.Substring(0, sb.Length - 1); } diff --git a/src/Atc/Extensions/DataTableExtensions.cs b/src/Atc/Extensions/DataTableExtensions.cs index 1d1b3722..69dd0387 100644 --- a/src/Atc/Extensions/DataTableExtensions.cs +++ b/src/Atc/Extensions/DataTableExtensions.cs @@ -93,14 +93,10 @@ from DataRow dr in dataTable.Rows select dr[countOnColumn].ToString()) { - if (list.ContainsKey(key)) + if (!list.TryAdd(key, 1)) { list[key] = list[key] + 1; } - else - { - list.Add(key, 1); - } } return list; diff --git a/src/Atc/Extensions/StringExtensions.cs b/src/Atc/Extensions/StringExtensions.cs index a1a2f40a..b999b631 100644 --- a/src/Atc/Extensions/StringExtensions.cs +++ b/src/Atc/Extensions/StringExtensions.cs @@ -1325,13 +1325,13 @@ public static string TrimSpecial(this string value) } value = value.Trim(); - while (value.IndexOf("\t", StringComparison.Ordinal) != -1) + while (value.Contains('\t', StringComparison.Ordinal)) { - value = value.Replace("\t", " ", StringComparison.Ordinal); + value = value.Replace('\t', ' '); } var lengthBefore = value.Length; - while (value.IndexOf("\n ", StringComparison.Ordinal) != -1) + while (value.Contains("\n ", StringComparison.Ordinal)) { value = value.Replace("\n ", "\n", StringComparison.Ordinal); if (lengthBefore == value.Length) @@ -1343,7 +1343,7 @@ public static string TrimSpecial(this string value) } lengthBefore = value.Length; - while (value.IndexOf("\n\n", StringComparison.Ordinal) != -1) + while (value.Contains("\n\n", StringComparison.Ordinal)) { value = value.Replace("\n\n", "\n", StringComparison.Ordinal); if (lengthBefore == value.Length) @@ -1355,7 +1355,7 @@ public static string TrimSpecial(this string value) } lengthBefore = value.Length; - while (value.IndexOf("\r\n\r\n", StringComparison.Ordinal) != -1) + while (value.Contains("\r\n\r\n", StringComparison.Ordinal)) { value = value.Replace("\r\n\r\n", "\r\n", StringComparison.Ordinal); if (lengthBefore == value.Length) @@ -1366,7 +1366,7 @@ public static string TrimSpecial(this string value) lengthBefore = value.Length; } - while (value.IndexOf("..", StringComparison.Ordinal) != -1) + while (value.Contains("..", StringComparison.Ordinal)) { value = value.Replace("..", ".", StringComparison.Ordinal); } @@ -1405,7 +1405,7 @@ public static string TrimExtended(this string value) } var s = value.Trim(); - while (s.IndexOf(" ", StringComparison.Ordinal) != -1) + while (s.Contains(" ", StringComparison.Ordinal)) { s = s.Replace(" ", " ", StringComparison.Ordinal); } diff --git a/src/Atc/Helpers/CultureHelper.cs b/src/Atc/Helpers/CultureHelper.cs index 867a7c4b..0090e066 100644 --- a/src/Atc/Helpers/CultureHelper.cs +++ b/src/Atc/Helpers/CultureHelper.cs @@ -446,7 +446,7 @@ public static List GetCulturesByLanguageCodeA2( break; } - case 5 when value.IndexOf('-', StringComparison.Ordinal) != -1: + case 5 when value.Contains('-', StringComparison.Ordinal): { culture = cultures.Find(x => x.Name.Equals(value, StringComparison.OrdinalIgnoreCase)); if (culture is not null) @@ -631,14 +631,10 @@ public static Dictionary GetCountryNames( continue; } - if (countryDisplayNameCount.ContainsKey(culture.CountryDisplayName)) + if (!countryDisplayNameCount.TryAdd(culture.CountryDisplayName, 1)) { countryDisplayNameCount[culture.CountryDisplayName]++; } - else - { - countryDisplayNameCount.Add(culture.CountryDisplayName, 1); - } } foreach (var culture in cultures.OrderBy(x => x.CountryDisplayName, StringComparer.Ordinal)) @@ -768,14 +764,10 @@ public static Dictionary GetLanguageNames( continue; } - if (languageDisplayNameCount.ContainsKey(culture.LanguageDisplayName)) + if (!languageDisplayNameCount.TryAdd(culture.LanguageDisplayName, 1)) { languageDisplayNameCount[culture.LanguageDisplayName]++; } - else - { - languageDisplayNameCount.Add(culture.LanguageDisplayName, 1); - } } foreach (var culture in cultures.OrderBy(x => x.LanguageDisplayName, StringComparer.Ordinal)) diff --git a/src/Atc/Serialization/DynamicJson.cs b/src/Atc/Serialization/DynamicJson.cs index 92324780..c3c2d620 100644 --- a/src/Atc/Serialization/DynamicJson.cs +++ b/src/Atc/Serialization/DynamicJson.cs @@ -323,7 +323,7 @@ private static (bool IsSucceeded, string? ErrorMessage) SetListValue( ErrorMessage: null); } - private (bool IsSucceeded, string? ErrorMessage) RemovePathRecursive( + private static (bool IsSucceeded, string? ErrorMessage) RemovePathRecursive( IDictionary currentDict, IReadOnlyList segments, int index)