question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Prettier lint error isn't fixable

See original GitHub issue

Prettier 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:closed
  • Created 5 years ago
  • Comments:7 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
lydellcommented, Oct 19, 2018

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!

1reaction
jackiehluocommented, Oct 19, 2018

The “autoformatter” just refers to:

prettier --write --single-quote --trailing-comma es5 'addon/**/*.js' 'app/**/*.js' 'config/**/*.js' 'tests/**/*.js'

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!

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found