This is the first StyleCop.Analyzers release since 1.2.0-beta.556, and it's a big one. The project is active again: this release brings the analyzers up to date with every C# version from 10 through the C# 15 previews, clears a long backlog of bugs, and modernizes how the project is built, tested and shipped. Thank you to everyone who contributed code, reviews, translations and bug reports over the long gap. Many of the changes below started as community pull requests.
Highlights
- C# 8 through C# 15 language support. Each language version was audited rule by rule, and the rules now understand newer syntax instead of ignoring it or crashing: records and record structs, file-scoped namespaces, global usings, raw and interpolated strings, primary constructors, collection expressions, partial properties, events and constructors,
allows ref struct, C# 14 extension blocks and thefieldkeyword, and C# 15 preview unions with theclosedandsafemodifiers. (#4142, #4139, #4137, #4163, #4148, #4191, #4193) - A large batch of bug fixes. These cover false positives, crashes and wrong code fixes across spacing, layout, documentation, naming and maintainability rules. Several are long-standing issues. (#4210, #3935, #4202, #4195, #4198, #3880)
- Better code fixes. Code fixes now keep the file's line endings, keep comments in place, indent correctly when they add braces or move arguments, and use the compiler's batch Fix All. There is also a new SA1312 fix that turns underscore-only locals into discards, plus a "Generate additional part" refactoring. (#4076, #4199, #4108, #4229, #4208, #3705)
- Faster analysis. Settings are loaded faster, the spacing and layout rules walk each syntax tree only once, and SA1141 was optimized. (#3885, #4106, #3610)
- Configuration and documentation. Every setting can now be set in
.editorconfig, and the docs explain how that works alongsidestylecop.json. The documentation and rule status are published on GitHub Pages, and there are more translations of the code-fix documentation text (Czech, Dutch, Russian and others). (#4221, #4218, #3374, #3944, #3900, #4220) - Packaging. The NuGet packages now include a README, and PDBs are embedded in the DLLs, so there is no separate symbols package. Packages are published from GitHub Actions using nuget.org trusted publishing. (#4204, #4173, #4123)
- Modernized engineering. CI moved to GitHub Actions and now runs on Linux, the build uses the .NET 10 SDK, tests use xUnit v3, and Renovate keeps dependencies current. The analyzers still target the same Roslyn version, so they work with the same compilers and IDEs as before. (#4105, #4126, #4225, #4226, #4253, #4231)
Behavior changes worth knowing about
Upgrading may produce new or different diagnostics:
- Rules now cover newer syntax. Ordering, layout, spacing and documentation rules now analyze records, primary constructors, collection expressions, extension blocks, unions and other newer constructs. They used to skip these, so expect new warnings in code that uses them.
- Extension members need documentation. SA1600 no longer treats C# 14 extension blocks as private, so their public members must be documented. SA1600 also reports undocumented record primary constructor parameters. (#4163, #4213)
- Partial members. For partial methods, properties, indexers, constructors and events, SA1600 now leaves the check to SA1601. Documenting one part is enough. (#4148, #4149, #4152)
- SA1316 now always reports explicitly written tuple element names, even when
includeInferredTupleElementNamesis off. Names the compiler infers are still checked only when that setting is on. (#4202) - SA1312 no longer reports
_forforeachvariables andusingdeclarations. (#4203) - SA1205 treats the
filemodifier as an access modifier. (#4198) - SA1304 now analyzes
protected readonlyfields when SA1307 is enabled. (#4217) - SA1122 now reports empty interpolated and raw string literals, and SA1130 reports anonymous methods whose parameter names differ from the delegate's. SA1121 and SA1125 report System types in using alias targets. (#4178, #4179, #4175)
- SA1642 expects "union" wording, for example "Initializes a new instance of the … union.", in constructor summaries of C# 15 union types. (#4193)
- SA1600 respects the
documentInterfacessetting values. (#3140) - The default rule set is complete, so rules that were missing from it are now listed with their default severity. (#4115)
- Packaging: the separate
.symbols.nupkgis gone, because PDBs are now embedded in the DLLs. (#4173)
All changes
Fixes (52)
- Fix SA1504, SA1413, SA1402, SA1135, and blank lines above documentation comments by @AArnott in #4210
- Fix SA1649 for C# 15 union declarations and C# 14 extension blocks by @verdie-g in #4096, completed by @AArnott in #4127
- Update SettingsHelper to not throw exception if the settings file can not be read by @bjornhellander in #3935
- Update SA1404 to not crash when attribute uses a namespace alias by @bjornhellander in #3830
- Update SA1135UsingDirectivesMustBeQualified to not crash on a UsingDirectiveSyntax without a Name by @bjornhellander in #3883
- Fix line ending handling by @sharwell in #4076
- SA1316: always check explicit element names in tuple expressions by @AArnott in #4202
- SA1205: treat the C# 11 file modifier as an access modifier by @AArnott in #4198
- SA1118: apply the multi-line argument exceptions to attribute arguments by @AArnott in #4195
- SA1013: don't report a closing interpolation brace that starts a line by @AArnott in #4196
- SA1629: accept a period followed by closing quotation marks by @AArnott in #4197
- Fix SA1611 not triggering on class primary constructors by @SapiensAnatis in #3777
- SA1304: analyze protected readonly fields when SA1307 is enabled by @AArnott in #4217
- SA1649: match escaped identifiers to filenames by @AArnott in #4215
- SA1137: fix closing brace indentation when inline by @AArnott in #4216
- SA1008: allow whitespace before comments after opening parentheses by @AArnott in #4214
- Fix csharp_using_directive_placement setting retrieval by @kvpt in #3762
- Update SA1515 to not require a blank line before a comment at the start of a collection expression by @bjornhellander in #3768
- Update SA1513 to not require a blank line before linq 'into' keyword by @DoobieAsDave in #3820
- Update SA1004 to allow doc comments to start with the in, out and ref keywords by @bjornhellander in #3836
- Correct SA1629 to add a period if the documentation ends in an xml entity. Previously replaced the semicolon in the xml entity. by @bjornhellander in #3859
- SA1642: Allow Tags in Constructor Documentation by @MattFromRVA in #3861
- Issue 3100 - Changed SA1600 and tests to meet new documentInterfaces values by @CPAM34 in #3140
- Update SA1316 to not trigger in tuple types which are part of a member's signature, if that member is an override by @bjornhellander in #3782
- Skip Warnings for Commas After Conditional Directives by @MattFromRVA in #3839
- Fix SA1514: Do not report when documenting types declared in the global namespace by @MattFromRVA in #3863
- Exempt file-local types from SA1402 [resolves #3803] by @6bee in #3879
- Update SA1623 and SA1624 to not trigger if the summary contains an inheritdoc element by @bjornhellander in #3880
- Update SA1200UsingDirectivesMustBePlacedCorrectly to not trigger in files with only global using directives by @bjornhellander in #3938
- Do not report SA1516 for two consecutive single line properties by @FantasyTeddy in #3936
- update SA1518 to ignore empty (0 bytes) files by @DWIAltonaAnalytics in #3927
- Update SA1515SingleLineCommentMustBePrecededByBlankLine to not require a blank line at the start of an expression body by @bjornhellander in #3940
- Complete the default rule set by @alexander-efremov in #4115
- Describe all constructs SA1413 reports in its message by @alexander-efremov in #4113
- Require a blank line after a closing brace inside a lambda passed as an argument in SA1513 by @alexander-efremov in #4112
- Expand aliases in alias targets when using directives move into a namespace by @alexander-efremov in #4109
- Indent the whole first argument when SA1116 moves it to its own line by @alexander-efremov in #4107
- Indent the whole statement when the SA1503, SA1519 and SA1520 code fix adds braces by @alexander-efremov in #4108
- Turn a stray comment inside documentation into a documentation line in the SA1626 code fix by @alexander-efremov in #4111
- Use the right article in SA1201 messages by @alexander-efremov in #4114
- Report empty documentation text when inheritdoc has nothing to inherit by @alexander-efremov in #4110
- Update for null-forgiving operator at end of line by @EdwinEngelen in #4080
- Update SA1649CodeFixProvider to fix problems related to linked files by @bjornhellander in #3862
- Fix SA1130 for anonymous methods with a natural type by @AArnott in #4133
- Allow a closing brace followed by the end of an interpolation in SA1500 by @AArnott in #4134
- Fix SA1023 false positive for pointer types in using aliases by @AArnott in #4140
- SA1122: report empty interpolated and raw string literals by @AArnott in #4178
- SA1130: report anonymous methods whose parameter names differ from the delegate's by @AArnott in #4179
- SA1021/SA1022: don't move comments when removing the space before a sign by @AArnott in #4199
- SA1102: don't offer the code fix when it would delete comments by @AArnott in #4200
- SA1005: don't report .NET template engine directives (//-:cnd, //+:cnd) by @AArnott in #4201
- SA1312: allow _ for foreach variables and using declarations by @AArnott in #4203
Enhancements (73)
- Support C# 15 unions in SA1600/SA1601/SA1300/SA1400/SA1206/SA1201-SA1204 (test with Roslyn 5.10 preview) by @AArnott in #4191
- Support C# 15 unions in the remaining type declaration rules by @AArnott in #4193
- Support C# 15 union declarations in SA1201, SA1202 and SA1402 by @AArnott in #4188
- Require documentation for C# 14 extension members (extension blocks no longer treated as private) by @AArnott in #4163
- Handle C# 14 partial constructors and events as partial elements by @AArnott in #4152
- C# 13: handle partial properties and indexers in documentation rules by @AArnott in #4148
- C# 13: SA1600 leaves partial methods, properties and indexers to SA1601 (stacked on #4148) by @AArnott in #4149
- Handle records in ordering, layout and documentation rules by @AArnott in #4142
- Apply SA1201, SA1202 and SA1204 inside C# 14 extension blocks by @AArnott in #4174
- Update SA1101 and SA1201 for C# 14 extension members by @AArnott in #4119
- Update SA1500 and SA1513 for property initializers after accessor lists (C# 14 field-backed properties) by @EdwinEngelen in #4077, completed by @AArnott in #4118
- SA1312: add a code fix that replaces underscore-only locals with discards by @AArnott in #4208
- Embed PDBs in the shipped DLLs and stop producing a symbols package by @AArnott in #4173
- Add a README to the NuGet packages by @AArnott in #4204
- Use the compiler-provided batch Fix All provider by @AArnott in #4229
- Add 'Generate additional part' refactoring by @sharwell in #3705
- Faster settings by @sharwell in #3885
- Walk the tokens of a syntax tree once for the spacing and layout rules by @alexander-efremov in #4106
- Optimize SA1141 by @sharwell in #3610
- Update analyzers for better design time support by @sharwell in #3773
- Complete Russian localization and add multilingual DocFX documentation by @SergeyZhurikhin in #3900
- Add missing documentation resource translations by @AArnott in #4220
- Add Czech translations for documentation strings by @DavidCizek in #3944
- Update to use a custom fixer for SA1629 by @bjornhellander in #3767
- Update SA1012 to forbid space before a property pattern, when it is preceeded by an opening parenthesis. Previously only handled positional patterns correctly. by @bjornhellander in #3813
- Update SA1110 to also check the parameter list in primary constructors by @bjornhellander in #3800
- Update SA1111 to also check the parameter list in primary constructors by @bjornhellander in #3791
- Update SA1003 to handle the null-coalescing assignment operator, the unsigned right-shift operator, the unsigned right-shift assignment operator and the null-forgiving operator by @bjornhellander in #3823
- Update SA1612 to also check primary constructor parameters by @bjornhellander in #3833
- Update SA1015 to not care about trailing spaces in a number of cases: typically last in dictionary initializer items, collection initializers and collection expressions. #3856 by @bjornhellander in #3857
- Correct property standard text for ru-RU culture by @ds1709 in #3335
- added dutch document culture by @JEFFTheDev in #3333
- Update SA1121 and SA1404 to detect global using aliases, using GetImportScopes and compiling expression trees by @bjornhellander in #3678
- Update SA1008 to require a space before the opening parenthesis if it's the left operand of a range expression by @bjornhellander in #3895
- Update SA1008OpeningParenthesisMustBeSpacedCorrectly to disallow a leading space before a lambda in a collection expression by @bjornhellander in #3934
- Update for nullable types in C# 8 by @sharwell in #4039
- Support static local functions from C# 8 by @sharwell in #4036
- Support indices and ranges from C# 8 by @sharwell in #4038
- Update to support default interface members by @sharwell in #4034
- Support async streams from C# 8 by @sharwell in #4037
- Update rules for pattern matching in C# 8 by @sharwell in #4035
- Update rules for target-typed new in C# 9 by @sharwell in #4061
- Update for init-only setters by @sharwell in #4053
- Support relational and logical patterns from C# 9 by @sharwell in #4058
- Update for native integers in C# 9 by @sharwell in #4060
- Updates for covariant return types in C# 9 by @sharwell in #4062
- Update for top-level statements by @sharwell in #4054
- Update for static anonymous functions in C# 9 by @sharwell in #4064
- Update for partial methods in C# 9 by @sharwell in #4063
- Update for function pointers in C# 9 by @sharwell in #4059
- Update for extended property patterns in C# 10 by @sharwell in #4072
- Update for lambda natural types in C# 10 by @sharwell in #4073
- Update for global usings in C# 10 by @sharwell in #4071, completed by @AArnott in #4121
- Updates for record structs by @sharwell in #4074, completed by @AArnott in #4122
- Support the C# 10 #line span directive format by @sharwell in #4079, completed by @AArnott in #4128
- Update SA1133 and SA1134 for attributes on lambda expressions (C# 10) by @AArnott in #4131
- Update SA1000 for the C# 11 scoped keyword by @AArnott in #4135
- Update SA1137 to check collection expressions by @AArnott in #4137
- Update SA1413 to check collection expressions by @AArnott in #4138
- Update SA1112-SA1117 to handle primary constructor parameter and base argument lists by @AArnott in #4139
- Update SA1500 to handle C# 14 extension blocks by @AArnott in #4154
- Update SA1502 to handle C# 14 extension blocks by @AArnott in #4155
- Update SA1505 to handle C# 14 extension blocks by @AArnott in #4156
- Update SA1508 to handle C# 14 extension blocks by @AArnott in #4157
- Update SA1516 to handle C# 14 extension blocks by @AArnott in #4158
- Update SA1106 to handle C# 14 extension blocks by @AArnott in #4159
- Update SA1110 to handle C# 14 extension blocks by @AArnott in #4160
- Update SA1111 to handle C# 14 extension blocks by @AArnott in #4161
- Update SA1137 to handle C# 14 extension blocks by @AArnott in #4162
- C# 13: SA1130 handles params collections by @AArnott in #4147
- SA1121/SA1125: report System types in using alias targets from C# 12 by @AArnott in #4175
- C# 15: SA1206 orders the closed and safe modifiers correctly by @AArnott in #4187
- SA1600: report undocumented record primary constructor parameters by @AArnott in #4213
Documentation (10)
- Publish documentation and rule status with DocFX on GitHub Pages by @AArnott in #4218
- Allow every setting in .editorconfig and document unified configuration by @AArnott in #4221
- Add documentation for .editorconfig properties by @FantasyTeddy in #3374
- Docs: document how systemUsingDirectivesFirst affects SA1208, SA1210 and SA1217 by @AArnott in #4205
- Update known changes documentation by @sharwell in #4047
- Update SA1025 documentation to reflect handling of multiple spaces preceding a symbol by @bjornhellander in #3765
- Update
stylecop.jsonschema to have correct default forheaderDecoration. by @alexrp in #3842 - Corrected SA1604 documentation to include a relevant example by @bjornhellander in #3855
- Add tests and documentation for records by @sharwell in #4052
- Update SA1516 documentation for file-scoped namespaces by @sharwell in #4075
Infrastructure and build (80)
- Add a release workflow using nuget.org trusted publishing by @AArnott in #4123
- Move CI to GitHub Actions; retire AppVeyor and Azure Pipelines config by @AArnott in #4105
- Modernize the build: .NET 10 SDK, Roslyn 5.9 compiler, C# 14, coverage without .NET 6 by @AArnott in #4126
- Move C# test matrix and coverage jobs to Linux on .NET 10 by @AArnott in #4225
- Move solution build jobs to Linux without changing package compatibility by @AArnott in #4226
- Compile C# 15 tests against .NET 11 ref assemblies and disallow errors by @bjornhellander in #4212
- Retarget C# 6/7 tests to net472 and update Microsoft.CodeAnalysis.Testing to 1.1.4 by @AArnott in #4190
- Match C# 13+ test reference assemblies to the language version by @AArnott in #4189
- Add agent skills and AGENTS.md for AI-assisted contributions by @AArnott in #4209
- Update to StyleCop.Analyzers 1.2.0-beta.556 by @sharwell in #3761
- Set version numbers in CI by @sharwell in #3203
- Remove VSIX project and unnecessary build outputs by @sharwell in #3763
- Define lightup method for TypeDeclarationSyntax.ParameterList by @sharwell in #3774
- Improve tests for SA1612 by @bjornhellander in #3801
- Update some tests to not use a fixed language version by @bjornhellander in #3832
- Add test project for c# 13 (pre-release version) by @bjornhellander in #3864
- Fix codecov not displaying on GitHub by @eXpl0it3r in #3905
- Added SyntaxKinds related to Patterns and InitOnlySetters by @csaba-sagi-sonarsource in #3356
- Add tests for ForEachVariableStatementSyntaxWrapper by @bjornhellander in #3626
- Add test for SA1000's handling of c# 7.1 default literal expressions by @bjornhellander in #3838
- Update the code analysis nuget in the c# 13 test project to the official 4.12.0 version by @bjornhellander in #3908
- Use existing constant SyntaxKind.GlobalKeyword by @sharwell in #3963
- Add tests for readonly members in C# 8 by @sharwell in #4032
- Update SA1503 and SA1106 tests for using declarations by @sharwell in #4033
- Support testing on Linux by @sharwell in #4048
- Only build net6.0 test targets on Linux by @sharwell in #4050
- Downgrade Nerdbank.GitVersioning for net6.0 runtime by @sharwell in #4051
- Update tests for target-typed conditional expressions by @sharwell in #4055
- Add tests for attributed local functions in C# 9 by @sharwell in #4057
- Update tests for lambda discard parameters by @sharwell in #4056
- Add tests for extension foreach in C# 9 by @sharwell in #4065
- Add test project for C# 14 by @bjornhellander in #4040, completed by @AArnott in #4117
- Add tests for mixed deconstruction in C# 10 by @sharwell in #4081, completed by @AArnott in #4120
- Fixes 13 instances of IDE00250 and IDE0251 by @jsrustad in #3958
- Fixes 9 instance of code causing IDE0038 by @jsrustad in #3952
- Add a C# 15 preview test project by @AArnott in #4125
- Update lightup Syntax.xml to Roslyn 5.9.0 by @AArnott in #4124
- Remove leftover OpenCover and CodecovUploader tooling by @AArnott in #4129
- CI: fail when checked-in generated files are stale by @AArnott in #4130
- Fixes IDE0052 and IDE0270 by @jsrustad in #3960
- Use the standard .NET gitignore by @alexander-efremov in #4169
- Add C# 12 language feature audit tests by @AArnott in #4141
- C# 13: add 'allows ref struct' tests (with .NET 9 reference assemblies) by @AArnott in #4146
- Speed up the CI jobs with server GC for the tests and less MSBuild and NuGet overhead by @alexander-efremov in #4153
- Update the GitHub Actions to their Node.js 24 versions by @alexander-efremov in #4167
- Add C# 11 language feature audit tests by @AArnott in #4136
- C# 14: add audit tests (lambda parameter modifiers, compound assignment operators, null-conditional assignment, nameof unbound generics) by @AArnott in #4151
- Add C# 10 language feature audit tests by @AArnott in #4132
- C# 13: add audit tests (escape sequence, implicit index, params collections, ref struct interfaces) by @AArnott in #4145
- Fix or suppress IDE0079 warnings by @jsrustad in #3962, completed by @AArnott in #4168
- C# 14: add extension block tests for rules that already handle them by @AArnott in #4164
- Add tests for types with primary constructors (stacked on #4142) by @AArnott in #4143
- C# 14: add field keyword tests (field-backed properties) by @AArnott in #4165
- Default the C# 15 test project to the preview language version by @AArnott in #4192
- Lightup: implement SeparatedSyntaxListWrapper equality instead of throwing by @AArnott in #4206
- Merge SA1206 diagnostic and code fix test classes by @AArnott in #4207
- Check repository markup links with mlc in GitHub Actions by @AArnott in #4219
- Skip GitHub URLs in markup link checks by @AArnott in #4223
- Cleanup: Remove redundant references from test projects by @bjornhellander in #4227
- Remove redundant test class analyzer by @AArnott in #4230
- Configure Renovate by @renovate[bot] in #4231
- Slnx by @AArnott in #4232
- Update dependency DotNetAnalyzers.DocumentationAnalyzers to 1.0.0-beta.59 by @renovate[bot] in #4233
- Update dependency Newtonsoft.Json to 13.0.4 by @renovate[bot] in #4234
- Update dependency Microsoft.NET.Test.Sdk to v18 by @renovate[bot] in #4237
- Update dependency Nerdbank.GitVersioning to 3.10.94 by @renovate[bot] in #4236
- Migrate to NuGet CPVM by @AArnott in #4238
- Update dependency dotnet-reportgenerator-globaltool to v5.5.11 by @renovate[bot] in #4240
- Update dotnet monorepo by @renovate[bot] in #4239
- Update dependency LibGit2Sharp to 0.32.0 by @renovate[bot] in #4241
- Update dependency Microsoft.Build.Locator to 1.11.2 by @renovate[bot] in #4242
- Update actions/setup-node action to v7 by @renovate[bot] in #4243
- Update dependency Xunit.Combinatorial to 1.7.31 by @renovate[bot] in #4248
- Update dependency NuGet.Resolver to 7.9.0 by @renovate[bot] in #4246
- Update dotnet monorepo (major) by @renovate[bot] in #4251
- Support xUnit runner 4 in language test projects by @AArnott in #4247
- Migrate tests to xUnit v3 for Xunit.Combinatorial v2 by @AArnott in #4253
- Update dependency DiffPlex to 1.9.0 by @renovate[bot] in #4252
- Pin Microsoft.Build.Framework to 18.9.6 for .NET 10 compatibility by @AArnott in #4254
- Replace AsyncUsageAnalyzers with VS threading analyzers by @AArnott in #4255
New Contributors
- @kvpt made their first contribution in #3762
- @SapiensAnatis made their first contribution in #3777
- @DoobieAsDave made their first contribution in #3820
- @alexrp made their first contribution in #3842
- @MattFromRVA made their first contribution in #3861
- @eXpl0it3r made their first contribution in #3905
- @csaba-sagi-sonarsource made their first contribution in #3356
- @ds1709 made their first contribution in #3335
- @CPAM34 made their first contribution in #3140
- @JEFFTheDev made their first contribution in #3333
- @6bee made their first contribution in #3879
- @FantasyTeddy made their first contribution in #3936
- @DWIAltonaAnalytics made their first contribution in #3927
- @alexander-efremov made their first contribution in #4115
- @jsrustad made their first contribution in #3958
- @DavidCizek made their first contribution in #3944
- @verdie-g made their first contribution in #4096
- @SergeyZhurikhin made their first contribution in #3900
- @renovate[bot] made their first contribution in #4231
Full Changelog: 1.2.0-beta.556...1.3.1-beta