Skip to content

Commit a1909e0

Browse files
Update SA1004 to allow doc comments to start with the in, out and ref keywords
#3817
1 parent 17b613d commit a1909e0

File tree

2 files changed

+48
-4
lines changed

2 files changed

+48
-4
lines changed

StyleCop.Analyzers/StyleCop.Analyzers.Test/SpacingRules/SA1004UnitTests.cs

Lines changed: 45 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
// Copyright (c) Tunnel Vision Laboratories, LLC. All Rights Reserved.
22
// Licensed under the MIT License. See LICENSE in the project root for license information.
33

4-
#nullable disable
5-
64
namespace StyleCop.Analyzers.Test.SpacingRules
75
{
6+
using System.Collections.Generic;
87
using System.Threading;
98
using System.Threading.Tasks;
9+
using Microsoft.CodeAnalysis.CSharp;
1010
using Microsoft.CodeAnalysis.Testing;
11+
using StyleCop.Analyzers.Lightup;
1112
using StyleCop.Analyzers.SpacingRules;
1213
using Xunit;
1314
using static StyleCop.Analyzers.Test.Verifiers.StyleCopCodeFixVerifier<
@@ -19,6 +20,20 @@ namespace StyleCop.Analyzers.Test.SpacingRules
1920
/// </summary>
2021
public class SA1004UnitTests
2122
{
23+
public static IEnumerable<object[]> ParameterModifiers
24+
{
25+
get
26+
{
27+
yield return new[] { "out" };
28+
yield return new[] { "ref" };
29+
30+
if (LightupHelpers.SupportsCSharp72)
31+
{
32+
yield return new[] { "in" };
33+
}
34+
}
35+
}
36+
2237
[Fact]
2338
public async Task TestFixedExampleAsync()
2439
{
@@ -213,5 +228,33 @@ private void Method1(int x, int y)
213228

214229
await VerifyCSharpFixAsync(testCode, expected, fixedCode, CancellationToken.None).ConfigureAwait(false);
215230
}
231+
232+
[Theory]
233+
[MemberData(nameof(ParameterModifiers))]
234+
[WorkItem(3817, "https://github.com/DotNetAnalyzers/StyleCopAnalyzers/issues/3817")]
235+
public async Task TestParameterModifierFirstOnLineAsync(string keyword)
236+
{
237+
string testCode = $@"
238+
/// <summary>
239+
/// Description of some remarks that refer to a method: <see cref=""SomeMethod(int, int,
240+
/// {keyword} string)""/>.
241+
/// </summary>
242+
public class TypeName
243+
{{
244+
public void SomeMethod(int x, int y, {keyword} string z)
245+
{{
246+
throw new System.Exception();
247+
}}
248+
}}";
249+
250+
var languageVersion = (LightupHelpers.SupportsCSharp8, LightupHelpers.SupportsCSharp72) switch
251+
{
252+
// Make sure to use C# 7.2 if supported, unless we are going to default to something greater
253+
(false, true) => LanguageVersionEx.CSharp7_2,
254+
_ => (LanguageVersion?)null,
255+
};
256+
257+
await VerifyCSharpDiagnosticAsync(languageVersion, testCode, DiagnosticResult.EmptyDiagnosticResults, CancellationToken.None).ConfigureAwait(false);
258+
}
216259
}
217260
}

StyleCop.Analyzers/StyleCop.Analyzers/SpacingRules/SA1004DocumentationLinesMustBeginWithSingleSpace.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
// Copyright (c) Tunnel Vision Laboratories, LLC. All Rights Reserved.
22
// Licensed under the MIT License. See LICENSE in the project root for license information.
33

4-
#nullable disable
5-
64
namespace StyleCop.Analyzers.SpacingRules
75
{
86
using System;
@@ -112,6 +110,9 @@ private static void HandleDocumentationCommentExteriorTrivia(SyntaxTreeAnalysisC
112110
case SyntaxKind.XmlCommentEndToken:
113111
case SyntaxKind.XmlCDataStartToken:
114112
case SyntaxKind.XmlCDataEndToken:
113+
case SyntaxKind.InKeyword:
114+
case SyntaxKind.OutKeyword:
115+
case SyntaxKind.RefKeyword:
115116
if (!token.HasLeadingTrivia)
116117
{
117118
break;

0 commit comments

Comments
 (0)