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

fix: Added lint error for appsmith store mutations #33484

Merged
merged 2 commits into from
May 17, 2024

Conversation

sneha122
Copy link
Contributor

@sneha122 sneha122 commented May 15, 2024

Description

The interface we have for storing local variables using appsmith.store is immutable, meaning if we want to add variables to this, we have to use storeValue method to add or remove values from appsmith.store. If we use appsmith.store.value = "", we already get a linting error that says Use storeValue() method to modify store. Now if we are in a situation where we have stored an array inside appsmith store and we are mutating this array using push or any other array method, we should be able to see the same linting error. This Pr fixes that problem and shows error any time any function call is made on store object.

Note: removed ImperativeStoreUpdate_spec cypress test case as I have added unit test case which covers this case.

Fixes #29969
or
Fixes Issue URL

Warning

If no issue exists, please create an issue first, and check with the maintainers if the issue is valid.

Automation

/ok-to-test tags="@tag.Settings"

🔍 Cypress test results

Caution

🔴 🔴 🔴 Some tests have failed.
Workflow run: https://github.com/appsmithorg/appsmith/actions/runs/9124146068
Commit: 56bd967
Cypress dashboard: Click here!
The following are new failures, please fix them before merging the PR:

  1. cypress/e2e/Regression/ClientSide/SettingsPane/EmbedSettings_spec.ts
To know the list of identified flaky tests - Refer here

Communication

Should the DevRel and Marketing teams inform users about this change?

  • Yes
  • No

Copy link
Contributor

coderabbitai bot commented May 15, 2024

Walkthrough

The changes introduce a new interface MemberCallExpressionData to handle call expressions where the callee is a member node, such as obj.func(). The modifications ensure that the extractExpressionsFromCode function and linting utilities can detect and handle mutations on immutable objects, particularly in the Appsmith store, by providing appropriate lint errors.

Changes

Files/Paths Change Summary
app/client/packages/ast/index.ts Added MemberCallExpressionData to imports and exports for type definitions related to call expressions.
app/client/packages/ast/src/index.ts Introduced MemberCallExpressionData interface and updated extractExpressionsFromCode to handle this new data structure alongside existing ones.
app/client/src/plugins/Linting/tests/... Added tests to verify lint errors for mutations on immutable objects, including Appsmith store variables and input widget properties.
app/client/src/plugins/Linting/utils/... Renamed parameters and variables to reflect handling of MemberCallExpressionData, updated getInvalidAppsmithStoreSetterErrors to use these new data structures, and modified getCustomErrorsFromScript.

Assessment against linked issues

Objective Addressed Explanation
Show lint error when Appsmith store is reassigned or mutated (#29969)
Detect mutations using member function calls on objects in the store (#29969)
Ensure tests cover new linting rules for immutable object mutations (#29969)

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.

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

@github-actions github-actions bot added BE Coders Pod Issues related to users writing code to fetch and update data Bug Something isn't working Enhancement New feature or request FE Coders Pod Issues related to users writing javascript in appsmith Integrations Pod Issues related to a specific integration Integrations Pod General Issues related to the Integrations Pod that don't fit into other tags. JS Linting & Errors Issues related to JS Linting and errors JS Usability usability issues with JS editor and JS elsewhere Needs Triaging Needs attention from maintainers to triage Production and removed Enhancement New feature or request labels May 15, 2024
@sneha122 sneha122 added the ok-to-test Required label for CI label May 15, 2024
@github-actions github-actions bot added the Enhancement New feature or request label May 15, 2024
@github-actions github-actions bot added Enhancement New feature or request and removed Enhancement New feature or request labels May 15, 2024
Copy link
Contributor

@rishabhrathod01 rishabhrathod01 left a comment

Choose a reason for hiding this comment

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

Code changes LGTM. Testing the DP

@rishabhrathod01
Copy link
Contributor

/build-deploy-preview skip-tests=true

Copy link

Deploying Your Preview: https://github.com/appsmithorg/appsmith/actions/runs/9111180273.
Workflow: On demand build Docker image and deploy preview.
skip-tests: true.
env: ``.
PR: 33484.
recreate: .

Copy link

Deploy-Preview-URL: https://ce-33484.dp.appsmith.com

@rishabhrathod01
Copy link
Contributor

image

Changes look good on DP.

@github-actions github-actions bot added Enhancement New feature or request and removed Enhancement New feature or request labels May 17, 2024
@github-actions github-actions bot added the Enhancement New feature or request label May 17, 2024
@sneha122 sneha122 added ok-to-test Required label for CI and removed ok-to-test Required label for CI labels May 17, 2024
@nidhi-nair nidhi-nair merged commit bbfe4ff into release May 17, 2024
40 of 42 checks passed
@nidhi-nair nidhi-nair deleted the fix/show-lint-error-on-appsmithstore-mutation branch May 17, 2024 11:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
BE Coders Pod Issues related to users writing code to fetch and update data Bug Something isn't working Enhancement New feature or request FE Coders Pod Issues related to users writing javascript in appsmith Integrations Pod General Issues related to the Integrations Pod that don't fit into other tags. Integrations Pod Issues related to a specific integration JS Linting & Errors Issues related to JS Linting and errors JS Usability usability issues with JS editor and JS elsewhere Needs Triaging Needs attention from maintainers to triage ok-to-test Required label for CI Production
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Bug]: Appsmith store should show lint error when reassinged or mutated
3 participants