-
Notifications
You must be signed in to change notification settings - Fork 46
Description
Describe the bug
When an ESLint rule fails for code at the start of the line the issueColumn is stored as a -1 instead of 0.
This results in Betterer not being able to identify a reoccurring error when lines are added above the erroring code.
To Reproduce
Here is a simple repo with a reproduction of the issue: https://github.com/annaet/betterer-demo
In this branch I have applied a change that causes an update to the results file. However when you run npm run betterer it results in this error:
💥 Betterer (213ms): 1 test done! 1 test errored!
🔥 Enable eslint rules: "Enable eslint rules" got worse. (1 issue) 😔
・ 1 fixed issue in "/Users/anna.thomas/Development/betterer-demo/src/App.tsx".
・ New issue in "/Users/anna.thomas/Development/betterer-demo/src/App.tsx"!
・
・ /Users/anna.thomas/Development/betterer-demo/src/App.tsx
・ 9 | */
・ 10 |
・ > 11 | /* eslint-disable */
・ | ^^^^^^^^^^^^^^^^^^^^^ Unexpected unlimited 'eslint-disable' comment. Specify some rule names to disable.
・ 12 | function App() {
・ 13 | const [count, setCount] = useState(0)
・ 14 |
・
Error: "Enable eslint rules" got worse. (1 issue) 😔
at task (/Users/anna.thomas/Development/betterer-demo/node_modules/@betterer/reporter/src/components/suite/tasks.ts:66:13)
at async /Users/anna.thomas/Development/betterer-demo/node_modules/@betterer/tasks/src/tasks/TaskLogger.tsx:73:24
1 test got checked. 🤔
1 test got worse. 😔
It reports that 1 issue was fixed and a new error was identified, instead of understanding they're the same error.
Expected behavior
I'd expect the issueColumn to be saved as 0 instead of -1 and the results file to be updated correctly when new code is added above the erroring code.
Versions (please complete the following information):
- OS: MacOS
- Betterer Version: 5.4.0
- Node Version: 20.11.1
Additional context
I was able to get the results file to updated as expected when adding new code by removing the minus 1 from the following code:
packages/eslint/src/eslint.ts#L81
const startColumn = message.column; // - 1 was removed
From what I can tell eslint indexes it's line numbers from 1, but its column numbers from 0. Which is a bit confusing! 🤷♀️