github DotNetAnalyzers/StyleCopAnalyzers 1.3.1-beta

pre-release6 hours ago

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 the field keyword, and C# 15 preview unions with the closed and safe modifiers. (#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 alongside stylecop.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 includeInferredTupleElementNames is off. Names the compiler infers are still checked only when that setting is on. (#4202)
  • SA1312 no longer reports _ for foreach variables and using declarations. (#4203)
  • SA1205 treats the file modifier as an access modifier. (#4198)
  • SA1304 now analyzes protected readonly fields 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 documentInterfaces setting 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.nupkg is 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.json schema to have correct default for headerDecoration. 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)

New Contributors

Full Changelog: 1.2.0-beta.556...1.3.1-beta

Don't miss a new StyleCopAnalyzers release

NewReleases is sending notifications on new releases.