HubSpot / prettier-maven-plugin

Apache License 2.0
116 stars 23 forks source link

Way to format this on save #110

Open jaoxford opened 2 weeks ago

jaoxford commented 2 weeks ago

Just curious if there's a way of formatting this on save? I am using intelliJ. I have tried to use the file-watcher plugin, with the following config for my IDE:

Screenshot 2024-06-20 at 15 11 19

When I save my file I get the following error:

//.m2/repository/com/hubspot/maven/plugins/prettier-maven-plugin/0.16/prettier-maven-plugin-0.16-prettier-java-0.7.0/prettier-java/node_modules/prettier/bin-prettier.js --write src/main/java/MyFile.java
[error] No matching files. Patterns tried: src/main/javaMyFile.java !**/node_modules/** !./node_modules/** !**/.{git,svn,hg}/** !./.{git,svn,hg}/**

Process finished with exit code 2

Here's the output of print-args:

printWidth=90
tabWidth=4
useTabs=false
noConfig=true
noEditorconfig=true
inputGlob=src/main/java/**/*.java
inputGlob=src/test/java/**/*.java
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  0.273 s
[INFO] Finished at: 2024-06-20T15:15:03+01:00
[INFO] ------------------------------------------------------------------------

Process finished with exit code 0

And if I manually trigger prettier:write that is also fine. Ideally this would be something that runs on every save, so I don't have to think about it!

Any idea or help would be appreciated!

jaoxford commented 2 weeks ago

Bit of an update:

I managed to get this to work, but there's a few things that don't work exactly as I had hoped.

It seems that running prettier from the file watcher behaves differently than how it's run in the pom.xml file, I think there's a few ways of getting this locked down.

  1. Ideally I'd be able to run mvn prettier:write inside of the file watcher instead of manually providing the prettier location.
  2. If that's not possible, use the .prettierrc in both ways of running prettier: From the file watcher / command line, & the pom / mvn