Skip to content

chore: update logic to calculate length of lint#36548

Merged
ayushpahwa merged 31 commits intoreleasefrom
feat/eslint/lint-length-processing
Nov 19, 2024
Merged

chore: update logic to calculate length of lint#36548
ayushpahwa merged 31 commits intoreleasefrom
feat/eslint/lint-length-processing

Conversation

@ayushpahwa
Copy link
Contributor

@ayushpahwa ayushpahwa commented Sep 25, 2024

Description

As part of project to migrate linter to eslint, a small dependency we need to take care of is to update how we calculate the length of the lint to be shown. Today we use an array of variables and calculate their char lengths. With eslint, we directly get the length and hence can be passed down to this function. To ensure backward compatibility till we are still phasing out JSHint, a conditional check is added to the linthelper file.

[!NOTE] > This PR is part of a series of stacked diffs and might have changes from it's parent PRs. Untill the blocking parent PRs are merged, this diff would show more changes than are relevant for this PR. Blocking PRs: - #36543

Fixes #36546

Automation

/test js sanity

🔍 Cypress test results

Tip

🟢 🟢 🟢 All cypress tests have passed! 🎉 🎉 🎉
Workflow run: https://github.com/appsmithorg/appsmith/actions/runs/11907265100
Commit: 7da61e7
Cypress dashboard.
Tags: @tag.JS, @tag.Sanity
Spec:


Tue, 19 Nov 2024 07:50:17 UTC

Communication

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

  • Yes
  • No

Summary by CodeRabbit

  • New Features

    • Introduced a new optional property lintLength to enhance lint error reporting.
    • Improved handling of dynamic bindings for better accuracy and responsiveness to changes.
  • Bug Fixes

    • Enhanced test coverage for lint error annotations to ensure correct behavior with and without lintLength.
  • Documentation

    • Updated comments for clarity regarding new linting logic and error handling.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Sep 25, 2024

Walkthrough

The changes in this pull request enhance the linting functionality by introducing a new optional property, lintLength, to the LintError interface and updating the getLintAnnotations() function to utilize this property. Two new test cases have been added to verify the behavior of the function with and without the lintLength property. Additionally, the getDynamicBindingsChangesSaga function has been refined to improve dynamic binding handling.

Changes

File Path Change Summary
app/client/src/components/editorComponents/CodeEditor/lintHelpers.test.ts Added two new test cases for getLintAnnotations() to check behavior with and without lintLength.
app/client/src/components/editorComponents/CodeEditor/lintHelpers.ts Introduced lintLength parameter in getLintAnnotations(), updated length calculation logic.
app/client/src/utils/DynamicBindingUtils.ts Added optional lintLength property to LintError interface; refined getDynamicBindingsChangesSaga.

Assessment against linked issues

