Follow-up of #17329
From docs: https://google.github.io/styleguide/javaguide.html#s4.2-block-indentation
[opening quotes] may either follow the same indentation rules as other constructs, or it may have no indentation at all (so it starts at the left margin).
Currently, TextBlockGoogleStyleFormatting Check covers:
Code:
/** somejavadoc. */
public class InputTextBlocksIndentation {
public void textFunc() {
String zeroIndentation = // False-positive below
"""
content of the block
"""; // False-positive
getData( OK, below
"""
Indentation of Text-block
""", // OK
5
);
}
public static void getData(String data, int length) {}
Cli:
$ java -jar checkstyle-11.1.0-all.jar -c google_checks.xml InputTextBlocksIndentation.java
Starting audit...
[WARN] InputTextBlocksIndentation.java:6:1: '"""' has incorrect indentation level 0, expected level should be 8. [Indentation]
[WARN] InputTextBlocksIndentation.java:9:1: '"""' has incorrect indentation level 0, expected level should be 8. [Indentation]
[WARN] InputTextBlocksIndentation.java:12:5: 'method call' child has incorrect indentation level 4, expected level should be 6. [Indentation]
[WARN] InputTextBlocksIndentation.java:14:5: 'method call' child has incorrect indentation level 4, expected level should be 6. [Indentation]
Audit done.
The first two violations are not expected, as Google-style allows for indenting opening quotes at the start of the line without any additional indentation. And because closing quotes should be aligned with opening quotes, they are also allowed to appear at the 0th indentation level.
The last two violations are expected because if the indentation level is not zero, then it has to follow the indentation rules like other blocks.
Google-Formatter output:
/** somejavadoc. */
public class InputTextBlocksIndentation {
public void textFunc() {
String zeroIndentation =
"""
content of the block
""";
getData(
"""
Indentation of Text-block
""",
5);
}
public static void getData(String data, int length) {}
}
Difference between Original and Formatted code:
$ diff -Naru InputTextBlocksIndentation.java FormattedInputTextBlocksIndentation.java
--- InputTextBlocksIndentation.java 2025-12-03 08:25:55.734581300 +0530
+++ FormattedInputTextBlocksIndentation.java 2025-12-03 08:26:53.807180600 +0530
@@ -6,14 +6,13 @@
getData(
- """
- Indentation of Text-block
- """,
- 5
- );
+ """
+ Indentation of Text-block
+ """,
+ 5);
}
public static void getData(String data, int length) {}
Follow-up of #17329
From docs: https://google.github.io/styleguide/javaguide.html#s4.2-block-indentation
Currently, TextBlockGoogleStyleFormatting Check covers:
Both opening and closing quotes are on their own lines.
Opening quotes are vertically aligned with closing quotes, i.e, both must have the same indentation value
Extend TextBlockGoogleStyleFormatting to check indentation of each line in the blocks #18227
Quotes can have zero indentation
Code:
Cli:
The first two violations are not expected, as Google-style allows for indenting opening quotes at the start of the line without any additional indentation. And because closing quotes should be aligned with opening quotes, they are also allowed to appear at the 0th indentation level.
The last two violations are expected because if the indentation level is not zero, then it has to follow the indentation rules like other blocks.
Google-Formatter output:
Difference between Original and Formatted code: