Skip to content

Deduplicate the delimiter-separated casing validators - #160

Merged
matt-edmondson merged 1 commit into
mainfrom
chore/sonar-casing-dedup
Aug 14, 2026
Merged

Deduplicate the delimiter-separated casing validators#160
matt-edmondson merged 1 commit into
mainfrom
chore/sonar-casing-dedup

Conversation

@matt-edmondson

Copy link
Copy Markdown
Contributor

Follow-up to #158, which merged while this last piece was still in flight.

#158 failed the quality gate on new_duplicated_lines_density (9.0% against a 3% threshold). The cause was pre-existing, not introduced: the kebab, snake and macro validators were 44–60% duplicated against each other as whole files, so touching any line inside those blocks counts as new duplicated code. Coverage on that PR reached 100%, and all three quality ratings were A — duplication was the only remaining condition.

All three validators implement the same five rules and differ in exactly three values: the delimiter, the delimiter belonging to a different convention that must not appear, and the required letter case. That is now DelimitedCaseValidation.Validate, leaving each validator a single delegating expression:

protected override ValidationResult ValidateValue(string value) =>
    DelimitedCaseValidation.Validate(value, -, _, char.IsLower, FailureMessage);

Net -102/+68 lines, and the three files drop from ~50% duplicated to none.

Behaviour is unchanged. One incidental improvement: the consecutive-delimiter check is an index scan rather than Contains("--"), which drops a string allocation per call and avoids constructing the doubled delimiter at run time.

This was only safe to do because #158 added tests for the two rejection branches — a foreign separator, and correct separators with the wrong letter case — that had never been exercised for any of the three. Every rule in the shared helper is now covered.

Verification

  • dotnet build — 0 errors, 0 warnings, all target frameworks
  • dotnet test1088/1088 pass

The quality gate failed on new_duplicated_lines_density, and the cause was
pre-existing rather than introduced: the kebab, snake and macro validators
were 44-60% duplicated against each other as whole files, so touching any
line inside those blocks counts as new duplicated code.

All three implement the same five rules and differ only in three values -
the delimiter, the delimiter belonging to a different convention that must
not appear, and the required letter case. Extracted that into
DelimitedCaseValidation.Validate, leaving each validator a single
delegating expression:

    DelimitedCaseValidation.Validate(value, \x27-\x27, \x27_\x27, char.IsLower, FailureMessage)

Behaviour is unchanged. The consecutive-delimiter check is now an index scan
rather than Contains("--"), which drops a string allocation per call and
avoids constructing the doubled delimiter at run time.

Safe to do now precisely because the previous commit added tests for the two
rejection branches that had never been exercised - every rule in the shared
helper is covered.

Build clean on all TFMs, 1088/1088 tests pass.
@sonarqubecloud

Copy link
Copy Markdown

@matt-edmondson
matt-edmondson merged commit 625e4c3 into main Aug 14, 2026
6 checks passed
@matt-edmondson
matt-edmondson deleted the chore/sonar-casing-dedup branch August 14, 2026 07:59
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