From 5ca9aeb4d32229cb06c9e65a96a210c0c8fb2c3f Mon Sep 17 00:00:00 2001 From: Azarasi Date: Sun, 22 Sep 2024 21:13:51 +0900 Subject: [PATCH] Fix coverage Remove unused method --- .../HelperTests/SyntaxTreeHelpersTests.cs | 21 ++++++++++ .../NamingRules/SA1313UnitTests.cs | 41 ++++++++++++++++++- .../Helpers/SyntaxTreeHelpers.cs | 18 -------- 3 files changed, 60 insertions(+), 20 deletions(-) create mode 100644 StyleCop.Analyzers/StyleCop.Analyzers.Test/HelperTests/SyntaxTreeHelpersTests.cs diff --git a/StyleCop.Analyzers/StyleCop.Analyzers.Test/HelperTests/SyntaxTreeHelpersTests.cs b/StyleCop.Analyzers/StyleCop.Analyzers.Test/HelperTests/SyntaxTreeHelpersTests.cs new file mode 100644 index 000000000..164c9ef3e --- /dev/null +++ b/StyleCop.Analyzers/StyleCop.Analyzers.Test/HelperTests/SyntaxTreeHelpersTests.cs @@ -0,0 +1,21 @@ +// Copyright (c) Tunnel Vision Laboratories, LLC. All Rights Reserved. +// Licensed under the MIT License. See LICENSE in the project root for license information. + +#nullable disable + +namespace StyleCop.Analyzers.Test.HelperTests +{ + using Microsoft.CodeAnalysis; + using StyleCop.Analyzers.Helpers; + using Xunit; + + public class SyntaxTreeHelpersTests + { + [Fact] + public void TestContainsUsingAliasArgumentIsNull() + { + SyntaxTree tree = null; + Assert.False(tree.ContainsUsingAlias(null)); + } + } +} diff --git a/StyleCop.Analyzers/StyleCop.Analyzers.Test/NamingRules/SA1313UnitTests.cs b/StyleCop.Analyzers/StyleCop.Analyzers.Test/NamingRules/SA1313UnitTests.cs index d9d253779..31e2fc120 100644 --- a/StyleCop.Analyzers/StyleCop.Analyzers.Test/NamingRules/SA1313UnitTests.cs +++ b/StyleCop.Analyzers/StyleCop.Analyzers.Test/NamingRules/SA1313UnitTests.cs @@ -594,12 +594,49 @@ public async Task TestMethodParameterNamedDoubleUnderscoreAsync() { var testCode = @"public class TypeName { - public void MethodName(int __) + public void MethodName(int __, int _) { } }"; - DiagnosticResult expected = Diagnostic().WithArguments("__").WithLocation(3, 32); + DiagnosticResult[] expected = + { + Diagnostic().WithArguments("__").WithLocation(3, 32), + Diagnostic().WithArguments("_").WithLocation(3, 40), + }; + await VerifyCSharpDiagnosticAsync(testCode, expected, CancellationToken.None).ConfigureAwait(false); + } + + [Fact] + [WorkItem(2974, "https://github.com/DotNetAnalyzers/StyleCopAnalyzers/issues/2974")] + public async Task TestMethodParameterNamedIncrementUnderscoreAsync() + { + var testCode = @"public class TypeName +{ + public void MethodName(int _, int __, int ___) + { + } +}"; + await VerifyCSharpDiagnosticAsync(testCode, DiagnosticResult.EmptyDiagnosticResults, CancellationToken.None).ConfigureAwait(false); + } + + [Fact] + [WorkItem(2974, "https://github.com/DotNetAnalyzers/StyleCopAnalyzers/issues/2974")] + public async Task TestMethodParameterNamedIrregularUnderscoreAsync() + { + var testCode = @"public class TypeName +{ + public void MethodName1(int __, int _) { } + public void MethodName2(int _, int ___, int __) { } +}"; + + DiagnosticResult[] expected = + { + Diagnostic().WithArguments("__").WithLocation(3, 33), + Diagnostic().WithArguments("_").WithLocation(3, 41), + Diagnostic().WithArguments("___").WithLocation(4, 40), + Diagnostic().WithArguments("__").WithLocation(4, 49), + }; await VerifyCSharpDiagnosticAsync(testCode, expected, CancellationToken.None).ConfigureAwait(false); } diff --git a/StyleCop.Analyzers/StyleCop.Analyzers/Helpers/SyntaxTreeHelpers.cs b/StyleCop.Analyzers/StyleCop.Analyzers/Helpers/SyntaxTreeHelpers.cs index 6c90a1733..70ca30828 100644 --- a/StyleCop.Analyzers/StyleCop.Analyzers/Helpers/SyntaxTreeHelpers.cs +++ b/StyleCop.Analyzers/StyleCop.Analyzers/Helpers/SyntaxTreeHelpers.cs @@ -73,24 +73,6 @@ public static bool IsWhitespaceOnly(this SyntaxTree tree, CancellationToken canc && TriviaHelper.IndexOfFirstNonWhitespaceTrivia(firstToken.LeadingTrivia) == -1; } - /// - /// Recursively descends through the tree structure, enumerating all Statement nodes encountered during the traversal. - /// - /// The syntax node to recursively. - /// Enumerated StatementSyntax. - public static IEnumerable StatementDescendRecursively(this SyntaxNode syntaxNode) - { - foreach (var statement in syntaxNode.ChildNodes().OfType()) - { - yield return statement; - - foreach (var innerItem in StatementDescendRecursively(statement)) - { - yield return innerItem; - } - } - } - /// /// Recursively descends through the tree structure, enumerating all Expression nodes encountered during the traversal. ///