Skip to content

refactor: types#136

Merged
Oudwins merged 1 commit intomasterfrom
refactor/types
Mar 18, 2025
Merged

refactor: types#136
Oudwins merged 1 commit intomasterfrom
refactor/types

Conversation

@Oudwins
Copy link
Owner

@Oudwins Oudwins commented Mar 18, 2025

Summary by CodeRabbit

  • Refactor
    • Updated API type declarations and method signatures across various validation and schema components, streamlining type usage.
  • Chore
    • Simplified interfaces for test and transformation options, enhancing consistency and maintainability of the overall API.

These improvements provide a cleaner, more unified API experience without altering the external behavior.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Mar 18, 2025

Walkthrough

This pull request refactors type usage across various schema files by removing package prefixes (such as p. and conf.) from type references. Field types and method signatures for schema definitions—including those for preTransforms, tests, postTransforms, required, and coercer—are updated to use direct type references. Additionally, related utility functions and core schema functions incorporate similar changes, simplifying the dependency on external package aliases.

Changes

Files Change Summary
boolean.go, numbers.go, pointers.go, slices.go, string.go, struct.go, time.go Removed p. prefix from type references in schema definitions and method signatures. Field types (e.g., PreTransform, Test, PostTransform, required) and return types in Parse, Validate, and Test methods now use direct references.
utilsOptions.go Updated the TestOption type alias and function signatures (MessageFunc, IssueCode, IssuePath, Params, WithErrFormatter, WithIssueFormatter) to remove the p. prefix, aligning test and formatting types with the new direct type references.
zogSchema.go Removed dependency on the conf package by changing CoercerFunc references. Function signatures for primitiveProcessor and primitiveValidator were updated to use direct type references (PreTransform, Test, PostTransform) instead of their prefixed counterparts.

Possibly related PRs

Poem

I'm a rabbit with a joyful beat,
Hopping through code that's neat and sweet.
Unprefixed types now dance in the light,
Making schemas clear and bright.
With every hop, refactoring's complete –
A bunny's code celebration, oh what a treat!

Tip

⚡🧪 Multi-step agentic review comment chat (experimental)
  • We're introducing multi-step agentic chat in review comments. This experimental feature enhances review discussions with the CodeRabbit agentic chat by enabling advanced interactions, including the ability to create pull requests directly from comments.
    - To enable this feature, set early_access to true under in the settings.

📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 2ac1517 and 934ae52.

📒 Files selected for processing (9)
  • boolean.go (6 hunks)
  • numbers.go (6 hunks)
  • pointers.go (4 hunks)
  • slices.go (9 hunks)
  • string.go (16 hunks)
  • struct.go (5 hunks)
  • time.go (8 hunks)
  • utilsOptions.go (5 hunks)
  • zogSchema.go (3 hunks)
🧰 Additional context used
🧬 Code Definitions (5)
struct.go (4)
zogSchema.go (2) (2)
  • PreTransform (34:34)
  • PostTransform (37:37)
internals/types.go (2) (2)
  • PreTransform (10:10)
  • PostTransform (13:13)
utils.go (2) (2)
  • Test (45:45)
  • ZogIssueMap (38:38)
internals/Issues.go (1) (1)
  • ZogIssueMap (101:101)
zogSchema.go (5)
internals/contexts.go (17) (17)
  • c (33:35)
  • c (37:39)
  • c (41:46)
  • c (48:50)
  • c (53:58)
  • c (62:64)
  • c (67:72)
  • c (74:85)
  • c (87:98)
  • c (100:102)
  • c (120:127)
  • c (129:140)
  • c (143:159)
  • c (162:171)
  • c (175:181)
  • c (184:186)
  • SchemaCtx (104:113)
utils.go (2) (2)
  • CoercerFunc (40:40)
  • Test (45:45)
internals/Issues.go (1) (1)
  • IssueFmtFunc (10:10)
internals/tests.go (1) (1)
  • Test (14:20)
internals/zeroValues.go (1) (1)
  • IsZeroValueFunc (8:8)
pointers.go (5)
utils.go (2) (2)
  • Test (45:45)
  • ZogIssueMap (38:38)
internals/tests.go (1) (1)
  • Test (14:20)
zogSchema.go (1) (1)
  • ZogSchema (10:15)
struct.go (12) (12)
  • v (25:27)
  • v (30:32)
  • v (47:62)
  • v (64:151)
  • v (155:170)
  • v (173:240)
  • v (243:249)
  • v (252:258)
  • v (265:267)
  • v (271:273)
  • v (289:295)
  • v (298:302)
