Skip to content

Commit

Permalink
Update SA1004 to allow doc comments to start with the in, out and ref…
Browse files Browse the repository at this point in the history
… keywords

#3817
  • Loading branch information
bjornhellander committed May 11, 2024
1 parent 17b613d commit a1909e0
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
// 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.SpacingRules
{
using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.CodeAnalysis.CSharp;
using Microsoft.CodeAnalysis.Testing;
using StyleCop.Analyzers.Lightup;
using StyleCop.Analyzers.SpacingRules;
using Xunit;
using static StyleCop.Analyzers.Test.Verifiers.StyleCopCodeFixVerifier<
Expand All @@ -19,6 +20,20 @@ namespace StyleCop.Analyzers.Test.SpacingRules
/// </summary>
public class SA1004UnitTests
{
public static IEnumerable<object[]> ParameterModifiers
{
get
{
yield return new[] { "out" };
yield return new[] { "ref" };

if (LightupHelpers.SupportsCSharp72)
{
yield return new[] { "in" };
}
}
}

[Fact]
public async Task TestFixedExampleAsync()
{
Expand Down Expand Up @@ -213,5 +228,33 @@ private void Method1(int x, int y)

await VerifyCSharpFixAsync(testCode, expected, fixedCode, CancellationToken.None).ConfigureAwait(false);
}

[Theory]
[MemberData(nameof(ParameterModifiers))]
[WorkItem(3817, "https://github.com/DotNetAnalyzers/StyleCopAnalyzers/issues/3817")]
public async Task TestParameterModifierFirstOnLineAsync(string keyword)
{
string testCode = $@"
/// <summary>
/// Description of some remarks that refer to a method: <see cref=""SomeMethod(int, int,
/// {keyword} string)""/>.
/// </summary>
public class TypeName
{{
public void SomeMethod(int x, int y, {keyword} string z)
{{
throw new System.Exception();
}}
}}";

var languageVersion = (LightupHelpers.SupportsCSharp8, LightupHelpers.SupportsCSharp72) switch
{
// Make sure to use C# 7.2 if supported, unless we are going to default to something greater
(false, true) => LanguageVersionEx.CSharp7_2,
_ => (LanguageVersion?)null,
};

await VerifyCSharpDiagnosticAsync(languageVersion, testCode, DiagnosticResult.EmptyDiagnosticResults, CancellationToken.None).ConfigureAwait(false);
}
}
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
// 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.SpacingRules
{
using System;
Expand Down Expand Up @@ -112,6 +110,9 @@ private static void HandleDocumentationCommentExteriorTrivia(SyntaxTreeAnalysisC
case SyntaxKind.XmlCommentEndToken:
case SyntaxKind.XmlCDataStartToken:
case SyntaxKind.XmlCDataEndToken:
case SyntaxKind.InKeyword:
case SyntaxKind.OutKeyword:
case SyntaxKind.RefKeyword:
if (!token.HasLeadingTrivia)
{
break;
Expand Down

0 comments on commit a1909e0

Please # to comment.