-
Notifications
You must be signed in to change notification settings - Fork 4.6k
feat: show lint errors in code editor #6265
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
Merged
Merged
Changes from 26 commits
Commits
Show all changes
39 commits
Select commit
Hold shift + click to select a range
0382d29
show lint errors as warnings
vnodecg 1d2678b
Merge branch 'release' into feature/linting-errors
vnodecg 966c446
Merge branch 'release' into feature/linting-errors
vnodecg 733361d
add initial code
vnodecg 6e766ac
Merge remote-tracking branch 'origin/release' into feature-lint-errors
vnodecg 15cf1e2
adjust editor positions
vnodecg 07b8235
update pr comments
vnodecg 7ae6b66
mark jshint errors
vnodecg 4631e60
Merge remote-tracking branch 'origin/release' into FEATURE/linting-erβ¦
vnodecg d8ec26c
reset changes
vnodecg 81c675c
remove unused prop
vnodecg c870580
fix test errors
vnodecg 36ccf2c
remove unused imports
vnodecg 8024f66
dont show warning in the error counter
vnodecg 336a59e
show yellow if warning
vnodecg 4609742
remove active error functionality
vnodecg 4b85ec8
update linter to use async functionality
vnodecg fe79c2e
update linter messages
vnodecg 8983554
update binding positions
vnodecg 106d78d
fix evaluate tests
vnodecg c6219f1
Merge branch 'release' into feature/Show-lint-errors-in-codeeditor
vnodecg 7c3cec6
Merge branch 'feature/linting-errors' into feature/Show-lint-errors-iβ¦
vnodecg ca40e4c
dont show undefined errors in debugger
vnodecg 35989b4
move lint code to separate file
vnodecg afbddef
update testes
vnodecg a6dde5e
remove unused import
vnodecg 0393726
update tests
vnodecg 97aa7bc
address pr comments
vnodecg 8c89473
add comment to explain why
vnodecg 22c109b
Merge branch 'release' into feature/Show-lint-errors-in-codeeditor
vnodecg 6fe0c95
Merge branch 'release' into feature/Show-lint-errors-in-codeeditor
vnodecg b82c8e5
replace proper regex
vnodecg ed9f8fe
fix undefined message error
vnodecg 6c6793a
Update styling for warnings
vnodecg 31d4b06
Merge branch 'release' into feature/Show-lint-errors-in-codeeditor
hetunandu 08085d2
Fix crashing error
hetunandu d9d125c
Add feature flags
hetunandu b27aa58
Merge branch 'release' into feature/Show-lint-errors-in-codeeditor
hetunandu 45ce0cf
fix Debugger error counts checks
hetunandu File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
30 changes: 30 additions & 0 deletions
30
app/client/src/components/editorComponents/CodeEditor/lintHelpers.test.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| import { getKeyPositionInString, getAllOccurences } from "./lintHelpers"; | ||
|
|
||
| describe("getAllOccurences()", function() { | ||
| it("should get all the indexes", () => { | ||
| const res = getAllOccurences("this is a `this` string", "this"); | ||
| expect(res).toEqual([0, 11]); | ||
| }); | ||
|
|
||
| it("should return empty array", () => { | ||
| expect(getAllOccurences("this is a string", "number")).toEqual([]); | ||
| }); | ||
| }); | ||
|
|
||
| describe("getKeyPositionsInString()", () => { | ||
| it("should return results for single line string", () => { | ||
| const res = getKeyPositionInString("this is a `this` string", "this"); | ||
| expect(res).toEqual([ | ||
| { line: 0, ch: 0 }, | ||
| { line: 0, ch: 11 }, | ||
| ]); | ||
| }); | ||
|
|
||
| it("should return results for multiline string", () => { | ||
| const res = getKeyPositionInString("this is a \n`this` string", "this"); | ||
| expect(res).toEqual([ | ||
| { line: 0, ch: 0 }, | ||
| { line: 1, ch: 1 }, | ||
| ]); | ||
| }); | ||
| }); |
103 changes: 103 additions & 0 deletions
103
app/client/src/components/editorComponents/CodeEditor/lintHelpers.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,103 @@ | ||
| import _ from "lodash"; | ||
| import { Annotation, Position } from "codemirror"; | ||
| import { | ||
| EvaluationError, | ||
| PropertyEvaluationErrorType, | ||
| } from "utils/DynamicBindingUtils"; | ||
|
|
||
| export const getAllOccurences = (str: string, key: string) => { | ||
| const indicies = []; | ||
| const keylen = key.length; | ||
| let index, startIndex; | ||
| index = str.indexOf(key, startIndex); | ||
| while (index > -1) { | ||
| indicies.push(index); | ||
| startIndex = index + keylen; | ||
| index = str.indexOf(key, startIndex); | ||
| } | ||
|
|
||
| return indicies; | ||
| }; | ||
|
|
||
| export const getKeyPositionInString = ( | ||
| str: string, | ||
| key: string, | ||
| ): Position[] => { | ||
| const indicies = getAllOccurences(str, key); | ||
| let positions: Position[] = []; | ||
| if (str.includes("\n")) { | ||
| for (const index of indicies) { | ||
| const substr = str.substr(0, index); | ||
| const substrLines = substr.split("\n"); | ||
| const ch = _.last(substrLines)?.length || 0; | ||
| const line = substrLines.length - 1; | ||
|
|
||
| positions.push({ line, ch }); | ||
| } | ||
| } else { | ||
| positions = indicies.map((index) => ({ line: 0, ch: index })); | ||
| } | ||
| return positions; | ||
| }; | ||
|
|
||
| export const getLintAnnotations = ( | ||
| value: string, | ||
| errors: EvaluationError[], | ||
| ): Annotation[] => { | ||
| const annotations: Annotation[] = []; | ||
| const lintErrors = errors.filter( | ||
| (error) => error.errorType === PropertyEvaluationErrorType.LINT, | ||
| ); | ||
|
|
||
| lintErrors.forEach((error) => { | ||
| const { errorMessage, originalBinding, severity, variables } = error; | ||
|
|
||
| if (!originalBinding) { | ||
| return annotations; | ||
| } | ||
|
|
||
| // We find the location of binding in the editor value and then | ||
| // we find locations of jshint variabls (a, b, c, d) in the binding and highlight them | ||
| const bindingPositions = getKeyPositionInString(value, originalBinding); | ||
|
|
||
| for (const bindingLocation of bindingPositions) { | ||
| if (variables) { | ||
| for (const variable of variables) { | ||
| if (variable && originalBinding.includes(variable)) { | ||
| const variableLocations = getKeyPositionInString( | ||
| originalBinding, | ||
| variable, | ||
| ); | ||
|
|
||
| for (const variableLocation of variableLocations) { | ||
| const from = { | ||
| line: bindingLocation.line + variableLocation.line, | ||
| // if the binding is a multiline function we need to | ||
| // use jshint variable position as the starting point | ||
| ch: | ||
| variableLocation.line > 0 | ||
| ? variableLocation.ch | ||
| : variableLocation.ch + bindingLocation.ch, | ||
| }; | ||
|
|
||
| const to = { | ||
| line: from.line, | ||
| ch: from.ch + variable.length, | ||
| }; | ||
|
|
||
| const annotation = { | ||
| from, | ||
| to, | ||
| message: errorMessage, | ||
| severity: severity, | ||
| }; | ||
|
|
||
| annotations.push(annotation); | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } | ||
| }); | ||
| return annotations; | ||
| }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -5,6 +5,7 @@ enum LOG_TYPE { | |
| ACTION_EXECUTION_SUCCESS, | ||
| ENTITY_DELETED, | ||
| EVAL_ERROR, | ||
| EVAL_WARNING, | ||
| ACTION_UPDATE, | ||
| } | ||
|
|
||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.