Skip to content

feat: NE0003 — only one namespace declaration per file - #13

Merged
samtrion merged 2 commits into
mainfrom
feat/ne0003-single-namespace
Aug 3, 2026
Merged

feat: NE0003 — only one namespace declaration per file#13
samtrion merged 2 commits into
mainfrom
feat/ne0003-single-namespace

Conversation

@samtrion

@samtrion samtrion commented Aug 3, 2026

Copy link
Copy Markdown
Contributor

Summary

Implements NE0003: a file should declare exactly one namespace. A file that declares more than one namespace (sibling or nested) hides types from the name↔location mapping the other organization rules establish, and complicates NE0001/NE0002.

Stacked on #12 (NE0002). It reuses the shared FolderNamespace helper introduced there. Review/merge #12 first; the base will retarget to main once #12 lands.

Non-compliant

// Types.cs — two sibling namespaces
namespace Geometry.Shapes { public sealed class Circle { } }
namespace Geometry.Solids { public sealed class Sphere { } }   // NE0003

// nested namespaces
namespace Geometry { namespace Shapes { public sealed class Circle { } } }  // NE0003 on the inner one

Behavior

  • Flags every namespace declaration except the first (in document order), for both sibling and nested shapes.
  • Honors the file-organization opt-outs (PublishSingleFile, NetEvolveAnalyzerDisableFileOrganizationRules) and skips generated code.

Code fix

  • Nested namespaces are flattened into a single file-scoped namespace whose value matches the folder-derived namespace (via FolderNamespace), falling back to the concatenated nesting (e.g. Outer.Inner) when no RootNamespace/ProjectDir anchor is available.
  • Multiple sibling namespaces are intentionally left to NE0001's move-type fix, so no action is offered for that shape.

Unit + integration tests and docs/rules/NE0003.md included.

Closes #5

@coderabbitai

coderabbitai Bot commented Aug 3, 2026

Copy link
Copy Markdown

Important

Review skipped

Auto reviews are limited based on label configuration.

🏷️ Required labels (at least one) (1)
  • state:ready for merge

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: e4b0f881-16f9-48b8-a3ee-2de00379a561

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

Base automatically changed from feat/ne0002-namespace-folder to main August 3, 2026 14:35
Report when a single file declares more than one namespace, whether sibling
or nested (block- and file-scoped). A file that declares multiple namespaces
hides types from the name-to-location mapping the other organization rules
establish, and complicates NE0001/NE0002. Exactly one namespace per file.

- SingleNamespacePerFileAnalyzer flags every namespace declaration except the
  first, and records whether the reported declaration is nested
- Code fix flattens the nested case into a single file-scoped namespace that
  matches the folder-derived namespace (via the shared FolderNamespace
  helper), falling back to the concatenated nesting when no anchor is
  available; the multiple-sibling case is left to NE0001's move-type fix
- Honors the file-organization opt-outs and skips generated code
- Unit + integration tests, docs/rules/NE0003.md

Closes #5
@samtrion
samtrion force-pushed the feat/ne0003-single-namespace branch from bed9ebc to e57ed3e Compare August 3, 2026 14:40
@codecov

codecov Bot commented Aug 3, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 98.07692% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 98.84%. Comparing base (26f0ef5) to head (fe69e60).

Files with missing lines Patch % Lines
...inability/SingleNamespacePerFileCodeFixProvider.cs 96.72% 0 Missing and 2 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main      #13      +/-   ##
==========================================
- Coverage   99.08%   98.84%   -0.25%     
==========================================
  Files           7        9       +2     
  Lines         328      432     +104     
  Branches       62       84      +22     
==========================================
+ Hits          325      427     +102     
- Partials        3        5       +2     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Raise NE0003 patch coverage over the 95% gate by exercising the analyzer and
flatten fix from both the unit and integration flags:

- Add an AdhocWorkspace-based runner to the unit suite so the flatten fix runs
  end-to-end there too (a line hit by only one flag counts as a partial)
- Cover the member-rendering branches (leading/interior blank lines, usings,
  enum and delegate members, trailing-newline style, folder-derived vs
  concatenated target)
- Add the analyzer null-argument guard and the PublishSingleFile /
  DisableFileOrganizationRules opt-outs to the integration suite
@samtrion
samtrion merged commit 53f1082 into main Aug 3, 2026
9 checks passed
@samtrion
samtrion deleted the feat/ne0003-single-namespace branch August 3, 2026 15:13
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.

analyzer: NE0003 — only one namespace declaration per file

1 participant