Report MA0206 on record struct and interface declarations
What
MA0206 (Remove unnecessary braces in type declaration) never reported on record struct or interface declarations. Both now produce a diagnostic and a code fix.
record R(int A) { } // reported before and after
record struct RS(int A) { } // only reported after this change
interface IFoo { } // only reported after this change
Why
RemoveUnnecessaryBracesInTypeDeclarationAnalyzer registered its action on SyntaxKind.RecordDeclaration, ClassDeclaration and StructDeclaration. A record struct produces a RecordDeclarationSyntax whose kind is SyntaxKind.RecordStructDeclaration — not RecordDeclaration (which covers record and record class) and not StructDeclaration — so the node was never visited. CanUseSemicolonTypeDeclaration already returns true for any RecordDeclarationSyntax, so the code was clearly written expecting record structs to arrive; this was a gap, not a scope decision.
Interfaces were simply missing from the registration. interface IFoo; is valid since C# 12, so the rule applies there too.
How
- The action is registered on the five kinds in a single
RegisterSyntaxNodeActioncall (addingRecordStructDeclarationandInterfaceDeclaration). CanUseSemicolonTypeDeclarationacceptsInterfaceDeclarationSyntaxin its C# 12-gated arm, in both the analyzer and the code fixer. Record structs need no change there: they already fall into theRecordDeclarationSyntaxarm.docs/Rules/MA0206.mdscope sentence and samples updated.
Notes for reviewers
The language gates were checked against the compiler rather than assumed. interface IFoo;, interface IFoo : IBase;, record struct RS; and readonly record struct RRS(int A); all compile under C# 12; interface IFoo; fails under C# 11 with CS9058. So the interface arm needs the C# 12 guard, and record structs correctly need none — a record struct only parses on a language version that supports it.
7 tests added to the existing test class: record struct with a primary constructor (code fix), readonly record struct without a parameter list, record struct with a member (no diagnostic), interface (code fix), interface with a base list (code fix), interface with a member (no diagnostic), and an interface under LanguageVersion.CSharp11 pinning the version gate (no diagnostic).
All 18 tests in the class pass on every supported Roslyn version (4.8, 4.14, 5.0, 5.6, 5.9) — 11 pre-existing plus the 7 new, so the count confirms the new tests ran. dotnet run --project src/DocumentationGenerator exits 0 with no further markdown changes.
No entry was added to docs/comparison-with-other-analyzers.md: MA0206 is absent from it today, and this widens an existing rule's scope rather than establishing a new equivalence with an external rule.