From 761f67900453401d0eec7bae5fcb49d47b8661a4 Mon Sep 17 00:00:00 2001 From: Chris Dahlberg Date: Sun, 4 Aug 2024 17:25:07 -0500 Subject: [PATCH 1/3] Updated test-related dependencies and resolved new build warnings. --- Build.ps1 | 3 +- .../CodeTiger.CodeAnalysis.Vsix.csproj | 2 +- CodeTiger.CodeAnalysis.Vsix/app.config | 39 ----- .../CodeTiger.CodeAnalysis.csproj | 7 +- ...sts.CodeTiger.CodeAnalysis.SelfTest.csproj | 8 +- .../Analyzers/DiagnosticVerifier.cs | 161 ++++++++---------- .../UnitTests.CodeTiger.CodeAnalysis.csproj | 14 +- 7 files changed, 91 insertions(+), 143 deletions(-) delete mode 100644 CodeTiger.CodeAnalysis.Vsix/app.config diff --git a/Build.ps1 b/Build.ps1 index d1957b5..110cb81 100644 --- a/Build.ps1 +++ b/Build.ps1 @@ -77,6 +77,7 @@ if ($SkipDebug) { } $roslynVersions = @("2.6", "3.8", "4.0", "4.4") +$latestRoslynVersion = $roslynVersions[-1] $roslynVersions | Foreach-Object { $roslynVersion = $_ $configurations | Foreach-Object { @@ -87,7 +88,7 @@ $roslynVersions | Foreach-Object { $slnPath = [IO.Path]::Combine($PSScriptRoot, "CodeTiger.CodeAnalysis.sln") - if (-not $SkipVsix) { + if ($roslynVersion -eq $latestRoslynVersion -and -not $SkipVsix) { if ($CleanBeforeBuilding) { Write-Host "Cleaning CodeTiger.CodeAnalysis.sln..." -ForegroundColor Cyan diff --git a/CodeTiger.CodeAnalysis.Vsix/CodeTiger.CodeAnalysis.Vsix.csproj b/CodeTiger.CodeAnalysis.Vsix/CodeTiger.CodeAnalysis.Vsix.csproj index b321d92..5e3c37e 100644 --- a/CodeTiger.CodeAnalysis.Vsix/CodeTiger.CodeAnalysis.Vsix.csproj +++ b/CodeTiger.CodeAnalysis.Vsix/CodeTiger.CodeAnalysis.Vsix.csproj @@ -4,6 +4,7 @@ 15.0 $(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion) + MSB3243;MSB3277 @@ -48,7 +49,6 @@ /rootsuffix Roslyn - Designer diff --git a/CodeTiger.CodeAnalysis.Vsix/app.config b/CodeTiger.CodeAnalysis.Vsix/app.config deleted file mode 100644 index 6efca9b..0000000 --- a/CodeTiger.CodeAnalysis.Vsix/app.config +++ /dev/null @@ -1,39 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/CodeTiger.CodeAnalysis/CodeTiger.CodeAnalysis.csproj b/CodeTiger.CodeAnalysis/CodeTiger.CodeAnalysis.csproj index da2c46d..d874be4 100644 --- a/CodeTiger.CodeAnalysis/CodeTiger.CodeAnalysis.csproj +++ b/CodeTiger.CodeAnalysis/CodeTiger.CodeAnalysis.csproj @@ -75,7 +75,12 @@ While not intended to be an exact replacement for StyleCop, many of the individu all runtime; build; native; contentfiles; analyzers; buildtransitive - + + + + + + diff --git a/SelfTests/UnitTests.CodeTiger.CodeAnalysis.SelfTest/UnitTests.CodeTiger.CodeAnalysis.SelfTest.csproj b/SelfTests/UnitTests.CodeTiger.CodeAnalysis.SelfTest/UnitTests.CodeTiger.CodeAnalysis.SelfTest.csproj index 1a2f3b3..2f6eab4 100644 --- a/SelfTests/UnitTests.CodeTiger.CodeAnalysis.SelfTest/UnitTests.CodeTiger.CodeAnalysis.SelfTest.csproj +++ b/SelfTests/UnitTests.CodeTiger.CodeAnalysis.SelfTest/UnitTests.CodeTiger.CodeAnalysis.SelfTest.csproj @@ -1,7 +1,7 @@  - net7.0 + net8.0 latest @@ -15,9 +15,9 @@ - - - + + + all runtime; build; native; contentfiles; analyzers; buildtransitive diff --git a/UnitTests/UnitTests.CodeTiger.CodeAnalysis/Analyzers/DiagnosticVerifier.cs b/UnitTests/UnitTests.CodeTiger.CodeAnalysis/Analyzers/DiagnosticVerifier.cs index 0c1177e..6eba063 100644 --- a/UnitTests/UnitTests.CodeTiger.CodeAnalysis/Analyzers/DiagnosticVerifier.cs +++ b/UnitTests/UnitTests.CodeTiger.CodeAnalysis/Analyzers/DiagnosticVerifier.cs @@ -297,17 +297,15 @@ private static void VerifyDiagnosticResults(IEnumerable actualResult { string diagnosticsOutput = actualResults.Any() ? FormatDiagnostics(analyzer, actualResults.ToArray()) - : " NONE."; + : "NONE."; - Assert.True(false, - string.Format("Mismatch between number of diagnostics returned, expected \"{0}\" actual \"{1}" - + """ - " + Assert.Fail( + $""" + Mismatch between number of diagnostics returned, expected {expectedCount}, actual {actualCount} Diagnostics: - {2} - - """, expectedCount, actualCount, diagnosticsOutput)); + {diagnosticsOutput} + """); } for (int i = 0; i < expectedResults.Length; i++) @@ -319,14 +317,13 @@ private static void VerifyDiagnosticResults(IEnumerable actualResult { if (actual.Location != Location.None) { - Assert.True(false, - string.Format(""" - Expected: + Assert.Fail( + $""" + Expected: A project diagnostic with No location - Actual: - {0} - """, - FormatDiagnostics(analyzer, actual))); + Actual: + {FormatDiagnostics(analyzer, actual)} + """); } } else @@ -336,15 +333,14 @@ A project diagnostic with No location if (additionalLocations.Length != expected.Locations.Length - 1) { - Assert.True(false, - string.Format( - """ - Expected {0} additional locations but got {1} for Diagnostic: - {2} - - """, - expected.Locations.Length - 1, additionalLocations.Length, - FormatDiagnostics(analyzer, actual))); + expectedCount = expected.Locations.Length - 1; + actualCount = additionalLocations.Length; + + Assert.Fail( + $""" + Expected {expectedCount} additional locations but got {actualCount} for Diagnostic: + {FormatDiagnostics(analyzer, actual)} + """); } for (int j = 0; j < additionalLocations.Length; ++j) @@ -356,48 +352,35 @@ A project diagnostic with No location if (actual.Id != expected.Id) { - Assert.True(false, - string.Format( - """ - Expected diagnostic id to be "{0}" was "{1}" - - Diagnostic: - {2} + Assert.Fail( + $""" + Expected diagnostic id to be "{expected.Id}" was "{actual.Id}" - """, - expected.Id, actual.Id, FormatDiagnostics(analyzer, actual))); + Diagnostic: + {FormatDiagnostics(analyzer, actual)} + """); } if (actual.Severity != expected.Severity) { - Assert.True(false, - string.Format(""" - Expected diagnostic severity to be "{0}" was "{1}" - - Diagnostic: - """ - + """ - - {2} + Assert.Fail( + $""" + Expected diagnostic severity to be "{expected.Severity}" was "{actual.Severity}" - """, expected.Severity, actual.Severity, - FormatDiagnostics(analyzer, actual))); + Diagnostic: + {FormatDiagnostics(analyzer, actual)} + """); } if (actual.GetMessage() != expected.Message) { - Assert.True(false, - string.Format(""" - Expected diagnostic message to be "{0}" was "{1}" + Assert.Fail( + $""" + Expected diagnostic message to be "{expected.Message}" was "{actual.GetMessage()}" - Diagnostic: - """ - + """ - - {2} - - """, expected.Message, actual.GetMessage(), - FormatDiagnostics(analyzer, actual))); + Diagnostic: + {FormatDiagnostics(analyzer, actual)} + """); } } } @@ -415,57 +398,52 @@ private static void VerifyDiagnosticLocation(DiagnosticAnalyzer analyzer, Diagno { var actualSpan = actual.GetLineSpan(); - Assert.True(actualSpan.Path == expected.Path - || (actualSpan.Path?.Contains("Test0.") == true && expected.Path?.Contains("Test.") == true), - string.Format(""" - Expected diagnostic to be in file "{0}" was actually in file "{1}" - + bool isSpanCorrect = actualSpan.Path == expected.Path + || (actualSpan.Path?.Contains("Test0.") == true && expected.Path?.Contains("Test.") == true); - """ - + """ - Diagnostic: - {2} + Assert.True(isSpanCorrect, + $""" + Expected diagnostic to be in file "{expected.Path}" was actually in file "{actualSpan.Path}" - """, expected.Path, actualSpan.Path, - FormatDiagnostics(analyzer, diagnostic))); + Diagnostic: + {FormatDiagnostics(analyzer, diagnostic)} + """); var actualLinePosition = actualSpan.StartLinePosition; // Only check line position if there is an actual line in the real diagnostic if (actualLinePosition.Line > 0) { - if (actualLinePosition.Line + 1 != expected.Line) - { - Assert.True(false, - string.Format(""" - Expected diagnostic to be on line "{0}" was actually on line "{1}" - - """ - + """ + int expectedLine = expected.Line; + int actualLine = actualLinePosition.Line + 1; - Diagnostic: - {2} + if (actualLine != expectedLine) + { + Assert.Fail( + $""" + Expected diagnostic to be on line {expectedLine} was actually on line {actualLine} - """, expected.Line, actualLinePosition.Line + 1, - FormatDiagnostics(analyzer, diagnostic))); + Diagnostic: + {FormatDiagnostics(analyzer, diagnostic)} + """); } } // Only check column position if there is an actual column position in the real diagnostic if (actualLinePosition.Character > 0) { - if (actualLinePosition.Character + 1 != expected.Column) - { - Assert.True(false, - string.Format("Expected diagnostic to start at column \"{0}\" was actually at column " - + """ - "{1}" + int expectedColumn = expected.Column; + int actualColumn = actualLinePosition.Character + 1; - Diagnostic: - {2} + if (actualColumn != expectedColumn) + { + Assert.Fail( + $""" + Expected diagnostic to start at column {expectedColumn} was actually at column {actualColumn} - """, expected.Column, - actualLinePosition.Character + 1, FormatDiagnostics(analyzer, diagnostic))); + Diagnostic: + {FormatDiagnostics(analyzer, diagnostic)} + """); } } } @@ -498,11 +476,8 @@ private static string FormatDiagnostics(DiagnosticAnalyzer analyzer, params Diag else { Assert.True(location.IsInSource, - $"Test base does not currently handle diagnostics in metadata locations." - + """ - Diagnostic in metadata: {diagnostics[i]} - - """); + "Test base does not currently handle diagnostics in metadata locations. Diagnostic: " + + diagnostics[i]); var sourceTree = location.SourceTree; string resultMethodName = sourceTree is null || sourceTree.FilePath.EndsWith(".cs") == true diff --git a/UnitTests/UnitTests.CodeTiger.CodeAnalysis/UnitTests.CodeTiger.CodeAnalysis.csproj b/UnitTests/UnitTests.CodeTiger.CodeAnalysis/UnitTests.CodeTiger.CodeAnalysis.csproj index 80c82b2..1e7ace1 100644 --- a/UnitTests/UnitTests.CodeTiger.CodeAnalysis/UnitTests.CodeTiger.CodeAnalysis.csproj +++ b/UnitTests/UnitTests.CodeTiger.CodeAnalysis/UnitTests.CodeTiger.CodeAnalysis.csproj @@ -1,7 +1,7 @@  - net7.0 + net8.0 latest enable Contains unit tests for the CodeTiger.CodeAnalysis project. @@ -25,18 +25,24 @@ - + all runtime; build; native; contentfiles; analyzers; buildtransitive - - + + all runtime; build; native; contentfiles; analyzers; buildtransitive + + + + + + From 97e68f8d1b8b97edd52e0ed49434b49860ec8c0a Mon Sep 17 00:00:00 2001 From: Chris Dahlberg Date: Sun, 11 Aug 2024 20:04:36 -0500 Subject: [PATCH 2/3] Changed CT1712 to allow discards in parethesized lambda expression. --- .../Analyzers/Naming/SymbolNamingAnalyzer.cs | 3 +++ .../Analyzers/Naming/SymbolNamingAnalyzerTests.cs | 5 ++++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/CodeTiger.CodeAnalysis/Analyzers/Naming/SymbolNamingAnalyzer.cs b/CodeTiger.CodeAnalysis/Analyzers/Naming/SymbolNamingAnalyzer.cs index 84d023c..32d74a4 100644 --- a/CodeTiger.CodeAnalysis/Analyzers/Naming/SymbolNamingAnalyzer.cs +++ b/CodeTiger.CodeAnalysis/Analyzers/Naming/SymbolNamingAnalyzer.cs @@ -515,6 +515,9 @@ bool IsAllowableDiscard() case SyntaxKind.ParenthesizedLambdaExpression: case SyntaxKind.SimpleLambdaExpression: return "_".Equals(parameterNode.Identifier.ValueText, StringComparison.OrdinalIgnoreCase); + case SyntaxKind.ParameterList: + return parameterNode.Parent.Parent?.IsKind(SyntaxKind.ParenthesizedLambdaExpression) == true + && "_".Equals(parameterNode.Identifier.ValueText, StringComparison.OrdinalIgnoreCase); default: return false; } diff --git a/UnitTests/UnitTests.CodeTiger.CodeAnalysis/Analyzers/Naming/SymbolNamingAnalyzerTests.cs b/UnitTests/UnitTests.CodeTiger.CodeAnalysis/Analyzers/Naming/SymbolNamingAnalyzerTests.cs index 4d29d47..08ca5a7 100644 --- a/UnitTests/UnitTests.CodeTiger.CodeAnalysis/Analyzers/Naming/SymbolNamingAnalyzerTests.cs +++ b/UnitTests/UnitTests.CodeTiger.CodeAnalysis/Analyzers/Naming/SymbolNamingAnalyzerTests.cs @@ -1041,6 +1041,9 @@ public void DoSomething() { var dictionary = new ConcurrentDictionary(); dictionary.GetOrAdd(0, _ => "0"); + dictionary.GetOrAdd(0, (_) => "0"); + Action action = _ => { }; + Func func = (_) => true; } } } @@ -1050,7 +1053,7 @@ public void DoSomething() } [Fact] - public void ParameterWithDiscardNamesWhereNotAllowedProduceDiagnostics() + public void ParametersWithDiscardNamesWhereNotAllowedProduceDiagnostics() { string code = """ using System; From 18ee146a5ea8a444896e87975f3aa2b31f9769fe Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 12 Aug 2024 02:13:20 +0000 Subject: [PATCH 3/3] Bump System.Text.RegularExpressions in /CodeTiger.CodeAnalysis Bumps System.Text.RegularExpressions from 4.3.0 to 4.3.1. --- updated-dependencies: - dependency-name: System.Text.RegularExpressions dependency-type: direct:production ... Signed-off-by: dependabot[bot] --- CodeTiger.CodeAnalysis/CodeTiger.CodeAnalysis.csproj | 2 +- Directory.Build.props | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/CodeTiger.CodeAnalysis/CodeTiger.CodeAnalysis.csproj b/CodeTiger.CodeAnalysis/CodeTiger.CodeAnalysis.csproj index d874be4..8aa98e3 100644 --- a/CodeTiger.CodeAnalysis/CodeTiger.CodeAnalysis.csproj +++ b/CodeTiger.CodeAnalysis/CodeTiger.CodeAnalysis.csproj @@ -80,7 +80,7 @@ While not intended to be an exact replacement for StyleCop, many of the individu - + diff --git a/Directory.Build.props b/Directory.Build.props index 9581b22..6d0860c 100644 --- a/Directory.Build.props +++ b/Directory.Build.props @@ -11,19 +11,19 @@ - 2.6.1 + 4.4.0 $(DefineConstants);ROSLYN2_6;ROSLYN2_6_OR_HIGHER - 3.8.0 + 4.4.0 $(DefineConstants);ROSLYN3_8;ROSLYN3_8_OR_HIGHER;ROSLYN2_6_OR_HIGHER - 4.0.1 + 4.4.0 $(DefineConstants);ROSLYN4_0;ROSLYN4_0_OR_HIGHER;ROSLYN3_8_OR_HIGHER;ROSLYN2_6_OR_HIGHER