Prettier lint error isn't fixable
See original GitHub issuePrettier 1.14.3 Playground link
--parser babylon
--single-quote
--trailing-comma es5
Input:
function set(key, value) {
// DEV NOTE: We use assign here to create a new object so that Ember can
// register and rollback the changes to availableHours
const time = Object.assign({}, this.get('time'));
const selectedPeriod = this.get('selectedPeriod');
time.hour = (Number(value) % 12) + (selectedPeriod == 'PM' ? 12 : 0);
this.set('time', time);
return value;
}
Output:
function set(key, value) {
// DEV NOTE: We use assign here to create a new object so that Ember can
// register and rollback the changes to availableHours
const time = Object.assign({}, this.get('time'));
const selectedPeriod = this.get('selectedPeriod');
time.hour = (Number(value) % 12) + (selectedPeriod == 'PM' ? 12 : 0);
this.set('time', time);
return value;
}
Expected behavior:
I’ve been running into a pretty frustrating issue where I keep getting a Prettier error, running the autoformatter doesn’t fit it, and then when I fix it manually, I get another error that the original formatting is correct.
Here’s the error:
30:19 error Replace `(Number(value)·%·12)` with `Number(value)·%·12` prettier/prettier
69:19 error Replace `(time.hour·%·12)` with `time.hour·%·12` prettier/prettier
But when I fix it manually, it shows this error:
30:19 error Replace `Number(value)·%·12` with `(Number(value)·%·12)` prettier/prettier
69:19 error Replace `time.hour·%·12` with `(time.hour·%·12)` prettier/prettier
And the autoformatter doesn’t notice it at all.
Any thoughts on what I can do? I’m not sure if this issue is in Prettier’s domain or if it’s an issue with the ESLint plugin.
Issue Analytics
- State:
- Created 5 years ago
- Comments:7 (4 by maintainers)
Top Results From Across the Web
Don't just lint your code - fix it with Prettier - freeCodeCamp
Linters are powerful and provide an easy way to scan your code for syntax errors that could lead to bugs. Or they can...
Read more >How can I solve the prettier/prettier problem - Stack Overflow
This error is related to Windows Line endings being different from Unix ones. Try running npx prettier --write . on your project's directory ......
Read more >Using Prettier and ESLint to automate formatting and fixing ...
Learn how to use ESLint and Prettier together to automatically format and fix JavaScript code in your projects.
Read more >Integrating with Linters - Prettier
Linters usually contain not only code quality rules, but also stylistic rules. ... immediately lint files by running, for example, eslint --fix on...
Read more >How to use Prettier with ESLint and TypeScript in VSCode
Using the above config, Prettier will not format TypeScript code on ... (1 error, 1 warning) 1 error and 0 warnings potentially fixable...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Ok, thanks!
What you need to do now is to reduce your config. Keep removing stuff until the error goes away, or you’re left with the minimal setup to reproduce the problem. Then post all of the files and steps to reproduce here. The easiest way is to make a new repo and put everything there. Let me know if you need any help with any of that!
The “autoformatter” just refers to:
I’m using Ember, so ESLint gets run as a part of
ember test
, and ESLint is both disagreeing with Prettier and disagreeing with itself. Running the above Prettier command never shows any formatting issues. Running ESLint shows a Prettier error, and then if I fix the error, it says that my original code was correct and throws a new lint error that contradicts the prior one.We’re already using
eslint-config-prettier
!