Deduplicate the delimiter-separated casing validators - #160
Merged
Conversation
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.
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.



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: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 frameworksdotnet test— 1088/1088 pass