-
Notifications
You must be signed in to change notification settings - Fork 459
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Facing "Could not resolve parser" when using multiple prettier formats with different plugins #1162
Comments
I also have this issue with the latest version of the Spotless Gradle plugin, using its Prettier formatter step in 3 different sections (one Java, one XML, on SQL), specifying on each only the latest version of Prettier and the latest versions of those respective plugins. It's intermittant, and therefore seems to me like some kind of race condition. I can make it more likely to occur with "gradle spotlessApply --rerun-tasks" (to avoid up-to-date checking). It is fixed for me the same as @julb fixed his (putting all Prettier plugin dependencies on all references to the Prettier formatter step). Also note that it's not always that same error message. For example, if I'm having it format .sql files with the "sql" Spotless extension, and I do not specify the parser as "sql" in Prettier's config, when it complains, it will complain that it can't automatically discern the correct parser to use for that file extension (don't remember the exact wording). Example sometimes-broken Spotless Gradle configuration (using Kotlin DSL): import com.diffplug.spotless.LineEnding
plugins {
id("application")
id("com.diffplug.spotless") version "latest.release"
}
...
spotless {
encoding("UTF-8")
lineEndings = LineEnding.UNIX
java {
// This is included only for its ability to break up long strings and reformat JavaDoc comments.
googleJavaFormat().reflowLongStrings()
prettier(
mapOf(
"prettier" to "latest",
"prettier-plugin-java" to "latest"
)
)
.config(
mapOf(
"parser" to "java"
)
)
importOrder("")
removeUnusedImports()
trimTrailingWhitespace()
endWithNewline()
}
kotlinGradle {
ktlint("0.46.1")
.editorConfigOverride(mapOf("indent_size" to 2))
trimTrailingWhitespace()
endWithNewline()
}
format("xml") {
target(
"src/**/*.xml"
)
prettier(
mapOf(
"prettier" to "latest",
"@prettier/plugin-xml" to "latest"
)
)
.config(
mapOf(
"xmlSelfClosingSpace" to false,
"xmlWhitespaceSensitivity" to "ignore"
)
)
trimTrailingWhitespace()
endWithNewline()
}
sql {
target(
"src/**/*.sql"
)
prettier(
mapOf(
"prettier" to "latest",
"prettier-plugin-sql" to "latest"
)
)
.config(
mapOf(
"language" to "tsql",
"keywordCase" to "upper"
)
)
trimTrailingWhitespace()
endWithNewline()
}
} |
Since it only happens when the different formats use different plugins, it seems the workaround is to pass the same map of prettier + plugin versions for every format, like so (based on @Magotchi 's config): import com.diffplug.spotless.LineEnding
plugins {
id("application")
id("com.diffplug.spotless") version "latest.release"
}
...
spotless {
encoding("UTF-8")
lineEndings = LineEnding.UNIX
val prettierPlugins = mapOf(
"prettier" to "latest",
"prettier-plugin-java" to "latest",
"prettier-plugin-sql" to "latest",
"@prettier/plugin-xml" to "latest",
)
java {
// This is included only for its ability to break up long strings and reformat JavaDoc comments.
googleJavaFormat().reflowLongStrings()
prettier(prettierPlugins)
importOrder("")
removeUnusedImports()
trimTrailingWhitespace()
endWithNewline()
}
kotlinGradle {
ktlint("0.46.1")
.editorConfigOverride(mapOf("indent_size" to 2))
trimTrailingWhitespace()
endWithNewline()
}
format("xml") {
target(
"src/**/*.xml"
)
prettier(prettierPlugins)
.config(
mapOf(
"xmlSelfClosingSpace" to false,
"xmlWhitespaceSensitivity" to "ignore"
)
)
trimTrailingWhitespace()
endWithNewline()
}
sql {
target(
"src/**/*.sql"
)
prettier(prettierPlugins)
.config(
mapOf(
"language" to "tsql",
"keywordCase" to "upper"
)
)
trimTrailingWhitespace()
endWithNewline()
}
} This seems to be working for me. |
Fixed in |
If you are submitting a bug, please include the following:
gradlew spotless[Apply/Check] --stacktrace
If you're just submitting a feature request or question, no need for the above.
Summary of the problem
I'm configuring a pom where I want to have different rules for prettier according to file extension.
I followed the documentation and configure specific format section, with for each a specific prettier plugin.
I suspect that NodeJS installs are competing each other, and may lead to have a missing plugin on a specific execution.
I'm able to fix the issue if I install all the prettier plugins I use in each format section.
Maven version
3.8.4
Spotless version
2.22.0 with Node v16.14.2
Operating system
Windows
Spotless configuration
Stacktrace / Outputs
Outputs of target/spotless-node-modules-prettier-format/package.json:
The text was updated successfully, but these errors were encountered: