Skip to content

analyzer: NE0001 code fix — rename file / move type to its own file #7

Description

@samtrion

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:

  1. 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.
  2. 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

  • OneTypePerFileCodeFixProvider implemented in src/NetEvolve.Analyzer/Maintainability/
  • Code-fix tests via CSharpCodeFixVerifier (rename + move-to-file, incl. generics & partial)
  • Coverage gates met (unit >75%, integration >80%, project >90%, patch >95%)
  • docs/rules/NE0001.md updated: code fix available

Metadata

Metadata

Assignees

No one assigned

    Labels

    state:investigateIndicates issues requiring further investigation to understand or gather information.type:featureIndicates a new feature or enhancement to be added.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions