3
3
import io .mpolivaha .maven .plugin .editorconfig .Editorconfig .Section ;
4
4
import io .mpolivaha .maven .plugin .editorconfig .assertions .Assert ;
5
5
import io .mpolivaha .maven .plugin .editorconfig .common .ByteArrayLine ;
6
+ import io .mpolivaha .maven .plugin .editorconfig .common .IndentationBlock ;
6
7
import io .mpolivaha .maven .plugin .editorconfig .model .IndentationStyle ;
7
8
import io .mpolivaha .maven .plugin .editorconfig .model .Option ;
8
9
import io .mpolivaha .maven .plugin .editorconfig .model .TrueFalse ;
@@ -22,6 +23,11 @@ public class IndentationSizeOptionVerifier extends SpecOptionVerifier<Integer> {
22
23
23
24
private static final String PREVIOUS_LINE_KEY = "PREVIOUS_LINE_KEY" ;
24
25
26
+ /**
27
+ * The indentation block that is applicable for the given line
28
+ */
29
+ private static final String INDENTATION_BLOCK = "INDENTATION_BLOCK" ;
30
+
25
31
public IndentationSizeOptionVerifier () {
26
32
super (Option .IDENT_SIZE );
27
33
}
@@ -34,28 +40,12 @@ protected void onInit(Section section) {
34
40
@ Override
35
41
protected void forEachLine (ByteArrayLine line , int lineNumber , Integer optionValue , OptionValidationResult result , Map <String , Object > executionContext ) {
36
42
Assert .notNull (section , "The section cannot be null at this point" );
43
+ var indentationBlock = (IndentationBlock ) executionContext .getOrDefault (INDENTATION_BLOCK , IndentationBlock .root ());
37
44
38
- ByteArrayLine previous ;
39
- if ((previous = (ByteArrayLine ) executionContext .get (PREVIOUS_LINE_KEY )) == null ) {
40
- executionContext .put (PREVIOUS_LINE_KEY , line );
41
- return ;
42
- }
43
-
44
- // TODO: Here, we reclaculate the indent of previous line, which can in fact be avoided
45
- int previousIndent = previous .getIndentInColumns (section .getTabWidth ());
46
- int thisIndent = line .getIndentInColumns (section .getTabWidth ());
47
-
48
- if (previousIndent != thisIndent ) {
49
- int indentLevel = Math .abs (previousIndent - thisIndent );
50
- if (indentLevel != optionValue ) {
51
- result .addErrorMessage (
52
- "The indentation level between lines %d and %d differs from the configured level of indentation. Required: %d, Actual : %d"
53
- .formatted (lineNumber - 1 , lineNumber , optionValue , indentLevel )
54
- );
55
- }
56
- }
57
-
58
- executionContext .put (PREVIOUS_LINE_KEY , line );
45
+ executionContext .put (
46
+ PREVIOUS_LINE_KEY ,
47
+ line .startsNewCodeBlock () ? indentationBlock .next (optionValue ) : indentationBlock
48
+ );
59
49
}
60
50
61
51
@ Override
0 commit comments