Skip to content

refactor: SonarQube code-smell & duplication cleanup#25

Open
HandyS11 wants to merge 9 commits into
developfrom
feat/sonar-cleanup
Open

refactor: SonarQube code-smell & duplication cleanup#25
HandyS11 wants to merge 9 commits into
developfrom
feat/sonar-cleanup

Conversation

@HandyS11

Copy link
Copy Markdown
Owner

Cleans up the SonarQube maintainability smells (82) and the structural duplication (8.4% density, 1,551 lines), sequenced low-risk → high-risk with the test suite green at every commit.

What changed

Mechanical:

  • chore(sonar): exclude auto-generated EF migrations + obj/bin from analysis (CPD noise).
  • style: analyzer auto-fixes (collection init, var, switch expr, UTF-8 literals). Two fixes deliberately left as-is where they conflict with other analyzers (nested-ternary S3358, primary-ctor CA2000).
  • S1192: extracted repeated string literals to private const.
  • IDE0130: moved 8 RustPlusBot.Abstractions.Connections types to the namespace matching their folder, updating ~69 consumers (the shared using was kept where genuine Features.Connections.Listening types are still referenced).

Structural (the duplication):

  • RustPlusBot.Localization (new project): shared ILocalizer + DictionaryLocalizer replace 6 byte-identical per-feature localizer implementations. The 6 IXLocalizer interfaces are kept as thin markers extending the shared one, so per-feature DI registrations stay distinct (no last-wins collision). Resolves the in-code "consolidate into a shared project" TODO.
  • CachingChannelLocator: abstract base + 5 sealed subclasses collapse the near-identical Event/Map/Switch/Alarm/TeamChat locators (each was ~75 lines → ~10).
  • DiscordChannelMessenger: shared post/edit boilerplate for 4 posters (Switch/Alarm self-heal EnsureAsync, Event/Player fire-and-forget PostAsync). The Map poster (posts a file) and Alarm's SendEveryonePingAsync are intentionally left separate.

Other smells:

  • S107: bundled cohesive constructor dependencies into record types on 6 ctors + 1 method (all now ≤7 params).
  • S3776: extracted helpers to drop cognitive complexity <15 in MapRenderer.DrawPlayers, ServerInfoMessageRenderer.RenderAsync, ConnectionSupervisor.RunConnectedAsync.

Notes for review

  • Net −205 LOC despite adding a new project + its tests.
  • 531 tests across 13 assemblies green; dotnet jb cleanupcode --profile=ReformatAndReorder produces zero diff (format gate passes).
  • TeamChat's ResolveAsync moved from an O(1) dedicated reverse-dict to an O(n) scan of the forward map — equivalent under the data model (a channel can't map to two server keys), negligible volume.
  • The poster extraction incidentally fixed a pre-existing structured-log bug where {MessageId}/{ChannelId} were bound to swapped values (human-readable message unchanged).
  • The empirical SonarQube smell/duplication delta will only show after this lands on develop — Community-Edition Sonar analyzes the single long-lived branch only.

🤖 Generated with Claude Code

HandyS11 and others added 9 commits June 23, 2026 01:54
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
…UTF-8 literals)

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
…IDE0130)

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
…alizer + DictionaryLocalizer)

Collapses 6 byte-identical per-feature localizer implementations into one
shared DictionaryLocalizer + ILocalizer in a new leaf project. The 6
per-feature interfaces are kept as thin markers extending the shared
ILocalizer, and each feature keeps a 1-line concrete localizer that
subclasses DictionaryLocalizer and implements its marker — so DI
registrations and ~30 consumers are unchanged and there is no last-wins
DI collision in the composed host container.

Resolves the in-code 'consolidate into a shared project' TODO.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
…nnelLocator

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
…nelMessenger

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
…776)

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
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.

1 participant