internals/Issues.go (1) (1)
  • ZogIssueMap (101:101)
boolean.go (2)
zogSchema.go (2) (2)
  • PreTransform (34:34)
  • PostTransform (37:37)
conf/Coercers.go (1) (1)
  • CoercerFunc (32:32)
time.go (5)
internals/types.go (2) (2)
  • PreTransform (10:10)
  • PostTransform (13:13)
utils.go (2) (2)
  • Test (45:45)
  • ZogIssueList (21:21)
internals/tests.go (1) (1)
  • Test (14:20)
utilsOptions.go (2) (2)
  • ExecOption (73:73)
  • TestOption (10:10)
internals/Issues.go (1) (1)
  • ZogIssueList (98:98)
🔇 Additional comments (58)
pointers.go (6)

14-16: Type declarations simplified

The removal of package prefixes (p.) from field types makes the code cleaner and more maintainable. This change aligns with the PR objective of simplifying type references.


17-18: Consistent type simplification

Good continuation of the pattern of prefix removal, maintaining consistency throughout the struct definition.


35-36: Constructor updated correctly

The constructor has been properly updated to use the non-prefixed type, ensuring compatibility with the modified struct definition.


41-41: Return type simplified

Return type change from p.ZogIssueMap to ZogIssueMap maintains API consistency while removing unnecessary package prefixes.


97-97: Consistent return type update

The Validate method's return type has been updated consistently with the Parse method, maintaining a uniform API approach.


129-131: Test struct instantiation simplified

The instantiation of the Test struct now uses the direct type rather than the prefixed version, aligning with the changes made to field types.

zogSchema.go (4)

13-13: Interface method signature updated

The setCoercer method's parameter type has been simplified from conf.CoercerFunc to CoercerFunc, maintaining the same functionality while reducing namespace dependencies.


39-39: Added type alias for IssueFmtFunc

This addition follows the pattern of defining type aliases without package prefixes, enhancing code readability.


43-43: Function signature simplified

The primitiveProcessor function's parameter types have been updated to use direct type references instead of prefixed ones, making the signature cleaner while maintaining the same functionality.


126-126: Consistent function signature update

The primitiveValidator function's parameter types have been updated in the same way as primitiveProcessor, maintaining consistency across related functions.

struct.go (8)

15-15: Field type simplified

The preTransforms field type has been updated to use the non-prefixed PreTransform type, improving code readability.


17-18: Multiple field types simplified consistently

The postTransforms and tests field types have been updated following the same pattern as preTransforms, maintaining consistency throughout the struct.


20-20: Pointer field type simplified

The required field's pointer type has been updated to use the non-prefixed Test type, consistent with other field type changes.


47-47: Method return type simplified

The Parse method's return type has been updated from p.ZogIssueMap to ZogIssueMap, maintaining API consistency while simplifying type references.


155-155: Consistent return type update

The Validate method's return type has been updated consistently with the Parse method, maintaining a uniform API approach.


243-246: Method parameter and initialization simplified

Both the PreTransform method's parameter type and the initialization of the preTransforms slice now use the non-prefixed PreTransform type, ensuring consistency between parameter and field types.


253-255: Similar simplification for PostTransform

The PostTransform method follows the same pattern as PreTransform, using the non-prefixed type for both parameter and slice initialization.


289-293: Test method parameter type simplified

The Test method's parameter type has been updated to use the non-prefixed Test type, consistent with other method parameter changes.

slices.go (10)

16-17: Field types simplified

The preTransforms and tests field types have been updated to use non-prefixed types, improving code readability.


19-20: Additional field types simplified consistently

The postTransforms and required field types follow the same pattern, maintaining consistency throughout the struct definition.


52-52: Method return type simplified

The Validate method's return type has been updated from p.ZogIssueMap to ZogIssueMap, simplifying type references.


141-141: Consistent return type update

The Parse method's return type has been updated in the same way as the Validate method, maintaining a consistent approach.


236-239: Method parameter and initialization simplified

Both the PreTransform method's parameter type and the initialization of the preTransforms slice now use the non-prefixed type.


245-248: Similar simplification for PostTransform

The PostTransform method follows the same pattern, using the non-prefixed type for both parameter and slice initialization.


287-293: Test method parameter type simplified

The Test method's parameter type has been updated to use the non-prefixed Test type, consistent with other method parameter changes.


