-
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
How to disable formatting for snippet? Java/Maven #275
Comments
Hi @mattcopas, welcome to Spotless! What formatter from Spotless are you using? Does your setup look more like this: spotless {
java {
eclipse().configFile(...)
}
} or more like this: spotless {
java {
googleJavaFormat(...)
}
} or more like this? spotless {
java {
custom(...)
}
} If you're using If you're using If you're using a custom step or something else, I'd love it if you could provide us with more context e.g. an MVCE so we can understand better what you're trying to achieve. :) |
Oh, I should have asked first: are you using the Gradle plugin or the Maven plugin? |
@jbduncan Thanks for the quick response. We're using the google format, so it actually looks like this isn't a spotless issue but a google one (thank you for the link). Closing as out of scope. |
@mattcopas You're very welcome! I don't know if this will help, but with Spotless you can exclude certain files from being formatted, so if you have Java files that contain a lot of DSL-like code or unusual method chaining, you could exclude them from being formatted by google-java-format and manually format and maintain them yourself. Something like the following (untested, and may only work with Gradle's Kotlin DSL!): spotless {
java {
target(fileTree("src/**/*.java") {
exclude(
"**/com/company/package/FirstFileWeDoNotWantToFormat.java",
"**/com/company/package/SecondFileWeDoNotWantToFormat.java")
})
}
} |
Just an update that since |
@nedtwigg are there Adding I am using the maven plugin. |
@hanoch yes, but you'll need to enable |
How do I "enable toggleOffOn()" from the maven plugin? I am assuming that once enabled, the |
NVM, found it - https://github.com/diffplug/spotless/tree/main/plugin-maven#spotlessoff-and-spotlesson Worked for the XML format as well, with the |
BTW - is there a similar syntax to temporarily override an |
#817 is the closest we've got. |
How do I turn off formatting for a certain bit of code?
I am trying to disable it for a method chain.
I've tried using // @Formatter syntax
e.g.
but this approach doesn't seem to work.
Is there a way to do this in spotless?
Thanks
The text was updated successfully, but these errors were encountered: