eslint-plugin-prettier icon indicating copy to clipboard operation
eslint-plugin-prettier copied to clipboard

Resolve conflicts with `arrow-body-style`(and other rules)

Open fisker opened this issue 4 years ago • 3 comments

To resolve this problem, all we have to do is protect our fix "range", so other rules won't do fix inside it.

  • Question: how wide should our range be, the whole file or the max diff range. I've draft #379 to protect whole file.
  • Impact: This will slow down eslint fix, ESLint takes up to 10 rounds to run rules, in the round of prettier/prettier other rule won't work.
  • Problem: We don't want report issues on whole file, but we can still report each difference but fix the whole file, use ESLint through CLI won't feel anything, but if running in editor, people may don't expect that happen. I got no good solution, in #379 I added a notice behind the error message, and to fix one difference I used suggestion API.

I'd like to ship this feature under "experimentalFix" flag first.

Another alternative solution #381 is protect whole file on every fix of difference, but this will takes many rounds to fix the whole file, seems unacceptable solution.

Thoughts?

fisker avatar Feb 02 '21 10:02 fisker

Maybe a totally different approach would be to try and bake these rules directly into prettier. I think it might start to break prettier's philosophy, but, the options could be un-documented and only available through a "secret" hatch if you will. (Probably just exposed when you run require('prettier')). I wonder if there could be an alternate prettier plugin. Plugins are typically used for supporting different languages (ruby, elm, etc) but it's one possible vector.

devinrhode2 avatar Oct 06 '21 16:10 devinrhode2

Turns out that even stacking eslint on top of prettier, eslint does not know how to even maintain prettier's formatting:

I tried to get eslint and prettier to play nice inside of vscode... but when I save the first return-less snippet of code, I'm getting this:

CleanShot 2022-07-19 at 12 26 01

Second time I save it.. eslint has nothing to do, prettier does a final fix to the formatting: CleanShot 2022-07-19 at 12 27 18

Using this vscode extension: https://github.com/prettier/prettier-vscode/issues/1555 rohit-gohri.format-code-action

here's relelvant .vscode/settings.json:

  // By default, format code with prettier onSave:
  //  (Currently, this mostly just handles markdown files and json files)
  "editor.formatOnSave": true,
  "editor.defaultFormatter": "esbenp.prettier-vscode",

  // Enable eslint vscode extension:
  "eslint.enable": true,
  "eslint.format.enable": false, // assert default
  "eslint.validate": [
    "javascript",
    "javascriptreact",
    "typescript",
    "typescriptreact"
  ],
  "prettier.useEditorConfig": true,
  "eslint.useESLintClass": true,
  "eslint.packageManager": "yarn",
  "eslint.probe": [],
  "[typescript]": {
    "editor.formatOnSave": false,
    "editor.codeActionsOnSave": [
      "source.formatDocument",
      "source.fixAll.eslint"

devinrhode2 avatar Jul 19 '22 17:07 devinrhode2

You should turn off the conflict rule for now and try to reload vscode after eslint/preittier config changed.

JounQin avatar Jul 19 '22 17:07 JounQin