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.
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.
The readability is decreased. It becomes more tedious to review and modify the code.
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.
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
}
}
class Foo {
public int a;
public int b;
...
public void doSomething() {
if(something) {
doSomethingElse();
}
}
}
You can adopt a tool or configure your IDE to take care of code formatting automatically.