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

chore: disallow this in collection predicate #1176

Merged
merged 3 commits into from
Mar 25, 2024

Conversation

ymc9
Copy link
Member

@ymc9 ymc9 commented Mar 25, 2024

Summary by CodeRabbit

  • New Features
    • Enhanced validation logic for expressions involving specific operators.
  • Tests
    • Added tests to improve validation for collection predicates and data model structures.
    • Updated logic for determining read access within a model definition.
  • Chores
    • Disabled a test related to a reference with this.

Copy link
Contributor

coderabbitai bot commented Mar 25, 2024

Walkthrough

Walkthrough

The modifications involve refining the validation and auto-completion functionalities in the language server and its testing framework. Specifically, these changes enhance the handling of collection predicates in expressions by introducing a dedicated validation method and adjusting the scope of auto-completion to improve the development experience. Additionally, the testing suite is expanded to cover new scenarios, ensuring the robustness of data model validations, particularly with the use of this in collection predicates and the interplay between array and optional fields.

Changes

Files Summary
packages/schema/src/language-server/validator/expression-validator.ts Added streamAst import, removed isCollectionPredicate check, added validateCollectionPredicate method.
packages/schema/tests/schema/validation/datamodel-validation.test.ts Added tests for this in collection predicates and mixing array and optional fields.
tests/integration/tests/regression/issues.test.ts Adjusted logic for determining read access within a model definition.

Related issues

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:

Note: Auto-reply has been disabled for this repository by the repository owner. The CodeRabbit bot will not respond to your replies unless it is explicitly tagged.

  • 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 tests 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 tests.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

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 as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger a review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • The JSON schema for the configuration file is available here.
  • 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/coderabbit-overrides.v2.json

CodeRabbit Discord Community

Join our Discord Community to get help, request features, and share feedback.

Copy link
Contributor

@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.

Review Status

Actionable comments generated: 0

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between 35b4be9 and e518d39.
Files selected for processing (2)
  • packages/schema/src/language-server/validator/expression-validator.ts (3 hunks)
  • packages/schema/tests/schema/validation/datamodel-validation.test.ts (1 hunks)
Additional comments: 3
packages/schema/src/language-server/validator/expression-validator.ts (2)
  • 16-16: The addition of streamAst from 'langium' is appropriate for the functionalities introduced in this update. It's used effectively within the validateCollectionPredicate method to search for this expressions within collection predicates.
  • 231-244: The validateCollectionPredicate method is well-implemented to enforce the new rule against using this in collection predicates. It effectively searches for this expressions within the predicate and generates a clear error message if found. This addition aligns with the PR's objectives and enhances the validation logic.
packages/schema/tests/schema/validation/datamodel-validation.test.ts (1)
  • 81-102: The addition of the test for using this in collection predicates is well-crafted. It effectively verifies the new validation rule by expecting an error when this is used in a collection predicate. Additionally, it includes a positive case that validates correct behavior when this is not used, which is a good practice for comprehensive testing.

Copy link
Contributor

@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.

Review Status

Actionable comments generated: 0

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between e518d39 and 2d1ffee.
Files selected for processing (1)
  • tests/integration/tests/regression/issues.test.ts (1 hunks)
Additional comments: 1
tests/integration/tests/regression/issues.test.ts (1)
  • 603-603: The change from auth() == this to auth().id == id in the access control logic appears to correctly refine the condition for checking user IDs within the same organization. However, it's crucial to verify this change in the broader context of the application to ensure it doesn't introduce any security issues or regressions.

Copy link
Contributor

@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.

Review Status

Actionable comments generated: 0

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between 2d1ffee and f0a344d.
Files selected for processing (1)
  • tests/integration/tests/regression/issue-925.test.ts (1 hunks)
Additional comments: 1
tests/integration/tests/regression/issue-925.test.ts (1)
  • 38-39: Consider adding a comment above the disabled test case to explain why it was disabled. This helps maintain clarity and context for future developers or when revisiting this test case later.

@ymc9 ymc9 merged commit 6e9d242 into v2 Mar 25, 2024
12 checks passed
@ymc9 ymc9 deleted the chore/disallow-this-in-collection branch March 25, 2024 22:10
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