Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add contains tag #14

Merged
merged 1 commit into from
Sep 6, 2024
Merged

Add contains tag #14

merged 1 commit into from
Sep 6, 2024

Conversation

nao1215
Copy link
Owner

@nao1215 nao1215 commented Sep 6, 2024

Summary by CodeRabbit

  • New Features

    • Introduced a new validation rule "contains" for checking if a value includes a specified substring, enhancing validation capabilities.
    • Added error messages for better user feedback regarding validation failures, including invalid email addresses and format issues.
  • Bug Fixes

    • Improved error handling for validation tags, ensuring accurate error messages for malformed tags.
  • Localization

    • Expanded localization support by adding new error messages in English, Japanese, and Russian for better user experience across different languages.

Copy link

coderabbitai bot commented Sep 6, 2024

Walkthrough

The changes introduce a new validation rule called "contains" for checking if a value includes a specified substring. This is supported by updates to the documentation, error handling, and localization files. Additionally, new test cases have been added to ensure the functionality works correctly, and a new containsValidator struct has been implemented to handle the validation logic.

Changes

Files Change Summary
README.md Added documentation for the new "contains" validation rule.
csv_test.go Introduced two test cases: one for validating the "contains" rule and another for handling invalid tag formats.
errors.go Added two new error identifiers: ErrContainsID and ErrInvalidContainsFormatID for improved error reporting.
i18n/en.yaml Added three new error message entries for localization related to the new validation rules.
i18n/ja.yaml Introduced three new translation entries for error messages in Japanese.
i18n/ru.yaml Introduced three new translation entries for error messages in Russian.
parser.go Updated parseValidateTag function to handle the new "contains" validation tag.
tag.go Added a new constant containsTagValue for the "contains" validation.
validation.go Introduced a new containsValidator struct and associated methods to validate the presence of a substring in a target string.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant CSVDecoder
    participant Validator
    participant ErrorHandler

    User->>CSVDecoder: Submit CSV with "contains" validation
    CSVDecoder->>Validator: Validate "contains" rule
    Validator->>Validator: Check substring presence
    alt Substring found
        Validator-->>CSVDecoder: Validation success
    else Substring not found
        Validator-->>ErrorHandler: Return ErrContainsID
        ErrorHandler-->>CSVDecoder: Show error message
    end
Loading

🐰 In a world of strings and checks,
A rabbit hops with joyful pecks.
"Contains" is here, oh what a treat,
Validations now can’t be beat!
With errors caught and messages clear,
Hooray for changes, let’s all cheer! 🎉


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

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>.
    • 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 generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @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 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.

csv_test.go Show resolved Hide resolved
csv_test.go Show resolved Hide resolved
Copy link

github-actions bot commented Sep 6, 2024

Code Metrics Report

main (9133095) #14 (212993e) +/-
Coverage 81.9% 83.1% +1.2%
Test Execution Time 8s 1s -7s
Details
  |                     | main (9133095) | #14 (212993e) |  +/-  |
  |---------------------|----------------|---------------|-------|
+ | Coverage            |          81.9% |         83.1% | +1.2% |
  |   Files             |              6 |             6 |     0 |
  |   Lines             |            344 |           357 |   +13 |
+ |   Covered           |            282 |           297 |   +15 |
+ | Test Execution Time |             8s |            1s |   -7s |

Code coverage of files in pull request scope (83.6% → 84.4%)

Files Coverage +/-
errors.go 87.5% 0.0%
parser.go 81.7% +2.4%
tag.go 100.0% 0.0%
validation.go 85.5% +0.0%

Reported by octocov

@nao1215 nao1215 merged commit d3c14c2 into main Sep 6, 2024
19 checks passed
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

Outside diff range, codebase verification and nitpick comments (1)
parser.go (1)

138-146: Approved: Addition of contains tag handling in parseValidateTag.

The implementation for handling the contains tag in parseValidateTag is correctly integrated with the existing validation logic. The use of parseOneOf and the subsequent checks ensure that the tag is correctly parsed and validated.

Consider adding a comment before the contains case to explain that it expects exactly one value, similar to the comments in other cases. This will improve code readability and maintainability.

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 9133095 and b5dd909.

Files selected for processing (9)
  • README.md (1 hunks)
  • csv_test.go (1 hunks)
  • errors.go (1 hunks)
  • i18n/en.yaml (1 hunks)
  • i18n/ja.yaml (1 hunks)
  • i18n/ru.yaml (1 hunks)
  • parser.go (1 hunks)
  • tag.go (1 hunks)
  • validation.go (1 hunks)
Additional context used
golangci-lint
csv_test.go

589-589: singleCaseSwitch: should rewrite switch statement to if statement

(gocritic)


618-618: singleCaseSwitch: should rewrite switch statement to if statement

(gocritic)

Additional comments not posted (11)
i18n/ja.yaml (2)

79-80: Translation for ErrContains is correct.

The translation "指定された値を含んでいません" accurately conveys the intended message in Japanese.


82-83: Translation for ErrInvalidContainsFormat is correct.

The translation "'contains'タグの形式が無効です" accurately conveys the intended message in Japanese.

i18n/en.yaml (2)

73-74: Translation for ErrContains is correct.

The translation "target does not contain the specified value" accurately conveys the intended message in English.


76-77: Translation for ErrInvalidContainsFormat is correct.

The translation "'contains' tag format is invalid" accurately conveys the intended message in English.

i18n/ru.yaml (2)

73-74: Translation for ErrContains is correct.

The translation "целевое значение не содержит подстроку" accurately conveys the intended message in Russian.


76-77: Translation for ErrInvalidContains is correct.

The translation "Формат тега 'contains' недопустим" accurately conveys the intended message in Russian.

tag.go (1)

53-54: Approved: Addition of containsTagValue constant.

The addition of the containsTagValue constant is consistent with the existing structure and naming conventions used in the file.

errors.go (1)

101-104: Approved: Addition of error identifiers ErrContainsID and ErrInvalidContainsFormatID.

The addition of the error identifiers ErrContainsID and ErrInvalidContainsFormatID is consistent with the existing structure and naming conventions used in the file.

README.md (1)

132-132: Documentation for "contains" validation rule is clear and informative.

The addition of the "contains" validation rule in the documentation is well-explained and includes an appropriate example. This should help users understand how to use this new validation feature effectively.

csv_test.go (2)

569-596: Test case for "validate contains" is well-implemented.

The test case effectively checks the functionality of the "contains" validation rule, ensuring that it correctly identifies when the specified substring is not present. The error message is clear and provides useful information for debugging.

Tools
golangci-lint

589-589: singleCaseSwitch: should rewrite switch statement to if statement

(gocritic)


598-625: Test case for "invalid contains tag format" is effective.

This test case successfully verifies the system's ability to handle malformed validation tags. The error message clearly specifies the issue, aiding in quick identification and resolution of format errors in validation tags.

Tools
golangci-lint

618-618: singleCaseSwitch: should rewrite switch statement to if statement

(gocritic)

Comment on lines +506 to +527
// containsValidator is a struct that contains the validation rules for a contains column.
type containsValidator struct {
contains string
}

// newContainsValidator returns a new containsValidator.
func newContainsValidator(contains string) *containsValidator {
return &containsValidator{contains: contains}
}

// Do validates the target contains the contains value.
func (c *containsValidator) Do(localizer *i18n.Localizer, target any) error {
v, ok := target.(string)
if !ok {
return NewError(localizer, ErrContainsID, fmt.Sprintf("value=%v", target))
}

if !strings.Contains(v, c.contains) {
return NewError(localizer, ErrContainsID, fmt.Sprintf("contains=%s, value=%v", c.contains, target))
}
return nil
}
Copy link

Choose a reason for hiding this comment

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

Implementation of containsValidator is robust and well-structured.

The containsValidator struct and its associated methods are correctly implemented to support the new "contains" validation rule. The Do method effectively checks for the presence of the specified substring and returns informative error messages when the validation fails.

Suggestion for Improvement:
Consider enhancing the error message in the Do method to include more context about the expected and actual values, which could aid in debugging complex issues.

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