ESLint might give wrong position information
See original GitHub issueAs the above title says, It’s because that ESLint give wrong position information.
Tell us about your environment
- ESLint Version: 6.8.0
- Node Version: 10.15.3
- npm Version: 6.4.1
- OS System: Windows 10 Pro(64-bit)
What parser (default, Babel-ESLint, etc.) are you using? default
Please show your full configuration: Here is a configuration file for ESLint
What did you do? Please include the actual source code causing the issue, as well as the command that you used to run ESLint. Here is a minimal reproducible example, And the following is some code snippet
import isNil from 'lodash/isNil'
import linterModule from 'eslint/lib/linter/linter'
import defaultEslintConfig from '../assets/json/eslint.json'
const Pos = CodeMirror.Pos
const linter = new linterModule.Linter()
function validator(text, options) {
const result = []
if (!text) return result
const [
config = defaultEslintConfig,
wrappedText = `async () => {\n${text}\n}`,
] = []
const errors = linter.verify(wrappedText, {
...config,
})
for (let i = 0; i < errors.length; i++) {
const error = errors[i]
result.push({
message: error.message,
severity: getSeverity(error),
from: Pos(error.line - 1 - 1, error.column - 1),
to: Pos(
isNil(error.endLine) ? error.line - 1 - 1 : error.endLine - 1 - 1,
isNil(error.endColumn) ? error.column : error.endColumn - 1,
),
})
}
return result
}
CodeMirror.registerHelper('lint', 'javascript', validator)
function getSeverity(error) {
switch (error.severity) {
case 1:
return 'warning'
case 2:
default:
return 'error'
}
}
The command that I used to run ESLint is npm start
npm start
What did you expect to happen? Showing lint message after removing the right-most close curly
What actually happened? Please include the actual, raw output from ESLint. Not showing lint message after removing the right-most close curly
Are you willing to submit a pull request to fix this bug? No
Related Issue https://github.com/codemirror/CodeMirror/issues/6240
Issue Analytics
- State:
- Created 3 years ago
- Comments:6 (3 by maintainers)
Top GitHub Comments
@liuliangsir thanks for the issue!
I believe @anikethsaha’s analysis is correct, so you’ll probably need to adjust the code that transforms positions from the wrapped input to the original input.
Nevertheless, there’s not enough information to evaluate if this is really a bug with reported locations. Could you please make a file with the code in question, then run eslint with
-f json
on that file, and post both the code and the output here?I can’t reproduce this in the demo. as it does shows parsing error when you remove the right-most curly brace. I did try with the wrapped text and its working fine.
demo
I think you are getting the correct error but it’s being hidden because of the wrapped code. for the following code,
as you are wrapping the test, the following code is being sent to eslint
so when you remove the right-most curly braces of the code in the playground, its actually removing the braces of inner function which is visible in the playground. so the code which is sent is this
now the eslint will report a error with unexpected token at line 3, cause the inner function is fine , there is missing
}
for the async functionbut this is not visible in the playground so that’s why I think its not showing you the error here
I am not sure about this as I don’t know-how
codemirror-lint-eslint
works under the hood but it seems eslint is working fine.Also, the missing highlighted position in the eslint demo page might be cause it doesn’t highlight missing tokens in the playground. but the position is correct 👍