How to disable formatting for snippet? Java/Maven
See original GitHub issueHow 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.
public void foo() {
// @formatter:off
here()
.dont().format()
.the()
.code();
// @formatter:off
// format as normal from here...
}
but this approach doesn’t seem to work.
Is there a way to do this in spotless?
Thanks
Issue Analytics
- State:
- Created 5 years ago
- Comments:11 (6 by maintainers)
Top Results From Across the Web
intellij idea - How to disable code formatting for some part of ...
You must go to Preferences -> Code Style -> General -> Formatter Control and check Enable formatter markers in comments for this to...
Read more >Disable code formatting per region using comments
I'd like to selectively disable the IntelliJ IDEA code formatter for a portion of code just like I can in Eclipse. Does IntelliJ...
Read more >Java formatting and linting - Visual Studio Code
You can open the editor with the command Java: Open Java Formatter Settings with Preview. In the editor, you can change the formatter...
Read more >formatter-maven-plugin – Examples
Custom Configuration File · In Eclipse, go to Window > Preferences > Java > Code Style > Formatter · If you have a...
Read more >Configuring a Project to Exclude Certain Sonar Violations
In this short tutorial, we'll look at how to disable Sonar checks. ... This snippet defines analysis only for java files from the ......
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@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!):
Just an update that since
plugin-gradle 5.5.0
andplugin-maven 2.3.0
, it is now possible to use any formatter, in any language, and exclude specific snippets withspotless:off
tags.