DotNetAnalyzers / StyleCopAnalyzers

An implementation of StyleCop rules using the .NET Compiler Platform
MIT License
2.66k stars 507 forks source link

SA1600 is not raised for record primary constructors that are missing param tags #3780

Open SapiensAnatis opened 10 months ago

SapiensAnatis commented 10 months ago

Today, the following code will not cause any Stylecop diagnostics to be raised:

/// <summary>
/// Record.
/// </summary>
public record MyRecord(int Parameter);

This is in spite of the missing <param> tag for Parameter. Stylecop should report a diagnostic unless this is included:

/// <summary>
/// Record.
/// </summary>
/// <param name="Parameter">Parameter.</param>
public record MyRecord(int Parameter);

Because Parameter declares a property as well as a constructor parameter, it was agreed in #3770 that it should report SA1600 instead of the usual SA1611 for missing <param> tags.

SapiensAnatis commented 10 months ago

I've made some initial progress towards tackling this issue, but am currently dealing with a strange problem where my test is reporting each diagnostic twice 😔

I get this output for a record like the one in the example above that declares a single undocumented parameter:

Microsoft.CodeAnalysis.Testing.Verifiers.EqualWithMessageException : Context: Diagnostics of test state
Mismatch between number of diagnostics returned, expected "1" actual "2"

Diagnostics:
// /0/Test0.cs(5,28): warning SA1600: Elements should be documented
VerifyCS.Diagnostic().WithSpan(5, 28, 5, 34),
// /0/Test0.cs(5,28): warning SA1600: Elements should be documented
VerifyCS.Diagnostic().WithSpan(5, 28, 5, 34),

I won't make this a huge comment containing everything I've done (I could open a draft PR if need be) but it seems when I debug the tests all my breakpoints are hit twice. This seems to happen with other analyzers as well. I was wondering if that could be the cause, or is this normal when testing analyzers?

sharwell commented 10 months ago

I think there are some versions of Roslyn where callbacks execute twice, resulting in duplicate diagnostics. You can include the diagnostic twice in the expected results and I can investigate further.