Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prettier runs ESLint --fix even if requirePragma is set to true in .prettierrc #200

Closed
TiredFalcon opened this issue Feb 8, 2019 · 3 comments

Comments

@TiredFalcon
Copy link

TiredFalcon commented Feb 8, 2019

Versions:

  • prettier-eslint version: Included in the latest version of the prettier-vscode extension
  • node version: 8.15.0
  • npm (or yarn) version: 6.4.1

Have you followed the debugging tips?

No

Relevant code or config

.prettierrc and .eslintrc in the example repository.

settings.json

    "eslint.alwaysShowStatus": true,
    "eslint.autoFixOnSave": false,

    "prettier.requireConfig": true,
    "prettier.eslintIntegration": true,
    "prettier.tabWidth": 4,

    "editor.formatOnSave": true,
    "editor.formatOnPaste": false,
    "editor.formatOnType": false

What I did:

I opened a file containing old, non-pretty JavaScript code and hit Cmd+S to save it.

What happened:

The saving ran eslint --fix, even though no pragma comment was at the top of the file.
The pragma comment would look like this (source):

/**
 * @prettier
 */

Reproduction repository:
https://github.com/LambdaFalcon/h-prettier-eslint-bug

The file test.js shows the problem. It contains

var s = 'extremely_long_string____________________________________________________________________________________________';

Saving the file will convert the var to a const, meaning that eslint --fix was run.
Adding the pragma comment at the top and saving again will also move the string literal to a new line, meaning that Prettier was run.

Problem description:
The idea I had of this tool was to use Prettier (in my case on save) to also run eslint --fix, which it does correctly. However, I would have expected it respect the pragma comments also when running eslint --fix.

This makes sense also because if we set "editor.formatOnSave": false,, neither Prettier nor eslint --fix are run.

This is a big problem for large codebases with un-pretty code which could prefer to slowly review and prettify the code while still being able to instantly prettify on newer files.

Suggested solution:
Do not run eslint --fix if prettier did not run, or add an option for respecting the pragma not only with prettier but also with eslint --fix.

@TiredFalcon TiredFalcon changed the title Prettier runs even if requirePragma is set to true in .prettierrc Prettier runs ESLint --fix even if requirePragma is set to true in .prettierrc Feb 14, 2019
@TiredFalcon
Copy link
Author

Did someone see this? It is probably of lower importance, but important nevertheless since it's not the expected behaviour.

@zimme
Copy link
Member

zimme commented Feb 25, 2019

I've seen it, won't be able to fix anything until filsystem mocking and failing tests are fixed, sorry

@github-actions
Copy link
Contributor

Stale issue

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants