Closed MaXeraph closed 3 years ago
Do you have more info on the error you got and what your project structure looks like? I would expect that you'd be able to add an inputGlob argument and have this work, for example <inputGlob>src/main/javascript/**/*.js</inputGlob>
https://github.com/HubSpot/prettier-maven-plugin#example-usage
My javascript files are in /src/main/webapp/resources/javascript/
, there are sub folders with js files as well
POM configuration:
<plugin>
<groupId>com.hubspot.maven.plugins</groupId>
<artifactId>prettier-maven-plugin</artifactId>
<version>0.14</version>
<configuration>
<prettierJavaVersion>1.3.0</prettierJavaVersion>
<printWidth>90</printWidth>
<tabWidth>2</tabWidth>
<useTabs>false</useTabs>
<ignoreConfigFile>true</ignoreConfigFile>
<ignoreEditorConfig>true</ignoreEditorConfig>
<!-- Use <inputGlobs> to override the default input patterns -->
<inputGlobs>
<!-- These are the default patterns, you can omit <inputGlobs> entirely unless you want to override them -->
<inputGlob>src/main/webapp/resources/javascript/**/*.js</inputGlob>
</inputGlobs>
</configuration>
<executions>
<execution>
<phase>validate</phase>
<goals>
<goal>${plugin.prettier.goal}</goal>
</goals>
</execution>
</executions>
</plugin>
And the error:
admin@admins bridge % mvn prettier:check -e
[INFO] Error stacktraces are turned on.
[INFO] Scanning for projects...
[INFO]
[INFO] ----------------------< com.company.team:bridge >----------------------
[INFO] Building bridge 0.1.1
[INFO] --------------------------------[ jar ]---------------------------------
[INFO]
[INFO] --- prettier-maven-plugin:0.14:check (default-cli) @ bridge ---
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 7.266 s
[INFO] Finished at: 2021-07-12T16:58:39-04:00
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal com.hubspot.maven.plugins:prettier-maven-plugin:0.14:check (default-cli) on project bridge: Error trying to run prettier-java: 1 -> [Help 1]
org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal com.hubspot.maven.plugins:prettier-maven-plugin:0.14:check (default-cli) on project bridge: Error trying to run prettier-java: 1
at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:215)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:156)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:148)
at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:117)
at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:81)
at org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build (SingleThreadedBuilder.java:56)
at org.apache.maven.lifecycle.internal.LifecycleStarter.execute (LifecycleStarter.java:128)
at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:305)
at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:192)
at org.apache.maven.DefaultMaven.execute (DefaultMaven.java:105)
at org.apache.maven.cli.MavenCli.execute (MavenCli.java:957)
at org.apache.maven.cli.MavenCli.doMain (MavenCli.java:289)
at org.apache.maven.cli.MavenCli.main (MavenCli.java:193)
at jdk.internal.reflect.NativeMethodAccessorImpl.invoke0 (Native Method)
at jdk.internal.reflect.NativeMethodAccessorImpl.invoke (NativeMethodAccessorImpl.java:62)
at jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke (DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke (Method.java:566)
at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced (Launcher.java:282)
at org.codehaus.plexus.classworlds.launcher.Launcher.launch (Launcher.java:225)
at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode (Launcher.java:406)
at org.codehaus.plexus.classworlds.launcher.Launcher.main (Launcher.java:347)
Caused by: org.apache.maven.plugin.MojoExecutionException: Error trying to run prettier-java: 1
at com.hubspot.maven.plugins.prettier.CheckMojo.handlePrettierNonZeroExit (CheckMojo.java:62)
at com.hubspot.maven.plugins.prettier.AbstractPrettierMojo.execute (AbstractPrettierMojo.java:84)
at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo (DefaultBuildPluginManager.java:137)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:210)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:156)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:148)
at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:117)
at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:81)
at org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build (SingleThreadedBuilder.java:56)
at org.apache.maven.lifecycle.internal.LifecycleStarter.execute (LifecycleStarter.java:128)
at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:305)
at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:192)
at org.apache.maven.DefaultMaven.execute (DefaultMaven.java:105)
at org.apache.maven.cli.MavenCli.execute (MavenCli.java:957)
at org.apache.maven.cli.MavenCli.doMain (MavenCli.java:289)
at org.apache.maven.cli.MavenCli.main (MavenCli.java:193)
at jdk.internal.reflect.NativeMethodAccessorImpl.invoke0 (Native Method)
at jdk.internal.reflect.NativeMethodAccessorImpl.invoke (NativeMethodAccessorImpl.java:62)
at jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke (DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke (Method.java:566)
at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced (Launcher.java:282)
at org.codehaus.plexus.classworlds.launcher.Launcher.launch (Launcher.java:225)
at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode (Launcher.java:406)
at org.codehaus.plexus.classworlds.launcher.Launcher.main (Launcher.java:347)
[ERROR]
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionException
I also tried to lint java files and it works fine, just wasnt sure why this was an issue
Hmm it's hard to tell what's going wrong because for some reason its just printing the return code and not any of the prettier output. However this worked fine for me:
<inputGlobs>
<inputGlob>src/main/javascript/**/*.js</inputGlob>
</inputGlobs>
Printed:
[INFO]
[INFO] --- prettier-maven-plugin:0.14:write (default-cli) @ Test ---
[INFO] Reformatted file: src/main/javascript/test/test.js 48ms
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 1.945 s
[INFO] Finished at: 2021-07-12T17:33:08-04:00
[INFO] ------------------------------------------------------------------------
My hunch is that maybe one of the js files is invalid or has syntax which prettier can't parse? Could you try putting just a single js file inside src/main/webapp/resources/javascript
with a very simple hello world function inside of it?
My hunch is that maybe one of the js files is invalid or has syntax which prettier can't parse? Could you try putting just a single js file inside
src/main/webapp/resources/javascript
with a very simple hello world function inside of it?
Looks like there's something off with the check
command, I tried running write
and I was able to reformat the files. Although I want to be able to run check
on our build system.
TURNS OUT, now that I realize that this is a desired result as there were files that were not formatted, and the check
command was failing due to that! Haha. So it has been working as expected.
Although I do wonder if there is a way to show violating files when running check
instead of just failing the goal....
ahh I see 👍 yeah we definitely want to print a more user-friendly message. At the moment we try to parse stdout from the prettier process which isn't super reliable, I wonder if we should use prettier's programmatic API so that we can hopefully get more structured output.
so currently there's no way to know what is the violating file when running check
?
Correct, I think the issue is that we only parse log lines which end in .java
:
https://github.com/HubSpot/prettier-maven-plugin/blob/2383d84f8cc9f1f58e381a7969bddba64ba15633/src/main/java/com/hubspot/maven/plugins/prettier/CheckMojo.java#L40
I see, yeah would be great if any invalid input files are shown not just java.
Yeah definitely. The issue is that the prettier output has some superfluous stuff, for example:
Checking formatting...
[warn] src/main/java/MyClass.java
[warn] Code style issues found in the above file(s). Forgot to run Prettier?
So we're basically trying to parse this output and filter it down to just the file paths. Previously the heuristic of looking for line.endsWith(".java")
worked fine, but it doesn't work well now that we can also format other file extensions
I think it's good to close the issue since we resolved the original issue, I also made another issue to request changes on outputting more details.
I was under the impression that the plugin uses Prettier core which could also format
.js
files as well. Or am I mistaken?