chore: simplify serialization codegen and fix RS2007 release tracking#7
Conversation
Code-quality cleanup (no behavior change):
- AliasCodeGenerator (serialization converter codegen):
- For string-backed newtypes, emit a single string arm instead of
duplicate `typeof(string) || typeof(string)` conditions and
unreachable `is string` / `destinationType == typeof(string)`
branches (T == string makes typeof(T) == typeof(string)).
- Cache the underlying TypeConverter in a `static readonly _inner`
field instead of calling TypeDescriptor.GetConverter(typeof(T))
on every ConvertFrom/ConvertTo (emitted only for the non-string
path that uses it).
- AliasModelExtractor:
- ToLocationStruct: call GetLineSpan() once via `.Span` instead of
twice.
- Drop a no-op `.Where(x => x is not null)` over GetAttributes()
(Roslyn never returns null elements).
- AnalyzerReleases.Unshipped.md: rewrite the rules table into the
strict analyzer-release-tracking format (no surrounding pipes, bare
category) so NEWTYPE001/NEWTYPE002 are actually tracked and RS2007
no longer warns.
Full solution builds with 0 warnings; 395/395 tests pass (Debug).
|
Caution Review failedThe pull request is closed. ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (3)
WalkthroughThe source generator's ChangesTypeConverter string specialization and generator cleanup
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Possibly related PRs
Poem
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Code-quality cleanup from a
/simplifypass over the recently-merged work (serialization + constraints). No behavior change.Serialization converter codegen (
AliasCodeGenerator)[newtype<string>],typeof(T)istypeof(string), so the generatedTypeConverterpreviously contained duplicate conditions (typeof(string) || typeof(string)) and unreachableis string/destinationType == typeof(string)branches. Now gated onAliasedTypeSpecialType == System_Stringto emit a single string arm.ConvertFrom/ConvertTore-ranTypeDescriptor.GetConverter(typeof(T))on every call. Now resolved once into astatic readonly _innerfield (emitted only for the non-string path that uses it).AliasModelExtractorToLocationStructcalledGetLineSpan()twice; now once via.Span..Where(x => x is not null)overGetAttributes()(Roslyn never returns null elements).Release tracking (
AnalyzerReleases.Unshipped.md)RS2xxxrelease-tracking parser rejects →RS2007warning, and theNEWTYPE001/NEWTYPE002entries were silently discarded (not actually tracked).Category).Category/Severitymatch theDiagnosticDescriptors, so the entries validate andRS2007is gone.Validation
_innerfield and a singletypeof(string)term; int newtype has one cached_inner.Need help on this PR? Tag
/codesmithwith what you need. Autofix is disabled.Summary by CodeRabbit
Bug Fixes
TypeConverterclasses, with better handling of conversion scenarios.Refactor
Documentation