Repository navigation
feat(analyzers): add union rule family E128219-E128221 - #158
Merged
Merged
Conversation
Co-Authored-By: Claude
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Executive Summary
Adds three union-aware design rules to the E128.Analyzers package, written against the typed
UnionDeclarationSyntax. The typed node sits behindRSEXPERIMENTAL006at the pinned Roslyn 5.9.0 band; the maintainer approved that suppression, which both component csproj files now carry.closedhierarchy replaces. Code fix replaces theabstractmodifier with theclosedkeyword and keeps trivia. Skips a base that already carriesclosed(closedalone implies abstract, per CS0144 probe).vararm instead of anullarm. Code fix replaces a discard pattern with anullconstant pattern; avararm binds a value, so the fixer skips it. Probe finding:case _on a union governing type parses_as a case-type identifier (CS0103), so a statement catch-all iscase var _:.Valueread or cast outside a pattern match. No code fix, because the conversion changes control flow.Shared helper
UnionTypes.IsUnionaccepts a source union throughUnionDeclarationSyntaxor a binary/hand-written union through the compiler-synthesizedIUnioninterface, matched by name and namespace chain because no metadata lookup resolves it.Code Changes
src/E128.Analyzers/Design/: three new analyzers plusUnionTypes.cssrc/E128.Analyzers.CodeFixers/Design/: two new code fix providersAnalyzerReleases.Shipped.mdunder 2.10.0,PublicAPI.Unshipped.txtentries, README rule rows and sectionsRSEXPERIMENTAL006NoWarnadditions, version 2.9.8 to 2.10.0, README install snippet updatedTests and Tooling
UnionTestRuntime, a source stub forUnionAttribute,IsClosedTypeAttribute, andIUnion, because the net10.0 reference assemblies predate the union runtime. Fixture settings:LanguageVersion.Previewand anRSEXPERIMENTAL006suppression.scripts/check.sh) green: format, build, and the full suite, 2928 passed with 2 pre-existing skips. Test gate ran on the union sources before the commit; the docs-only and release-file follow-up edits did not rerun the suite.analyzer-release-check,readme-table-diff --analyzer, andreadme-auditall clean after promotion.Review Guide
Start with
UnionTypes.csfor the detection contract, then each analyzer. The two-pass compilation-end shape of E128219 mirrorsSealedByDefaultAnalyzer(E128005). Code fix tests for the compilation-end rule setSkipLocalDiagnosticCheckandNumberOfFixAllIterations = 1, the shapelode/dotnet/analyzers/testing.mdrecords.Rollback
Revert this single commit; the change set is self-contained to the analyzer package, its tests, and the release/README files.
🤖 Generated with Claude Code