339-358: Test struct instantiation simplified

The instantiation of the Test struct in the Contains method now uses the direct type rather than the prefixed version.


366-380: Helper function return type simplified

The sliceMin function's return type has been updated to use the non-prefixed Test type, as has the type of the local variable t.


381-410: Consistent helper function updates

The sliceMax and sliceLength helper functions have been updated in the same way as sliceMin, maintaining consistency across related functions.

utilsOptions.go (7)

10-10: Type reference update for improved clarity.

The TestOption type now directly references *Test instead of *p.Test, consistent with the PR's goal of removing package prefixes.


22-23: Function signature update for type consistency.

Both the parameter type IssueFmtFunc and the return type's function parameter *Test have been updated to remove the package prefix, making the code more readable.


33-33: Parameter type update for IssueCode function.

The parameter type has been changed from *p.Test to *Test, aligning with other type reference changes.


50-50: Parameter type update for IssuePath function.

The parameter type has been changed from *p.Test to *Test, maintaining consistency with the type system changes.


58-58: Parameter type update for Params function.

The parameter type has been changed from *p.Test to *Test, consistent with the pattern of removing package prefixes.


80-80: Parameter type update for deprecated WithErrFormatter function.

The parameter type has been updated from p.IssueFmtFunc to IssueFmtFunc, aligning with the type system changes.


86-86: Parameter type update for WithIssueFormatter function.

The parameter type has been updated from p.IssueFmtFunc to IssueFmtFunc, ensuring consistency with the updated type system.

string.go (5)

21-23: Updated struct field types to remove package prefixes.

All field types in the StringSchema struct have been updated to use direct type references rather than prefixed ones:

  • preTransforms from []p.PreTransform to []PreTransform
  • tests from []p.Test to []Test
  • postTransforms from []p.PostTransform to []PostTransform
  • required from *p.Test to *Test

This simplifies the type references while maintaining the same functionality.

Also applies to: 25-25


56-56: Updated return type for Parse and Validate methods.

The return type has been changed from p.ZogIssueList to ZogIssueList for both methods, removing the package prefix while maintaining the same functionality.

Also applies to: 81-81


104-104: Updated method signatures for transform functions.

The parameter types for PreTransform and PostTransform methods have been updated from p.PreTransform and p.PostTransform to PreTransform and PostTransform respectively, consistent with the PR's goal of removing package prefixes.

Also applies to: 126-126


168-168: Updated parameter type for Test method.

The parameter type has been changed from p.Test to Test, aligning with other type reference changes.


226-226: Updated struct instantiation across multiple validation methods.

The type reference has been changed from p.Test to Test across all validation methods (Email, URL, HasPrefix, HasSuffix, Contains, ContainsUpper, ContainsDigit, ContainsSpecial, UUID, Match). This change simplifies the code while maintaining the same behavior.

Also applies to: 245-245, 286-286, 307-307, 328-328, 352-352, 379-379, 406-406, 425-425

time.go (5)

15-17: Updated struct field types in TimeSchema.

Field types have been updated to remove package prefixes:

  • preTransforms from []p.PreTransform to []PreTransform
  • tests from []p.Test to []Test
  • postTransforms from []p.PostTransform to []PostTransform
  • required from *p.Test to *Test

This change aligns with the PR goal of simplifying type references.

Also applies to: 19-19


73-73: Updated return type for TimeSchema methods.

The return type has been changed from p.ZogIssueList to ZogIssueList for both Parse and Validate methods, eliminating the package prefix while maintaining the same functionality.

Also applies to: 96-96


118-118: Updated parameter types for transform methods.

The parameter types for PreTransform and PostTransform methods have been updated from p.PreTransform and p.PostTransform to PreTransform and PostTransform respectively, consistent with the type system changes throughout the codebase.

Also applies to: 127-127


168-168: Updated parameter type for Test method.

The parameter type has been changed from p.Test to Test, maintaining consistency with the updated type system.


188-188: Updated struct instantiation in time validation methods.

The type reference has been changed from p.Test to Test across all time validation methods (After, Before, EQ). This simplifies the code while preserving the same functionality.

Also applies to: 210-210, 232-232

numbers.go (5)

15-17: Updated struct field types in NumberSchema.

Field types have been updated to remove package prefixes:

  • preTransforms from []p.PreTransform to []PreTransform
  • tests from []p.Test to []Test
  • postTransforms from []p.PostTransform to []PostTransform
  • required from *p.Test to *Test