Objective Addressed Explanation
Improve lint length calculation logic with eslint (#[36546])

Possibly related PRs

Suggested labels

Enhancement, QA, IDE Product, IDE Pod

Suggested reviewers

  • sagar-qa007

🎉 In the realm of code, where errors reside,
A new lint length feature, we now can abide.
Tests added with care, to catch every flaw,
With dynamic bindings refined, we stand in awe!
So here’s to the changes, both clever and bright,
In the world of linting, we’ve taken a flight! 🚀


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

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 Task A simple Todo skip-changelog Adding this label to a PR prevents it from being listed in the changelog labels Sep 25, 2024
@github-actions github-actions bot added Workflows Pod Issues that the workflows team owns Workflows Product Issues related to the workflows product labels Sep 28, 2024
@github-actions
Copy link

github-actions bot commented Oct 7, 2024

This PR has not seen activitiy for a while. It will be closed in 7 days unless further activity is detected.

@github-actions github-actions bot added the Stale label Oct 7, 2024
@github-actions
Copy link

This PR has been closed because of inactivity.

@github-actions github-actions bot closed this Oct 23, 2024
@ayushpahwa ayushpahwa reopened this Nov 6, 2024
@ayushpahwa ayushpahwa added ok-to-test Required label for CI and removed Stale labels Nov 18, 2024
@ayushpahwa ayushpahwa marked this pull request as ready for review November 18, 2024 04:11
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.

Actionable comments posted: 0

🧹 Outside diff range and nitpick comments (2)
app/client/src/components/editorComponents/CodeEditor/lintHelpers.ts (1)

161-174: Consider these refinements to improve maintainability

The length calculation logic is correct but could be enhanced:

  1. Extract the default length as a named constant
  2. Simplify the variable-based calculation using array methods
  3. Add more context to the comment about why we're skipping length calculation

Consider this improvement:

+const DEFAULT_LINT_LENGTH = 1;
+
-    let calculatedLintLength = 1;
+    let calculatedLintLength = DEFAULT_LINT_LENGTH;

     // If lint length is provided, then skip the length calculation logic
+    // ESLint provides accurate length, while JSHint requires calculation from variables
     if (lintLength && lintLength > 0) {
       calculatedLintLength = lintLength;
     }
-    else if (variables) {
-      for (const variable of variables) {
-        if (variable) {
-          calculatedLintLength =
-            calculatedLintLength === 1
-              ? String(variable).length
-              : Math.min(String(variable).length, calculatedLintLength);
-        }
-      }
+    else if (variables?.length) {
+      calculatedLintLength = Math.min(
+        ...variables
+          .filter(Boolean)
+          .map(variable => String(variable).length)
+      );
     }
app/client/src/components/editorComponents/CodeEditor/lintHelpers.test.ts (1)

262-311: Consider adding edge cases to the test suite.

While the current tests cover the basic scenarios, consider adding tests for:

  • Zero or negative lintLength values
  • Very large lintLength values
  • Multi-line lint messages
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between cd3ed89 and afe552b.

📒 Files selected for processing (3)
  • app/client/src/components/editorComponents/CodeEditor/lintHelpers.test.ts (1 hunks)
  • app/client/src/components/editorComponents/CodeEditor/lintHelpers.ts (3 hunks)
  • app/client/src/utils/DynamicBindingUtils.ts (1 hunks)
🔇 Additional comments (7)
app/client/src/components/editorComponents/CodeEditor/lintHelpers.ts (3)

Line range hint 138-142: LGTM: Clean addition of lintLength parameter

The addition of the optional lintLength parameter to the error object destructuring maintains backward compatibility while supporting the ESLint migration.


213-213: LGTM: Correct usage of calculatedLintLength

The annotation position is correctly calculated using the new length determination logic.


Line range hint 138-174: Verify test coverage and usage

Let's ensure the new length calculation logic is properly tested and all callers are prepared for the changes.

✅ Verification successful

Let me check the test coverage for the new length calculation logic.


Let me check the actual implementation of the LintError interface and test cases.


Changes are properly tested and safe to proceed

The code changes are well-covered by tests:

  • Test cases exist for both scenarios: with explicit lintLength and with length calculation from variables
  • All callers use the function correctly through a consistent interface
  • The optional lintLength parameter maintains backward compatibility
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Check test coverage and usage of getLintAnnotations

# Find test files that cover this functionality
echo "Looking for relevant test files..."
fd -e test.ts -e spec.ts | xargs rg "getLintAnnotations"

# Find all callers of getLintAnnotations
echo "Looking for all callers..."
rg "getLintAnnotations\(" --type ts

# Check if there are any direct uses of the error object that might need updating
echo "Checking for direct error object usage..."
rg "LintError\[" --type ts

Length of output: 5022


Script:

#!/bin/bash
# Check test coverage for length calculation logic
echo "Checking test coverage for length calculation..."
rg -B 5 -A 10 "calculatedLintLength" app/client/src/components/editorComponents/CodeEditor/lintHelpers.test.ts

# Look at the LintError type definition
echo "Checking LintError type definition..."
rg -A 5 "type LintError" --type ts

Length of output: 939


Script:

#!/bin/bash
# Find LintError interface definition
echo "Looking for LintError interface..."
ast-grep --pattern 'interface LintError {
  $$$
}'

# Check test cases for variable length calculation
echo "Checking test cases with variables..."
rg -B 10 -A 10 'variables:' app/client/src/components/editorComponents/CodeEditor/lintHelpers.test.ts

# Check test cases with lintLength
echo "Checking test cases with lintLength..."
rg -B 10 -A 10 'lintLength:' app/client/src/components/editorComponents/CodeEditor/lintHelpers.test.ts

Length of output: 5568

app/client/src/components/editorComponents/CodeEditor/lintHelpers.test.ts (2)

262-286: LGTM! Well-structured test for explicit lintLength.

The test effectively verifies that the provided lintLength is respected in the annotation calculation.


288-311: LGTM! Good backward compatibility test.

The test ensures that length calculation works correctly when lintLength is not provided, maintaining compatibility with existing behavior.

app/client/src/utils/DynamicBindingUtils.ts (2)

439-439: LGTM: Clean interface extension

The addition of the optional lintLength property maintains backward compatibility while supporting direct length calculation from ESLint results.


439-439: Verify LintError interface implementations

Let's ensure all implementations and consumers of LintError are compatible with the new property.

@ayushpahwa ayushpahwa merged commit 5ec2ff1 into release Nov 19, 2024
@ayushpahwa ayushpahwa deleted the feat/eslint/lint-length-processing branch November 19, 2024 07:55
github-actions bot pushed a commit to Zeral-Zhang/appsmith that referenced this pull request Nov 20, 2024
## Description

As part of project to migrate linter to eslint, a small dependency we
need to take care of is to update how we calculate the length of the
lint to be shown. Today we use an array of variables and calculate their
char lengths. With eslint, we directly get the length and hence can be
passed down to this function. To ensure backward compatibility till we
are still phasing out JSHint, a conditional check is added to the
linthelper file.

> [!NOTE] > This PR is part of a series of [stacked
diffs](https://newsletter.pragmaticengineer.com/p/stacked-diffs) and
might have changes from it's parent PRs. Untill the blocking parent PRs
are merged, this diff would show more changes than are relevant for this
PR. Blocking PRs: - appsmithorg#36543

Fixes appsmithorg#36546 

## Automation

/test js sanity

### 🔍 Cypress test results
<!-- This is an auto-generated comment: Cypress test results  -->
> [!TIP]
> 🟢 🟢 🟢 All cypress tests have passed! 🎉 🎉 🎉
> Workflow run:
<https://github.com/appsmithorg/appsmith/actions/runs/11907265100>
> Commit: 7da61e7
> <a
href="https://internal.appsmith.com/app/cypress-dashboard/rundetails-65890b3c81d7400d08fa9ee5?branch=master&workflowId=11907265100&attempt=2"
target="_blank">Cypress dashboard</a>.
> Tags: `@tag.JS, @tag.Sanity`
> Spec:
> <hr>Tue, 19 Nov 2024 07:50:17 UTC
<!-- end of auto-generated comment: Cypress test results  -->


## Communication
Should the DevRel and Marketing teams inform users about this change?
- [ ] Yes
- [x] No


<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->

## Summary by CodeRabbit

- **New Features**
- Introduced a new optional property `lintLength` to enhance lint error
reporting.
- Improved handling of dynamic bindings for better accuracy and
responsiveness to changes.

- **Bug Fixes**
- Enhanced test coverage for lint error annotations to ensure correct
behavior with and without `lintLength`.

- **Documentation**
- Updated comments for clarity regarding new linting logic and error
handling.

<!-- end of auto-generated comment: release notes by coderabbit.ai -->
ayushpahwa pushed a commit that referenced this pull request Nov 22, 2024
## Description
We are shifting the linter engine for jshint to eslint. This PR adds the
package needed for the same and also adds the required configs. The
eslint feature is behing a rollout feature flag, it's currently at 0%
right now.

> [!NOTE] > This PR is part of a series of [stacked
diffs](https://newsletter.pragmaticengineer.com/p/stacked-diffs) and
might have changes from it's parent PRs. Untill the blocking parent PRs
are merged, this diff would show more changes than are relevant for this
PR.
Blocking PRs: - #36548 

Fixes #37254 

## Automation

/test js sanity

### 🔍 Cypress test results
<!-- This is an auto-generated comment: Cypress test results  -->
> [!TIP]
> 🟢 🟢 🟢 All cypress tests have passed! 🎉 🎉 🎉
> Workflow run:
<https://github.com/appsmithorg/appsmith/actions/runs/11965021215>
> Commit: 579e477
> <a
href="https://internal.appsmith.com/app/cypress-dashboard/rundetails-65890b3c81d7400d08fa9ee5?branch=master&workflowId=11965021215&attempt=1"
target="_blank">Cypress dashboard</a>.
> Tags: `@tag.JS, @tag.Sanity`
> Spec:
> <hr>Fri, 22 Nov 2024 02:49:47 UTC
<!-- end of auto-generated comment: Cypress test results  -->


## Communication
Should the DevRel and Marketing teams inform users about this change?
- [ ] Yes
- [ ] No


<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
## Summary by CodeRabbit

## Release Notes

- **New Features**
- Integrated ESLint support alongside existing JSHint functionality for
enhanced linting capabilities.
	- Added a new dependency for ESLint linting.

- **Improvements**
- Enhanced error handling and reporting for linting errors, ensuring
consistency across different linting tools.
- Updated testing framework to accommodate multiple linter types without
duplicating logic.
- Introduced new functions for sanitizing and converting ESLint errors
to the application's format.
	- Added support for structured cloning in the testing setup.
- Improved logic for determining main actions and error handling in
conditional expressions.

- **Bug Fixes**
- Improved logic for handling lint errors, particularly in
differentiating between ESLint and JSHint errors.

- **Documentation**
	- Updated comments for clarity on linting processes and configurations.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->
github-actions bot pushed a commit to Zeral-Zhang/appsmith that referenced this pull request Nov 27, 2024
## Description
We are shifting the linter engine for jshint to eslint. This PR adds the
package needed for the same and also adds the required configs. The
eslint feature is behing a rollout feature flag, it's currently at 0%
right now.

> [!NOTE] > This PR is part of a series of [stacked
diffs](https://newsletter.pragmaticengineer.com/p/stacked-diffs) and
might have changes from it's parent PRs. Untill the blocking parent PRs
are merged, this diff would show more changes than are relevant for this
PR.
Blocking PRs: - appsmithorg#36548 

Fixes appsmithorg#37254 

## Automation

/test js sanity

### 🔍 Cypress test results
<!-- This is an auto-generated comment: Cypress test results  -->
> [!TIP]
> 🟢 🟢 🟢 All cypress tests have passed! 🎉 🎉 🎉
> Workflow run:
<https://github.com/appsmithorg/appsmith/actions/runs/11965021215>
> Commit: 579e477
> <a
href="https://internal.appsmith.com/app/cypress-dashboard/rundetails-65890b3c81d7400d08fa9ee5?branch=master&workflowId=11965021215&attempt=1"
target="_blank">Cypress dashboard</a>.
> Tags: `@tag.JS, @tag.Sanity`
> Spec:
> <hr>Fri, 22 Nov 2024 02:49:47 UTC
<!-- end of auto-generated comment: Cypress test results  -->


## Communication
Should the DevRel and Marketing teams inform users about this change?
- [ ] Yes
- [ ] No


<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
## Summary by CodeRabbit

## Release Notes

- **New Features**
- Integrated ESLint support alongside existing JSHint functionality for
enhanced linting capabilities.
	- Added a new dependency for ESLint linting.

- **Improvements**
- Enhanced error handling and reporting for linting errors, ensuring
consistency across different linting tools.
- Updated testing framework to accommodate multiple linter types without
duplicating logic.
- Introduced new functions for sanitizing and converting ESLint errors
to the application's format.
	- Added support for structured cloning in the testing setup.
- Improved logic for determining main actions and error handling in
conditional expressions.

- **Bug Fixes**
- Improved logic for handling lint errors, particularly in
differentiating between ESLint and JSHint errors.

- **Documentation**
	- Updated comments for clarity on linting processes and configurations.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ok-to-test Required label for CI skip-changelog Adding this label to a PR prevents it from being listed in the changelog Task A simple Todo Workflows Pod Issues that the workflows team owns Workflows Product Issues related to the workflows product

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Task]: Improve lint length calculation logic with eslint

2 participants