jscheid / prettier.el

Prettier code formatting for Emacs.
GNU General Public License v3.0
167 stars 12 forks source link

Need a way to support prettier-eslint #23

Closed aspiers closed 4 years ago

aspiers commented 4 years ago

Sometimes prettier disagrees with eslint --fix. One solution to this is https://github.com/prettier/prettier-eslint which runs eslint --fix after every prettier invocation. It would be great if this mode could support that. It would probably require use of https://github.com/mantoni/eslint_d.js, maybe by integrating with https://github.com/aaronjensen/eslintd-fix or at least using a very similar approach.

jscheid commented 4 years ago

Personally, I would try to remove the need for this hack in some other way, maybe by relaxing lint rules or changing the code style. (At my day job, we've been using eslint-config-prettier). Running eslint --fix after every change is going to slow things down no matter how much you optimize it.

That said, I'm happy to accept a PR that adds support for this as long as it's in line with this package's philosophy, which means:

I'm afraid this would likely rule out using eslint_d.js:

prettier-eslint seems like a better option, and could maybe be changed to suit, but couldn't be used in its current form because currently:

I think the cleanest solution would be the following:

  1. Change prettier-eslint, or create a new packages (either from scratch or based on prettier-eslint), so that it has an API identical to Prettier's [†]
  2. Change this package so that it accepts a "search path" for which Prettier-like packages to try, which could default to something like '(that-package prettier).

The advantages of this approach are:

[†] Except that it might support additional configuration options. Also, from this package's perspective, currently only the following two API methods would have to be implemented: formatWithCursor, resolveConfig.sync.

aspiers commented 4 years ago

Thanks a lot for the very detailed and carefully considered response! I agree with everything you've written. I'm not 100% convinced that prettier-eslint's current design is great - it seems like a workaround for the fact that two tools are disagreeing over style and consequently fighting over how the same file should look. eslint-config-prettier does sound like a less conflicted approach.

I won't have time to do any more on this right now, but maybe I'll be able to return to it in a while.

jscheid commented 4 years ago

Sounds like this is unlikely to happen, which is fine by me. I'm closing this for now.