Skip to content

Fix every Roslyn and Roslynator finding, or suppress it in source with its reason - #318

Merged
electricessence merged 5 commits into
masterfrom
chore/roslyn-pass
Dec 4, 2026
Merged

electricessence merged 5 commits into
masterfrom
chore/roslyn-pass

Conversation

@electricessence

Copy link
Copy Markdown
Collaborator

Every finding the Roslyn tools report at any severity, in every project, now fixed at its root or suppressed in source at the narrowest level with its reason beside it. No behavior change and no public API change.

  • Core usings. Two directives that no target framework uses are removed (CaptureNames, the output-parameter part of ExpressiveCommandBase). System.Runtime.InteropServices in ChunkChain and PooledArray is used only for CollectionsMarshal, which exists from .NET 8, so it now sits inside the same #if NET8_0_OR_GREATER that guards its use.
  • Tests and samples. Redundant casts (IDE0004) and an unnecessary null-forgiving operator (IDE0370) are removed. The legacy package's extension class is called as an instance method where Roslynator asks for it (RCS1196), and a fake transaction is disposed with await using in an async test (RCS1261). The docs sample compares with Length instead of "" (RCS1156) and loses a comment that described the removed cast.
  • Suppressed, not fixed, with a reason. A block-bodied discard lambda passed to Assert.Throws stays a block (an expression body binds to the Func<Task> overload that xUnit rejects, RCS1021): 14 test methods carry [SuppressMessage] with one shared reason constant. In the benchmarks the reader keeps its synchronous dispose, because the published numbers measure that call (RCS1261): 12 methods, one shared reason constant. A property over an initialized backing field and a retired parameter are the cases under test (RCS1085, RCS1163).
  • Fixed, not suppressed. RCS1158 (static member in a generic type): the benchmark variant names move to non-generic holders and the ParamsSource member becomes an instance method, which BenchmarkDotNet resolves on the concrete benchmark type. Checked by listing the benchmarks and by a negative control that names a missing member and fails as it should.

Left on purpose: 29 findings that only some target frameworks of Core report (IDE0370, IDE0390), because fixing them for one framework breaks another.

Counts (before → after). Roslyn scan with every style rule as a warning, per project and target framework: 10 actionable → 0. Roslynator, all severities, 14 projects: 48 sites → 0. dotnet format style and analyzers at info, 14 projects: 0 → 0 (it was blind to these: it reports only rules that have a code fix).

Verification: solution Release build with no incremental state 0 warnings, 0 errors; Visual Studio's MSBuild on the whole solution, Debug and Release, 0 errors; Core.Tests Release 16231 passed, Debug 16210 passed and 16 self-skipped; generator tests 189 passed; 267 sample checks; docfx 0 warnings; Benchmarks and Benchmarks.Generated Release builds 0 warnings; style scan clean; no PublicAPI diff.

🤖 Generated with Claude Code

electricessence and others added 5 commits December 4, 2026 08:49
Two files in Core had a using directive that no code in them uses on any
target framework (CaptureNames and the output-parameter part of
ExpressiveCommandBase). Two more (ChunkChain and PooledArray) use
System.Runtime.InteropServices only for CollectionsMarshal, which exists from
.NET 8, so on the netstandard targets the directive was unused there; it is now
inside the same #if NET8_0_OR_GREATER that guards its use.

No behavior change and no public API change.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Redundant casts (IDE0004) and an unnecessary null-forgiving operator (IDE0370)
are removed in Core.Tests, Generator.Tests and the docs sample, together with
the sample comment that described the cast. A test that used the legacy
package's extension class by name now calls the extension as an instance
method (RCS1196), and its unused alias is gone. A fake transaction is disposed
with await using in an async test (RCS1261). The docs sample compares a string
with Length instead of with "" (RCS1156).

Where the finding cannot be fixed without changing what the test checks, it is
suppressed in source with the reason beside it: block-bodied discard lambdas
passed to Assert.Throws (an expression body would bind to the Func<Task>
overload that xUnit rejects, RCS1021), a property over an initialized backing
field and a retired parameter that are the cases under test (RCS1085, RCS1163).

Tests only; no test asserts anything different.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
The benchmarks keep the synchronous dispose of the data reader, a static member
the benchmark class has to own for BenchmarkDotNet, and the single field of an
inline array. Each Roslynator finding about them (RCS1261, RCS1158, RCS1213,
RCS1169) is suppressed in source around exactly that code, with the reason
beside it. Changing any of them would change what the benchmarks measure or
whether they compile.

No code change.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Suppression is now at method level, with each reason written once.

- RCS1021 (block-bodied discard lambdas passed to Assert.Throws): the
  file-level pragmas in three test files are gone. The 14 test methods that
  need a block body carry [SuppressMessage] with one shared reason constant.
- RCS1261 (await using) in the benchmarks: the two block pragmas over the async
  sections are replaced by [SuppressMessage] on each of the 12 benchmark
  methods, with one shared reason constant. The reader still disposes
  synchronously, so what the benchmarks measure is unchanged.
- RCS1158 (static member in a generic type) is fixed, not suppressed: the
  variant names move to non-generic holders (the checks read them from there)
  and the ParamsSource member becomes an instance method, which
  BenchmarkDotNet resolves on the concrete benchmark type.
- One reason names both IDE0032 and RCS1085, and a test with two long lines
  and a split call is wrapped.

No test asserts anything different and no benchmark body changed.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
…olders

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@electricessence
electricessence merged commit 949386f into master Dec 4, 2026
9 checks passed
@electricessence
electricessence deleted the chore/roslyn-pass branch December 4, 2026 18:10
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.

1 participant