Skip to content

Support records in several additional rules - #3264

Merged
sharwell merged 5 commits into
DotNetAnalyzers:masterfrom
sharwell:record-order
Dec 5, 2020
Merged

sharwell merged 5 commits into
DotNetAnalyzers:masterfrom
sharwell:record-order

Conversation

@sharwell

@sharwell sharwell commented Dec 5, 2020 •

Copy link
Copy Markdown
Member
  • Add tests for records in many rules
    • SA1106
    • SA1137 (with fixes)
    • SA1201 (with fixes)
    • SA1205 (with fixes)
    • SA1400 (with fixes)
    • SA1500
    • SA1502 (with fixes)
    • SA1505
    • SA1508
    • SA1604
    • SA1605
    • SA1606
    • SA1607
    • SA1608
    • SA1618
    • SA1619
    • SA1625
  • Update SA1205 to support private protected

Fixes #3236

@codecov

codecov Bot commented Dec 5, 2020

Copy link
Copy Markdown

Codecov Report

Merging #3264 (e6720f1) into master (9715fc0) will increase coverage by 0.04%.
The diff coverage is 94.46%.

@@            Coverage Diff             @@
##           master    #3264      +/-   ##
==========================================
+ Coverage   93.48%   93.52%   +0.04%     
==========================================
  Files        1002     1009       +7     
  Lines      109695   109886     +191     
  Branches     3724     3771      +47     
==========================================
+ Hits       102550   102774     +224     
+ Misses       6215     6165      -50     
- Partials      930      947      +17     

@sharwell
sharwell merged commit 3414e7a into DotNetAnalyzers:master Dec 5, 2020
@sharwell
sharwell deleted the record-order branch December 5, 2020 21:54
@sharwell sharwell added this to the 1.2-beta.next milestone Dec 5, 2020
@ivan-nosar

Copy link
Copy Markdown

Issue still persists for the files that contains nested record type definitions (accessibility modifiers doesn't matter)

I encountered the following analyzer failure when attempted to build the code:

public class TopLevelClass : IDisposable
{
   // Some logic that refers NestedRecordType

   private record NestedRecordType(string name, int value);
}

Error message: Analyzer 'StyleCop.Analyzers.OrderingRules.SA1201ElementsMustAppearInTheCorrectOrder' threw an exception of type 'System.Collections.Generic.KeyNotFoundException' with message 'The given key was not present in the dictionary.'.

Record types defined with public modifier at the top-level doesn't cause that issue.

@bjornhellander

Copy link
Copy Markdown
Contributor

@ivan-nosar I suspect that you are using an old version. I can at least not reproduce this with 1.2.0-beta.556. The latest beta is currently the only way to get a good experience with these analyzers when using "new" language features. In particular, version 1.1.118 is from 2019 and does not handle modern c# well. If you are indeed using a late beta, then please create a new issue.

@ivan-nosar

ivan-nosar commented Jan 21, 2026 •

Copy link
Copy Markdown

@bjornhellander you're right, I'm using version 1.1.118 as it is latest one marked as stable - unfortunately, I can't update to beta, so I'll just avoid creating nested record types. I'm glad to hear that this issue was fixed in latest releases, though.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

SA1201 for records says '<unknown>' should not follow an enum

3 participants