apheleia icon indicating copy to clipboard operation
apheleia copied to clipboard

Add prettier-eslint as a prettier format option

Open ZelCloud opened this issue 2 years ago • 6 comments

Could we have prettier-eslint added as a prettier format option. If like the name suggests runs prettier first followed by eslint --fix.

(prettier-eslint  . (npx "prettier-eslint" "--stdin-filepath" filepath)

ZelCloud avatar Oct 08 '22 04:10 ZelCloud

No objection there. Although if the script just runs prettier followed by eslint, would it be better to add eslint as a separate formatter, since Apheleia already supports running multiple formatters in sequence?

raxod502 avatar Oct 25 '22 00:10 raxod502

Unfortunately, I don't think running the formatters in sequence is enough in this case. I believe issue #88 is still the blocking issue for getting prettier and eslint --fix to work in sequence with the desired results. The formatter prettier-eslint has a lot of additional logic and command line options to make this significantly easier to setup, and possible to use correctly from a global npx invoke.

ZelCloud avatar Oct 26 '22 02:10 ZelCloud

Got it, okay, that makes sense.

raxod502 avatar Oct 28 '22 00:10 raxod502

I looked into this a bit and this is my take on why running eslint and prettier separately doesn't work so well.

  • eslint cannot output formatted code to stdout, it only updates an input file in place
  • eslint discovers configuration relative to the file path
  • apheleia creates temporary files, when formatters use the inplace token, in a temporary directory path

We could reimplement logic to find the ESLint configuration, but the simpler thing is to let ESLint do that itself. Perhaps there's a solution for some sigil wherein formatters that act in place act on the real file, rather than a temporary one.

tilgovi avatar Apr 04 '23 18:04 tilgovi

It's possible, but I think it would really be better to simply tell the upstream maintainers that they need to fix their tool so it's possible to run it without mutating existing files. Or so that it's possible to pass the original filepath as an additional argument, as is the standard pattern. It's not a good architectural choice to try to work around every possible bad upstream decision in Apheleia.

raxod502 avatar Apr 06 '23 23:04 raxod502

Not sure how relevant this is, but --fix-dry-run sounds like it fixes one of the problems with eslint --fix and apheleia. https://eslint.org/docs/latest/use/command-line-interface#--fix-dry-run

Flirre avatar Jun 14 '23 12:06 Flirre