Conflict with prettier
See original GitHub issueTell us about your environment
- ESLint Version: 7.31.0 (was reproducible on 7.29.0 too)
- Node Version: v14.17.2
- npm Version: 6.14.13
What parser (default, @babel/eslint-parser
, @typescript-eslint/parser
, etc.) are you using? babel-eslint@10.1.0
Please show your full configuration:
package.json
{
"scripts": {
"lint-fix": "eslint --fix problem.js"
},
"devDependencies": {
"eslint": "^7.31.0",
"eslint-config-prettier": "^8.3.0",
"eslint-plugin-prettier": "^3.4.0",
"prettier": "^2.3.2",
"prettier-eslint": "^13.0.0"
},
"dependencies": {
"babel-eslint": "^10.1.0"
}
}
Configuration
module.exports = {
plugins: ['prettier'],
extends: [
'eslint:recommended',
"plugin:prettier/recommended"
],
parser: 'babel-eslint'
};
.prettierrc
{
"singleQuote": true,
"jsxSingleQuote": true,
"semi": true,
"printWidth": 120,
"tabWidth": 2
}
What did you do? Please include the actual source code causing the issue, as well as the command that you used to run ESLint.
I’m trying to run eslint --fix problem.js
to fix following code:
if (true) {
const isReproducible = !!1 ?
['apple', 'banana', 'orange', 'pineapple', 'apple', 'banana', 'orange', 'pineapple']
: ['apple', 'banana', 'orange', 'pineapple'];
}
What did you expect to happen?
I expected eslint --fix
to not add syntax errors to the file
What actually happened? Please include the actual, raw output from ESLint.
if (true) {
const isReproducible = 1 ?
? ['apple', 'banana', 'orange', 'pineapple', 'apple', 'banana', 'orange', 'pineapple']
: ['apple', 'banana', 'orange', 'pineapple'];
}
eslint --fix output
/home/strrife/Projects/eslint-repro/problem.js
3:5 error Parsing error: Unexpected token
1 | if (true) {
2 | const isReproducible = 1 ?
> 3 | ? ['apple', 'banana', 'orange', 'pineapple', 'apple', 'banana', 'orange', 'pineapple']
| ^
4 | : ['apple', 'banana', 'orange', 'pineapple'];
5 | }
6 |
✖ 1 problem (1 error, 0 warnings)
It looks like the no-extra-boolean-cast
somehow conflicts with the prettier config. I have experienced similar issues previously when formatting rules were conflicting with prettier. Disablign them made sense, but it is not the case here since prettier would not be fixing no-extra-boolean-cast
.
Fixing the file manually and running esling --fix again works just fine.
Also, fixing the following piece of code:
const isReproducible = !!1 ?
['apple', 'banana', 'orange', 'pineapple', 'apple', 'banana', 'orange', 'pineapple']
: ['apple', 'banana', 'orange', 'pineapple'];
does not create syntax errors.
Thanks, best regards, Alexander
Issue Analytics
- State:
- Created 2 years ago
- Comments:6 (4 by maintainers)
Top GitHub Comments
This looks like a known bug in
eslint-plugin-prettier
. ESLint prevents conflicts by not applying overlapping fixes, but each individual fix should be complete (should produce valid code after applying) and thus independent of other fixes, which isn’t always the case with fixes thateslint-plugin-prettier
provides: https://github.com/prettier/eslint-plugin-prettier/issues/65#issuecomment-339224115.Rules don’t know what other rules are doing. We can’t possibly guarantee that every rule created by a third party will work correctly with core ESLint rules. I’d suggest following up with the prettier folks.