diff --git a/.editorconfig b/.editorconfig index dd058616..42c03ba5 100644 --- a/.editorconfig +++ b/.editorconfig @@ -22,6 +22,17 @@ charset = utf-8-bom # .NET Coding Conventions # ############################### [*.{cs,vb}] + +# Enable style analyzers +dotnet_analyzer_diagnostic.category-Style.severity = warning + +dotnet_diagnostic.IDE0005.severity = silent +dotnet_diagnostic.IDE0045.severity = silent +dotnet_diagnostic.IDE0046.severity = silent +dotnet_diagnostic.IDE0058.severity = silent +dotnet_diagnostic.IDE0072.severity = silent +dotnet_diagnostic.IDE0079.severity = silent + # Organize usings dotnet_sort_system_directives_first = true @@ -81,6 +92,7 @@ csharp_style_expression_bodied_operators = false:none csharp_style_expression_bodied_properties = true:none csharp_style_expression_bodied_indexers = true:none csharp_style_expression_bodied_accessors = true:none +csharp_style_expression_bodied_local_functions = when_on_single_line # Pattern matching preferences csharp_style_pattern_matching_over_is_with_cast_check = true:suggestion diff --git a/Directory.Build.props b/Directory.Build.props index 714ebc35..a3f8502d 100644 --- a/Directory.Build.props +++ b/Directory.Build.props @@ -4,7 +4,7 @@ $(AllowedOutputExtensionsInPackageBuildOutputFolder);.pdb - AllEnabledByDefault + All $(MSBuildThisFileDirectory)ProjectEuler.snk martin_costello $(MSBuildThisFileDirectory)ProjectEuler.ruleset @@ -12,6 +12,7 @@ Martin Costello (c) 2015-$([System.DateTime]::UtcNow.ToString(yyyy)) true true + true false false true @@ -20,7 +21,6 @@ true en-US $(NoWarn);CS1591 - $(NoWarn);SA0001 enable Apache-2.0 https://github.com/martincostello/project-euler @@ -39,6 +39,10 @@ 8.0.0 + + true + $(NoWarn);419;1570;1573;1574;1584;1591;SA0001;SA1602 + diff --git a/Directory.Packages.props b/Directory.Packages.props index 83cf802e..a4e103aa 100644 --- a/Directory.Packages.props +++ b/Directory.Packages.props @@ -1,14 +1,14 @@ + + + + - - - - diff --git a/ProjectEuler.sln b/ProjectEuler.sln index c257ec10..1fd8be39 100644 --- a/ProjectEuler.sln +++ b/ProjectEuler.sln @@ -41,7 +41,8 @@ EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "workflows", "workflows", "{AD52E729-49AF-4F5C-9611-DD51EFED3727}" ProjectSection(SolutionItems) = preProject .github\workflows\build.yml = .github\workflows\build.yml - .github\workflows\update-dotnet-sdk.yml = .github\workflows\update-dotnet-sdk.yml + .github\workflows\dependency-review.yml = .github\workflows\dependency-review.yml + .github\workflows\lint.yml = .github\workflows\lint.yml EndProjectSection EndProject Global diff --git a/src/ProjectEuler/Puzzles/MaximumPathPuzzle.cs b/src/ProjectEuler/Puzzles/MaximumPathPuzzle.cs index 4ed99d88..6c277c60 100644 --- a/src/ProjectEuler/Puzzles/MaximumPathPuzzle.cs +++ b/src/ProjectEuler/Puzzles/MaximumPathPuzzle.cs @@ -83,7 +83,7 @@ protected int[][] LoadTriangle() lines++; } - return [..triangle]; + return [.. triangle]; } /// diff --git a/src/ProjectEuler/Puzzles/Puzzle054.cs b/src/ProjectEuler/Puzzles/Puzzle054.cs index d1d7ec26..095066a5 100644 --- a/src/ProjectEuler/Puzzles/Puzzle054.cs +++ b/src/ProjectEuler/Puzzles/Puzzle054.cs @@ -24,11 +24,11 @@ internal static bool IsFirstPlayerTheWinner(string hand) string[] player1 = cards[..5]; string[] player2 = cards[5..]; - player1 = [..player1.OrderBy(GetCardValue)]; - player2 = [..player2.OrderBy(GetCardValue)]; + player1 = [.. player1.OrderBy(GetCardValue)]; + player2 = [.. player2.OrderBy(GetCardValue)]; - var predicates = new IsHandPredicate[] - { + IsHandPredicate[] predicates = + [ IsRoyalFlush, IsStraightFlush, IsFourOfAKind, @@ -38,7 +38,7 @@ internal static bool IsFirstPlayerTheWinner(string hand) IsThreeOfAKind, IsTwoPair, IsPair, - }; + ]; foreach (var predicate in predicates) { diff --git a/src/ProjectEuler/Puzzles/Puzzle092.cs b/src/ProjectEuler/Puzzles/Puzzle092.cs index 53f5327d..f94e68c8 100644 --- a/src/ProjectEuler/Puzzles/Puzzle092.cs +++ b/src/ProjectEuler/Puzzles/Puzzle092.cs @@ -23,7 +23,7 @@ protected override int SolveCore(string[] args) { int value = i; - while (value != 1 && value != Target) + while (value is not 1 and not Target) { value = Maths.Digits(value).Sum((p) => p * p); } diff --git a/tests/ProjectEuler.Tests/MathsTests.cs b/tests/ProjectEuler.Tests/MathsTests.cs index 881c2fca..f76a2678 100644 --- a/tests/ProjectEuler.Tests/MathsTests.cs +++ b/tests/ProjectEuler.Tests/MathsTests.cs @@ -392,7 +392,7 @@ public static void Maths_Permutations_Returns_Correct_Value_2() Assert.Equal(new[] { "a", "b" }, actual[0]); Assert.Equal(new[] { "b", "a" }, actual[1]); - collection = new[] { "b", "a" }; + collection = ["b", "a"]; // Act actual = Maths.Permutations(collection) diff --git a/tests/ProjectEuler.Tests/ProjectEuler.Tests.csproj b/tests/ProjectEuler.Tests/ProjectEuler.Tests.csproj index 5f8a62bb..540684cc 100644 --- a/tests/ProjectEuler.Tests/ProjectEuler.Tests.csproj +++ b/tests/ProjectEuler.Tests/ProjectEuler.Tests.csproj @@ -14,7 +14,7 @@ - + diff --git a/tests/ProjectEuler.Tests/PuzzleTests.cs b/tests/ProjectEuler.Tests/PuzzleTests.cs index d867b71c..40344dbd 100644 --- a/tests/ProjectEuler.Tests/PuzzleTests.cs +++ b/tests/ProjectEuler.Tests/PuzzleTests.cs @@ -43,7 +43,7 @@ public static void Puzzles_Have_Questions() var puzzleTypes = puzzleType.GetTypeInfo().Assembly .GetTypes() .Where((p) => !p.GetTypeInfo().IsAbstract) - .Where((p) => puzzleType.IsAssignableFrom(p)) + .Where(puzzleType.IsAssignableFrom) .ToList(); Assert.NotEmpty(puzzleTypes);