org.sonar.l10n.java.rules.java.S1120.html Maven / Gradle / Ivy
Indentation should be consistent to make the code easy to read, review and modify. To fix this issue, change the indentation so that the text
starts at the expected column.
Why is this an issue?
Consistent indentation is a simple and effective way to improve the code’s readability. It reduces the differences that are committed to source
control systems, making code reviews easier.
This rule raises an issue when the indentation does not match the configured value. Only the first line of a badly indented section is
reported.
The rule behaves consistently when the indentation settings of the IDE use spaces instead of tabs. Using tabs can lead
to inconsistent indentation because the width of a tab can be configured differently in different environments.
What is the potential impact?
The readability is decreased. It becomes more tedious to review and modify the code.
How to fix it
Change the indentation so that the text starts at the expected column. The expected column should be the configured indent size multiplied by the
level at which the code block is nested.
Code examples
Noncompliant code example
With an indent size of 2:
class Foo {
public int a;
public int b; // Noncompliant, expected to start at column 4
...
public void doSomething() {
if(something) {
doSomethingElse(); // Noncompliant, expected to start at column 6
} // Noncompliant, expected to start at column 4
}
}
Compliant solution
class Foo {
public int a;
public int b;
...
public void doSomething() {
if(something) {
doSomethingElse();
}
}
}
Going the extra mile
You can adopt a tool or configure your IDE to take care of code formatting automatically.
Resources
External coding guidelines