This change provides more direct and readable type references.

Also applies to: 19-19


123-123: Updated return type for Parse and Validate methods.

The return type has been changed from p.ZogIssueList to ZogIssueList for both methods, removing the package prefix while maintaining the same functionality.

Also applies to: 147-147


170-170: Updated parameter types for transform methods.

The parameter types for PreTransform and PostTransform methods have been updated from p.PreTransform and p.PostTransform to PreTransform and PostTransform respectively, consistent with the type system changes throughout the codebase.

Also applies to: 179-179


218-218: Updated parameter type for Test method.

The parameter type has been changed from p.Test to Test, aligning with the PR goal of simplifying type references.


32-32:

Details

✅ Verification successful

Updated parameter type in setCoercer method.

The parameter type has been changed from conf.CoercerFunc to CoercerFunc, which suggests that either:

  1. There's a new local type alias for this type, or
  2. This could be an oversight as other methods still use conf.CoercerFunc (like in line 66 of utilsOptions.go)

🏁 Script executed:

#!/bin/bash
# Check if CoercerFunc is defined as a type alias
rg -A 1 "type CoercerFunc" --type go
# Check how CoercerFunc is used elsewhere
rg "CoercerFunc" --type go | grep -v "conf\.CoercerFunc"

Length of output: 1105


CoercerFunc alias usage verified and consistent

The update in numbers.go (line 32) is intentional. The local alias for CoercerFunc is defined in utils.go as follows:

  • type CoercerFunc = conf.CoercerFunc

Our recent search confirms that this alias is now in use throughout the codebase (e.g., in zogSchema.go and boolean.go), ensuring consistent usage. If there are any lingering references to conf.CoercerFunc (as was suspected in utilsOptions.go), they should be reviewed and updated accordingly.

boolean.go (8)

12-14: Type references simplified correctly in BoolSchema struct.

The package prefixes have been properly removed from field types in the BoolSchema struct, which aligns with the refactoring goal of simplifying type references. This change makes the code cleaner while maintaining the same functionality.

Also applies to: 16-16, 18-18


29-29: Parameter type in setCoercer method updated consistently.

The setCoercer method parameter has been updated to use the unprefixed CoercerFunc type, maintaining consistency with the struct field changes.


47-47: Return type for Parse method properly updated.

The return type of the Parse method has been changed from the prefixed p.ZogIssueList to the unprefixed ZogIssueList, which is consistent with the type refactoring pattern throughout the file.


69-69: Return type for Validate method properly updated.

The return type of the Validate method has been updated from p.ZogIssueList to ZogIssueList, maintaining consistency with the Parse method and other type reference changes.


93-93: Parameter type in Test method updated correctly.

The parameter type in the Test method has been properly changed from p.Test to Test, which aligns with the consistent pattern of removing package prefixes.


110-113: PreTransform method types updated properly.

Both the parameter type and the slice initialization type have been updated to use the unprefixed PreTransform type, maintaining consistency throughout the method.


119-122: PostTransform method types updated properly.

Similar to the PreTransform method, both the parameter type and slice initialization have been updated to use the unprefixed PostTransform type, ensuring consistency.


3-7:

Details

✅ Verification successful

Verify import usage after type refactoring.

With the prefixed types now being used directly, it would be good to verify that all the imports are still needed. If the p and conf packages are now only used minimally, consider whether they could be refactored further.


🏁 Script executed:

#!/bin/bash
# Check how the p and conf imports are used after refactoring
echo "Checking usage of p package:"
grep -n "p\." boolean.go
echo -e "\nChecking usage of conf package:"
grep -n "conf\." boolean.go

Length of output: 1091


Import Usage Verified – No Immediate Refactoring Required

The verification confirms that both the p and conf imports are still actively used in boolean.go:

  • p package: Used in multiple places (e.g., p.NewErrsList(), p.NewExecCtx(), p.NewPathBuilder(), and various function calls) across the file.
  • conf package: Provides essential constants (e.g., conf.Coercers.Bool and conf.IssueFormatter) which are used when initializing execution contexts.

No further refactoring is necessary based on the current usage; however, you could consider consolidating or refining usage in the future if the patterns change.

✨ Finishing Touches
  • 📝 Generate Docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@Oudwins Oudwins merged commit bce1b4d into master Mar 18, 2025
8 of 9 checks passed
@Oudwins Oudwins deleted the refactor/types branch March 18, 2025 07:25
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