Follow-up to #3 (NE0001 analyzer) · part of the file/namespace organization epic #6 · Category: Maintainability
Need & Action (Bedarf & Handlung)
Need: The NE0001 analyzer (#3) reports diagnostics but ships no automatic fix, so every violation must be
resolved by hand.
Action: Add a CodeFixProvider for NE0001 offering two code actions, mirroring StyleCop's SA1649/SA1402
fixes:
- Rename the file to match the type — for the single-type name-mismatch case. The target name honours
the current mode: TypeName.cs, the arity-encoded Result{T}.cs in strict mode, or the base identifier
Result.cs when NetEvolveAnalyzerGroupGenericOverloads is enabled.
- Move the type into its own file — for the multiple-types case: create a new document named after the
flagged type and remove the type from the original file.
Impact
- Turns NE0001 from advisory into one-click-fixable; makes enabling it on an existing code base practical.
- Interacts with partial types (all parts must move/rename consistently) and the generic arity naming.
Non-compliant example
// File: Shapes.cs
namespace Geometry;
public sealed class Circle { } // NE0001
public sealed class Square { } // NE0001
Compliant example (after fix)
// File: Circle.cs
namespace Geometry;
public sealed class Circle { }
// File: Square.cs
namespace Geometry;
public sealed class Square { }
Category
Maintainability
Default severity
n/a (code fix for NE0001)
Code fix
Yes — this issue is the code fix.
Edge cases & exceptions
- Partial types: renaming/moving must keep all partial parts consistent; a partial spread across files
should rename every part's file.
- Generic arity naming: the rename target must match the analyzer's
ArityEncodedFileName exactly
(Result{T}.cs, Result{T1,T2}.cs) so the fix does not re-trigger the diagnostic.
- Grouped overloads: when grouping is enabled the fix must not split overloads that are allowed to share
a file.
- Move-to-file: carry over the enclosing namespace (file-scoped vs block), relevant
using directives,
and leading trivia/doc comments; skip generated files.
- Testable via the existing
CSharpCodeFixVerifier (supports document rename and multi-document fixes).
Definition of Done
Need & Action (Bedarf & Handlung)
Need: The NE0001 analyzer (#3) reports diagnostics but ships no automatic fix, so every violation must be
resolved by hand.
Action: Add a
CodeFixProviderfor NE0001 offering two code actions, mirroring StyleCop's SA1649/SA1402fixes:
the current mode:
TypeName.cs, the arity-encodedResult{T}.csin strict mode, or the base identifierResult.cswhenNetEvolveAnalyzerGroupGenericOverloadsis enabled.flagged type and remove the type from the original file.
Impact
Non-compliant example
Compliant example (after fix)
Category
Maintainability
Default severity
n/a (code fix for NE0001)
Code fix
Yes — this issue is the code fix.
Edge cases & exceptions
should rename every part's file.
ArityEncodedFileNameexactly(
Result{T}.cs,Result{T1,T2}.cs) so the fix does not re-trigger the diagnostic.a file.
usingdirectives,and leading trivia/doc comments; skip generated files.
CSharpCodeFixVerifier(supports document rename and multi-document fixes).Definition of Done
OneTypePerFileCodeFixProviderimplemented insrc/NetEvolve.Analyzer/Maintainability/CSharpCodeFixVerifier(rename + move-to-file, incl. generics & partial)docs/rules/NE0001.mdupdated: code fix available