Skip to content

Conversation

@alexgarzao
Copy link
Collaborator

Closes #62

This PR refactors the way field validations are represented and processed across the analyzer and code generator components. Instead of using strings to represent validations, the code now uses strongly-typed *Validation objects. This change improves type safety, error handling, and clarity throughout the codebase. The update also touches all relevant tests and utility functions to work with the new representation.

Core refactoring to use typed validations:

  • Changed the FieldValidations.Validations field from []string to []*Validation in internal/analyzer/struct.go, and updated all related code to use *Validation objects instead of strings. [1] [2]
  • Updated the analyzer logic in AnalyzeStructs to parse validations into *Validation objects and propagate errors using a custom error type.
  • Refactored the code generator (build_validator.go and test_elements.go) to accept and process *Validation objects, including updating function signatures and validation handling logic. [1] [2] [3] [4] [5]

Test and utility updates:

  • Updated all relevant tests to use the new AssertParserValidation helper, which parses validation strings into *Validation objects, ensuring consistency and type safety in test code. [1] [2] [3] [4] [5] [6] [7] [8] [9]
  • Added the AssertParserValidation helper function to utils.go for use in tests, streamlining validation parsing and error handling in test cases. [1] [2]

Error handling improvements:

  • Improved error messages and error propagation in validation parsing and test element definition, making failures clearer and easier to diagnose. [1] [2]

Build and infrastructure:

  • Enhanced the Makefile to define a comprehensive all target that runs clean, tests, builds, and benchmarks, and consolidated .PHONY declarations.

These changes collectively modernize the validation handling in the codebase, making it more robust and maintainable.

@alexgarzao alexgarzao self-assigned this Aug 23, 2025
@alexgarzao alexgarzao requested a review from Copilot August 23, 2025 22:52

This comment was marked as outdated.

@alexgarzao alexgarzao requested a review from Copilot August 23, 2025 22:58

This comment was marked as outdated.

@alexgarzao alexgarzao requested a review from Copilot August 25, 2025 22:20

This comment was marked as outdated.

@alexgarzao alexgarzao requested a review from Copilot August 25, 2025 22:29

This comment was marked as outdated.

@alexgarzao alexgarzao requested a review from Copilot August 25, 2025 22:38
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR refactors the validation system to use strongly-typed *Validation objects instead of string representations throughout the analyzer and code generator components. The change improves type safety by moving validation parsing from the code generation stage to the analyzer stage, ensuring validation errors are caught earlier in the process.

Key changes:

  • Updated FieldValidations.Validations from []string to []*Validation in the analyzer
  • Modified all code generator functions to accept *Validation objects instead of strings
  • Added comprehensive test utilities and updated all test cases to use the new typed approach

Reviewed Changes

Copilot reviewed 13 out of 13 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
internal/analyzer/struct.go Changed FieldValidations.Validations field type from []string to []*Validation
internal/analyzer/analyzer.go Added validation parsing logic to AnalyzeStructs function with error handling
internal/codegenerator/build_validator.go Updated function signatures to accept *Validation objects
internal/codegenerator/test_elements.go Refactored DefineTestElements to work with *Validation objects directly
internal/codegenerator/utils_test.go Added AssertParserValidation helper function for tests
internal/codegenerator/utils.go Minor formatting change (added blank line)
internal/codegenerator/*_test.go Updated all test files to use the new AssertParserValidation helper
Makefile Enhanced with comprehensive 'all' target and improved organization

@alexgarzao alexgarzao merged commit cef55f8 into main Aug 26, 2025
1 check passed
@alexgarzao alexgarzao deleted the 62-move-tag-parser-to-analyzer-stage branch August 26, 2025 14:08
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.

Move the tag parser to analyzer stage

5 participants