jhipster / prettier-java

Prettier Java Plugin
http://www.jhipster.tech/prettier-java/
Apache License 2.0
1.06k stars 103 forks source link

How do specify plugins without requiring a fully qualified path? #639

Closed larsks closed 3 weeks ago

larsks commented 5 months ago

I have installed prettier and prettier-plugin-java globally:

$ npm -g list
/home/larsks/lib/npm-packages/lib
├── prettier-plugin-java@2.5.0
└── prettier@3.2.4

Attempting to format some Java code like this failed:

$ prettier Example.java
[error] Cannot find package 'prettier-plugin-java' imported from /home/larsks/tmp/java/noop.js

That's unpleasant but perhaps expected based on #508. But this also fails:

$ prettier --plugin prettier-plugin-java Tile.java
[error] Cannot find package 'prettier-plugin-java' imported from /home/larsks/tmp/java/noop.js

The only thing that worked was this:

$ prettier --plugin ~/lib/npm-packages/lib/node_modules/prettier-plugin-java/dist/index.js Tile.java
[error] Cannot find package 'prettier-plugin-java' imported from /home/larsks/tmp/java/noop.js

And...that's a lot of typing. I would put that into .prettierrc.yaml, but neither ~ nor $HOME work in that file to refer to my home directory, which means that I can't suggest this to colleagues as a generic solution, and if I happen to have different home directories in different environments (which I do) I can't use the same configuration file (and I can't make .prettierrc part of a project repository, because it would need to be modified by everybody in their own working directory).

Is there any way to make this work in a more graceful fashion?

jtkiesel commented 5 months ago

This appears to be identical to #630. See my response there for a temporary workaround.

jtkiesel commented 3 weeks ago

Closing as duplicate of #630.