import-js / import-js/eslint-plugin-import
Bad/big range on error report
- Dominant language
- JavaScript
- Stars
- 5.9k
- Forks
- 1.5k
- PR merge metrics
- No merged PRs in 30d
Description
The plugin report a big/bad range about the error for example for `default-export` report all the function but should reporting just the lines of the missing export, this cause that for example plugin like Flycheck in Emacs highlight too much, see: https://github.com/flycheck/flycheck/issues/1730#issuecomment-614953310
Function:
```javascript
// test-file.js
export function getTestRemaining() {
const val = 'test';
const noError = 0;
return `${val}${noError}`;
}
```
Config:
```yaml
extends:
- eslint:recommended
plugins:
- import
rules:
import/prefer-default-export: 2
```
Report:
`eslint --format=json test-file.js`
```json
[
{
"filePath": "/home/camilo/Documents/projects/univision/univision-fe/packages/utilities/src/helpers/date/getTimeRemaining.js",
"messages": [
{
"ruleId": "import/prefer-default-export",
"severity": 2,
"message": "Prefer default export.",
"line": 5,
"column": 1,
"nodeType": "ExportNamedDeclaration",
"endLine": 10,
"endColumn": 2
}
],
"errorCount": 1,
"warningCount": 0,
"fixableErrorCount": 0,
"fixableWarningCount": 0,
"source": "/**\n * Test function with big range of error\n * @returns {string} test value\n */\nexport function testFun() {\n const val = 'test';\n const noError = 0;\n\n return `${val}${noError}`;\n}\n"
}
]
```
As you can see the error report start at line 5 and end in 10 and should be end at 5, for example a report about an undefined value is:
```json
[
{
"filePath": "test-file.js",
"messages": [
{
"ruleId": "no-undef",
"severity": 2,
"message": "'Nodefined' is not defined.",
"line": 7,
"column": 19,
"nodeType": "Identifier",
"messageId": "undef",
"endLine": 7,
"endColumn": 28
}
],
"errorCount": 1,
"warningCount": 0,
"fixableErrorCount": 0,
"fixableWarningCount": 0,
"source": "/**\n * Test function with big range of error\n * @returns {string} test value\n */\nexport default function testFun() {\n const val = 'test';\n const noError = Nodefined;\n\n return `${val}${noError}`;\n}\n"
}
]
```
With a internal eslint rule the report start at line 7 and end in the same line.
Contributor guide
Research direction
Reproduce the report with `eslint --format=json test-file.js` using the `import/prefer-default-export` rule and inspect how that rule determines its reported range. Done means the example reports the missing export on line 5 without spanning the whole function; add or update regression coverage if the project’s existing rule tests are found.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 42/100