apheleia
apheleia copied to clipboard
Add prettier-eslint as a prettier format option
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)
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?
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.
Got it, okay, that makes sense.
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.
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.
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