chore: update logic to calculate length of lint#36548
Conversation
WalkthroughThe changes in this pull request enhance the linting functionality by introducing a new optional property, Changes
Assessment against linked issues
Possibly related PRs
Suggested labels
Suggested reviewers
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? 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
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)
Other keywords and placeholders
Documentation and Community
|
|
This PR has not seen activitiy for a while. It will be closed in 7 days unless further activity is detected. |
|
This PR has been closed because of inactivity. |
There was a problem hiding this comment.
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 maintainabilityThe length calculation logic is correct but could be enhanced:
- Extract the default length as a named constant
- Simplify the variable-based calculation using array methods
- 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
📒 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
lintLengthand with length calculation fromvariables - All callers use the function correctly through a consistent interface
- The optional
lintLengthparameter 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.
## 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 -->
## 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 -->
## 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 -->
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.
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.SanitySpec:
Tue, 19 Nov 2024 07:50:17 UTC
Communication
Should the DevRel and Marketing teams inform users about this change?
Summary by CodeRabbit
New Features
lintLengthto enhance lint error reporting.Bug Fixes
lintLength.Documentation