Unexpected behaviour from `indentWithSpaces(int)`
See original GitHub issueGiven the following build script and Java file on Gradle 3.2.1: build.gradle
plugins {
id 'java'
id 'com.diffplug.gradle.spotless' version '2.4.0'
}
group 'org.jbduncan'
version '1.0-SNAPSHOT'
sourceCompatibility = 1.8
repositories {
mavenCentral()
}
spotless {
format('example') {
target '**/*.java'
indentWithSpaces(4)
}
}
src/main/java/HelloWorld.java
public final class HelloWorld {
public String greeting() {
return "Hello, world!";
}
}
…I would have expected the Java file to turn into:
public final class HelloWorld {
public String greeting() {
return "Hello, world!";
}
}
or:
public final class HelloWorld {
public String greeting() {
return "Hello, world!";
}
}
…but it seems it doesn’t.
Have I misunderstood what indentWithSpaces(4)
is supposed to do here? I understand that it turns all tab indents into 4-space indents, but by my intuitive understanding it should also make sure that all space-indents have a number of spaces equal to a multiple of 4.
Issue Analytics
- State:
- Created 7 years ago
- Comments:8 (5 by maintainers)
Top Results From Across the Web
Unexpected behavior in JAVA - Stack Overflow
1 Answer 1 · The problem occurs in the first loop , while "fromSuraIndex" equal "i" equal 1, Why the debugger enter the...
Read more >Developers Who Use Spaces Make More Money Than Those ...
Analyzing the data leads us to an interesting conclusion. Coders who use spaces for indentation make more money than ones who use tabs,...
Read more >Almost Always Unsigned : r/programming - Reddit
Unsigned integers behave like modular arithmetic while they are used mainly for integer arithmetic. This leads to unexpected behaviour any ...
Read more >FormatExtension (plugin-gradle 5.6.1 API) - Javadoc.io
void, indentWithSpaces() ... void, indentWithSpaces(int numSpacesPerTab) ... it can't know if perhaps the behavior of your custom function has changed.
Read more >The point where you cease to understand how your code works
int b = 2+2; ... Do NOT indent with spaces, use Tab for that. ... You could of course add the targetable behaviour...
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
Yeah I was thinking to help tbh. I have a lot of spare time these days, so, why not contributing to OS? 😄
Thanks for the info, I’ll see if I can get a PR anytime soon. Would be my pleasure.
At first glance, the behavior you expect would be better than the behavior it actually has. But consider this case:
The behavior you expect would clobber those leading spaces, which seem to be the appropriate formatting even for
indentWithTabs()
. Many languages with block comments have indentation exceptions which are difficult to code in a general-purpose way.So the current behavior is to just ensure that if the formatting looks right, then it is right. Tabs and spaces are invisible, so you can’t see if you used the right one. With the current behavior, so long as it looks right, spotless will make sure that you used the right characters, and if you used the wrong one, it can swap it for you automatically.
I’m open to a more powerful compromise if we think of one 😃