Skip to content

refactor: reduce cognitive complexity (S3776)#4994

Merged
arturcic merged 14 commits into
GitTools:mainfrom
arturcic:fix/sonar-s3776-cognitive
Jun 30, 2026
Merged

refactor: reduce cognitive complexity (S3776)#4994
arturcic merged 14 commits into
GitTools:mainfrom
arturcic:fix/sonar-s3776-cognitive

Conversation

@arturcic

Copy link
Copy Markdown
Member

Reduces SonarCloud S3776 (cognitive complexity > 15) on several methods, one commit per method. All changes are behaviour-preserving refactors — no logic changes.

Method Before Approach
MergeCommitOnNonTrunkBase.GetIncrements 16 extract ConsolidateIncrement / ApplyBaseVersion
EffectiveBranchConfigurationFinder.GetEffectiveConfigurationsRecursive 17 flatten nested ifs into early yield breaks
AssemblyInfoFileUpdater.Execute 17 extract per-file UpdateAssemblyInfoFile
ProjectFileUpdater.Execute 19 extract per-file UpdateProjectFile
OutputGenerator.Execute 22 split into WriteDotEnv/WriteJsonToFile/WriteJsonToConsole; remove an unreachable trailing switch

More S3776 fixes will follow on top of this branch (GitVersionCacheKeyFactory, NextVersionCalculator, RepositoryStore, GitPreparer, ArgumentParser, SemanticVersion, MainlineVersionStrategy).

Verification

  • dotnet build — 0 warnings / 0 errors
  • dotnet format --verify-no-changes — clean
  • Tests green: full Core suite 36119, Output.Tests 369, App.Tests 663 (per method, on the relevant suite)

🤖 Generated with Claude Code

arturcic and others added 14 commits June 30, 2026 08:55
Extract the increment consolidation and base-version application out of the
GetIncrements iterator into ConsolidateIncrement and ApplyBaseVersion helpers.
Behaviour-preserving.

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

Flatten GetEffectiveConfigurationsRecursive with early yield breaks instead of nested
if/else. Behaviour-preserving.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Extract the per-file work from Execute into UpdateAssemblyInfoFile and inline the version
strings into their guarded conditionals. Behaviour-preserving.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Extract the per-file work from Execute into UpdateProjectFile (continue becomes return).
Behaviour-preserving.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Split Execute into WriteDotEnv / WriteJsonToFile / WriteJsonToConsole helpers and remove
the unreachable trailing switch (ShowVariable/Format are both already handled above).
Behaviour-preserving.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Extract TryGetDirectories, TryGetFiles and AddFileContents out of
CalculateDirectoryContents. Behaviour-preserving (null return mirrors the previous
catch-and-continue).

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Extract the nested base-version loops into GetNextVersions overloads and
an OrderStrategiesWithFallbackLast helper. Behavior-preserving.

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

Extract the merge-ignore collection, cross-branch pruning, and per-group
yielding into private helpers. Behavior-preserving.

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

Split the increment switch, alternative-version selection, and version
building into focused helpers; collapse the duplicated return paths.
Behavior-preserving.

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

Move the cross-iteration cursor into a TraversalState type and split the
loop body into ApplyBranchedFromTransition, ProcessCommit, and
HandleMergeCommit helpers. Behavior-preserving.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Extract the nested line/column position selection into a flat
GetPositionFormat helper. Behavior-preserving.

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

Extract the boolean-flag switches into a ParseBooleanArguments helper,
mirroring the existing ParseConfigArguments/ParseRemoteArguments pattern.
Behavior-preserving.

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

Extract local canonical name resolution and the create-or-update local
branch logic into helpers. Behavior-preserving.

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

Return (Content, Appended) from ReplaceOrInsertAfterLastAssemblyAttributeOrAppend
instead of mutating a ref bool, and OR-accumulate the appended flag at the
call sites. Removes the ref-mutation that tripped Sonar's S2583 false positive
(condition always false / unreachable code). Behavior-preserving.

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

Copy link
Copy Markdown

@arturcic
arturcic merged commit a712258 into GitTools:main Jun 30, 2026
120 checks passed
@arturcic
arturcic deleted the fix/sonar-s3776-cognitive branch June 30, 2026 09:04
@mergify

mergify Bot commented Jun 30, 2026

Copy link
Copy Markdown
Contributor

Thank you @arturcic for your contribution!

@arturcic arturcic modified the milestones: 6.x, 6.8.0 Jun 30, 2026
@arturcic

Copy link
Copy Markdown
Member Author

🎉 This issue has been resolved in version 6.8.0 🎉
The release is available on:

Your GitReleaseManager bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant