Skip to content

Conversation

@fahimfaisaal
Copy link
Member

validators.go - Major Refactor

  • Changed Validator function signature from func(string) bool to func(string) error for better error logging with actual reasons
  • Refactored ApplyValidationRules to use clean helper methods instead of if-else chains:
    • apply() - dispatches to value or slice validation
    • validateValue() - validates single string values with early returns
    • validateSlice() - validates slice values
    • normalizeValue() / normalizeSlice() - handle normalization
    • validate(value) - runs validator or checks valid set, returns error
    • printWarning() - formats and prints warning with reason if available
  • Removed all isValid boolean variables for cleaner code

parse_pattern.go - Validation Enhancements

  • Renamed ValidatePattern to ValidateGroupPattern for clarity
  • Added validation: pattern must contain xAxis (x) OR yAxis (y)
  • Added validation in ParseBenchmarkNameWithRegex: regex result must have xAxis or yAxis, otherwise returns error with clear message

flag_validation_rules.go - Cleanup

  • Removed wrapper function, now directly uses parser.ValidateGroupPattern
  • Removed duplicate group regex validation rule

Test Updates

  • Updated parse_pattern_test.go:
    • Test function now calls ValidateGroupPattern
    • Added test cases for xAxis/yAxis validation requirement
    • Added test cases for regex validation (name-only, xAxis-only, no named groups)
  • Updated flag_validation_test.go: removed group regex label assertion
  • Updated root_test.go: adjusted expected warning messages for new format

Warning Message Format

Old: Warning: Invalid time unit 'invalid'. Using default 'ns' New: Warning: Invalid time unit 'invalid'. Reason: value not in valid set [ns us ms s]. Using default 'ns'

…r ApplyValidationRules

## Changes

### validators.go - Major Refactor
- Changed Validator function signature from `func(string) bool` to `func(string) error`
  for better error logging with actual reasons
- Refactored ApplyValidationRules to use clean helper methods instead of if-else chains:
  - `apply()` - dispatches to value or slice validation
  - `validateValue()` - validates single string values with early returns
  - `validateSlice()` - validates slice values
  - `normalizeValue()` / `normalizeSlice()` - handle normalization
  - `validate(value)` - runs validator or checks valid set, returns error
  - `printWarning()` - formats and prints warning with reason if available
- Removed all `isValid` boolean variables for cleaner code

### parse_pattern.go - Validation Enhancements
- Renamed `ValidatePattern` to `ValidateGroupPattern` for clarity
- Added validation: pattern must contain xAxis (x) OR yAxis (y)
- Added validation in `ParseBenchmarkNameWithRegex`: regex result must have
  xAxis or yAxis, otherwise returns error with clear message

### flag_validation_rules.go - Cleanup
- Removed wrapper function, now directly uses `parser.ValidateGroupPattern`
- Removed duplicate group regex validation rule

### Test Updates
- Updated parse_pattern_test.go:
  - Test function now calls `ValidateGroupPattern`
  - Added test cases for xAxis/yAxis validation requirement
  - Added test cases for regex validation (name-only, xAxis-only, no named groups)
- Updated flag_validation_test.go: removed group regex label assertion
- Updated root_test.go: adjusted expected warning messages for new format

## Warning Message Format
Old: Warning: Invalid time unit 'invalid'. Using default 'ns'
New: Warning: Invalid time unit 'invalid'. Reason: value not in valid set [ns us ms s]. Using default 'ns'
@netlify
Copy link

netlify bot commented Dec 12, 2025

Deploy Preview for vizb-demo canceled.

Name Link
🔨 Latest commit d036993
🔍 Latest deploy log https://app.netlify.com/projects/vizb-demo/deploys/693becf8ce4b6c000807eac9

@codecov-commenter
Copy link

codecov-commenter commented Dec 12, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

- Add TestApplyValidationRulesSlice: valid slice, invalid slice fallback,
  slice with normalizer, empty slice handling
- Add TestApplyValidationRulesWithCustomValidator: validator returning nil,
  validator returning error, specific error messages, slice with custom validator

Coverage improved from 63.63% to 98.8% for validators.go
@fahimfaisaal fahimfaisaal merged commit 4f11bf0 into main Dec 12, 2025
5 checks passed
@fahimfaisaal fahimfaisaal deleted the refactor/validators-and-group-validation branch December 12, 2025 10:24
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.

3 participants