You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The current algorithm for indentation verification just checks the current line length and compares it with the previous line length, If the absolute value of subtraction one from the other gives the values different from what user have configured, we have an error.
This approach is simple, but it does not take into account multiple cases. For instance, here, we have code with configured indent_size = 2:
package com.something.other;
import java.util.function.Consumer;
public class TestJavaClass_IndentationTwo {
public static final String PARAM = "PARAM";
private static final Consumer<Object> MY_CONS = o ->
System.out.println(o);
public static void main(String[] args) {
System.out.println("Hey!");
String property = System
.getProperties()
.getProperty(PARAM);
if (property == null)
return;
System.out.println(property);
}
}
Inside the main() method, we have empty lines. That is totally possible and occurs commonly in java methods. The problem is that the current algorithm (in case this empty line is not populated with trailing whitespaces, which it almost certainly does not) will detect that it is an error having this code:
In reality, this code is fine, and it should not trigger any error. To do that, we need to move from this algorithm to another:
Detect current block indentation. The block of code is started with either {, ( or [ and closed with }, ), ] respectively. Initially, we start with the root code block that has indent level of 0 columns
If we met the new code block, we increase the expected indentation level for this code block (until terminated) by the size of the indent_size setting. Thus, first nesting level has indentation equal to the indent_size, second level of nesting code block has the indentation size equal to 2 * indent_size and so on.
If we met an empty line anywhere, it is always ignored and considered as a line with the correct indentation.
The line within the code block is considered as indented well only it met one of the following criteria:
a) It either has the indentation that is the same as the indentation of the owning code block
b) Or it has the indentation level that is higher than the indentation level of the previous line in the block by indent_size.
The text was updated successfully, but these errors were encountered:
The current algorithm for indentation verification just checks the current line length and compares it with the previous line length, If the absolute value of subtraction one from the other gives the values different from what user have configured, we have an error.
This approach is simple, but it does not take into account multiple cases. For instance, here, we have code with configured
indent_size = 2
:Inside the
main()
method, we have empty lines. That is totally possible and occurs commonly in java methods. The problem is that the current algorithm (in case this empty line is not populated with trailing whitespaces, which it almost certainly does not) will detect that it is an error having this code:In reality, this code is fine, and it should not trigger any error. To do that, we need to move from this algorithm to another:
Detect current block indentation. The block of code is started with either
{
,(
or[
and closed with}
,)
,]
respectively. Initially, we start with theroot
code block that has indent level of 0 columnsIf we met the new code block, we increase the expected indentation level for this code block (until terminated) by the size of the
indent_size
setting. Thus, first nesting level has indentation equal to theindent_size
, second level of nesting code block has the indentation size equal to2 * indent_size
and so on.If we met an empty line anywhere, it is always ignored and considered as a line with the correct indentation.
The line within the code block is considered as indented well only it met one of the following criteria:
a) It either has the indentation that is the same as the indentation of the owning code block
b) Or it has the indentation level that is higher than the indentation level of the previous line in the block by
indent_size
.The text was updated successfully, but these errors were encountered: