Bug: auto-fix with eslint-plugin-prettier causes code to run with errors #15354
Labels
3rd party plugin
This is an issue related to a 3rd party plugin, config, or parser
archived due to age
This issue has been archived; please open a new issue for any further discussion
bug
ESLint is working incorrectly
repro:needed
Projects
Environment
Node version: 14.18.1
npm version: 6.14.15
Local ESLint version: v8.3.0
Operating System: macOS 10.15.6
What parser are you using?
@typescript-eslint/parser
What did you do?
Configuration
What did you expect to happen?
This is the code repository that can be used to reproduce: test-eslint-prettier:
git clone git@github.com:await-ovo/test-eslint-prettier.git
cd test-eslint-prettier
yarn install
yarn eslint --fix ./src/index.ts
After executing
yarn eslint --fix ./src/index.ts
in the root directory, the code should be formatted to look like this:What actually happened?
In fact, the code after the automatic fix is as follows:
You can see that the comma before the second parameter is missing.
Participation
Additional comments
I found that in the loop of trying to fix the code, as soon as the range property of the next fix intersects with the previous fix, the fix is skipped and the problem is put into the remainingMessages array. Subsequent fixes that do not intersect will still be used
This can lead to problems in the figure above:
item > 1
when the range is[112, 138]
.[137, 139]
, the fix is skipped because 137 is smaller than the previous 138. Here is the code fixed by prettier, with the comma moved to the previous line.[140, 145]
, it changes, [0]
to[0],
.So the comma between the arguments of the
useMemo
function is lost.I'm not sure if this is an ESLint problem or a Prettier problem, but I've found that if the fix range overlaps, just ending the fix and re-executing verify and applyFixes can avoids this problem:
I'm not sure if this is the right fix for this problem, please give me some guidance or advice, thank you for your help.
The text was updated successfully, but these errors were encountered: