github DotNetAnalyzers/StyleCopAnalyzers 1.3.180

2 hours ago

This is the first stable StyleCop.Analyzers release since 1.1.118. It includes the entire 1.2 beta line and the 1.3 revival: the analyzers now understand C# 8 through the C# 15 previews, many long-standing bugs are fixed, and the project is once again actively maintained. Thank you to everyone who contributed code, reviews, translations and bug reports over the long gap.

Highlights

  • C# 8 through C# 15 language support. Rules now understand 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, instead of ignoring that syntax or crashing on it. (#4142, #4139, #4137, #4163, #4148, #4191, #4193)
  • New rules. SA1143 checks that wrapped conditional (?:) expressions are laid out consistently, SA1315 requires overriding and implementing parameters to keep their inherited names, SA1317 reports identifiers that use letters outside basic Latin A–Z, SA1653 reports <summary> documentation on more than one part of a partial type, and SA1654 reports escaped generic brackets in crefs (for example List&lt;T&gt; vs List{T}). SX1412 is an opt-in alternative to SA1412 that requires UTF-8 without a BOM. All of these except SX1412 are on by default as warnings. (#3942, #4299, #4318, #4314, #4315, #4328)
  • Better code fixes. The member-ordering rules (SA1201, SA1202, SA1203, SA1204 and SA1214) now offer their code fix, including Fix All. Many other rules gained fixes, and existing fixes keep comments, trivia, custom indentation and the document's line endings, and use the compiler's batch Fix All. (#4312, #4076, #4199, #4108, #4229, #4360)
  • More configuration. Every setting can be set in .editorconfig. New settings include orderingRules.memberKindOrder, orderingRules.accessibilityOrder and layoutRules.allowBracelessIfStatements (braceless ifs are off by default; the accessibility order default is unchanged). (#4221, #3285, #4324, #4359, #4319)
  • Fewer false positives and crash fixes. A long backlog of spacing, layout, documentation, naming and maintainability issues was cleared, including several crashes and incorrect code fixes found by fuzzing.
  • Localization and documentation. This release adds Simplified Chinese (zh-CN) resources and documentation, finishes the Czech translations, and includes more translations of code-fix documentation text (Czech, Dutch, Russian and others). Rule documentation and status are published on GitHub Pages. (#4285, #4286, #3374, #3944, #3900, #4220, #4218)
  • Packaging and engineering. The package has an icon and a README, and PDBs are embedded in the DLLs (there is no separate symbols package). Packages are published from GitHub Actions using nuget.org trusted publishing. CI runs on GitHub Actions on Linux, the build uses the .NET 10 SDK, and Renovate keeps dependencies current. The analyzers still target the same Roslyn version, so they work with the same compilers and IDEs as before. (#4320, #4204, #4173, #4123, #4105, #4126, #4231)

Behavior changes worth knowing about

Upgrading from 1.1.118, or from a 1.2 beta, 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.
  • New rules on by default: SA1143, SA1315, SA1317, SA1653 and SA1654 are enabled as warnings. SX1412 is off by default.
  • 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 types and members. For partial methods, properties, indexers, constructors, events and types, documenting one part is enough (SA1600 leaves the check for partial members to SA1601). SA1653 reports a <summary> on more than one part, but ignores generated partial declarations such as WPF *.g.cs files. (#4148, #4149, #4152, #4308, #4299, #4393)
  • SA1500 and SA1137 now check the brackets of multi-line collection expressions. SA1137 accepts aligning a closing bracket with an inline opening bracket (one that follows other code on the same line) or with the opening line's indentation. Both rules offer an alternate, tab-aware code fix that aligns the closing bracket with the opening bracket. (#4396, #4400)
  • SA1642 expects "union" wording in constructor summaries of C# 15 union types, for example "Initializes a new instance of the … union.", and "interface" rather than "class" in the standard text for static constructors in interfaces. (#4193, #4386)
  • SA1121 reports the built-in type inside a using alias target instead of every use of the alias, and no longer reports IntPtr and UIntPtr in XML documentation crefs, or in shared source compiled for targets where nint isn't equivalent. SA1121 and SA1125 also report System types in using alias targets. (#4287, #4395, #4175)
  • SA1316 always reports explicitly written tuple element names, even when includeInferredTupleElementNames is off. (#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 reports empty interpolated and raw string literals, and SA1130 reports anonymous methods whose parameter names differ from the delegate's. (#4178, #4179)
  • SA1407 now checks bitwise operators (&, |, ^) and >>>. SA1408 reports ?? mixed with && or || without parentheses. (#4289, #4323)
  • SA1200 reports and moves extern alias directives using the same placement setting as using directives. (#4313)
  • SA1017 requires a space after a parameter's or type parameter's attribute list, for example [NotNullWhen(true)] out string? foo. (#4321)
  • SA1633: disabling one required-header rule, for example SA1637, no longer turns off the other header checks. (#4276)
  • SA1202 treats explicit interface events as public, like other explicit interface members. SA1137 aligns type members to their most common indentation instead of the first member. SA1649 picks the type that names the file according to the maintainabilityRules.topLevelTypes setting. (#4281, #4301, #4316)
  • SA1600 respects the documentInterfaces setting. With documentInterfaces: false, public interfaces and their members are still required when documentExposedElements is on. With documentInterfaces: "exposed", members of interfaces that aren't actually exposed are not reported. (#3140, #4346, #4343)
  • SA1135 no longer reports using directives that start with an extern alias. (#4341)
  • SA1143 allows branches that continue onto more lines, and accepts an expanded conditional whose condition spans several lines when the ? and : lines line up and are indented past the condition's last line. The SA1143 code fix keeps multi-line branches intact. (#4336, #4374, #4392)
  • 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

Enhancements

Documentation

Infrastructure and build

New Contributors

Full Changelog: 1.1.118...1.3.180

Don't miss a new StyleCopAnalyzers release

NewReleases is sending notifications on new releases.