Skip to content

Issue #18227: added TextBlockGoogleStyleFormatting to check indentation#18947

Open
Anushreebasics wants to merge 1 commit into
checkstyle:masterfrom
Anushreebasics:textblock
Open

Issue #18227: added TextBlockGoogleStyleFormatting to check indentation#18947
Anushreebasics wants to merge 1 commit into
checkstyle:masterfrom
Anushreebasics:textblock

Conversation

@Anushreebasics

@Anushreebasics Anushreebasics commented Feb 16, 2026

Copy link
Copy Markdown
Contributor

fixes #18227

Core functionality implemented
All translations added (9 languages)
Updated javadoc and metadata
All unit tests passing (17 tests)
All integration tests passing (5 Google tests)
Test input files updated with proper violation markers

@Anushreebasics Anushreebasics force-pushed the textblock branch 8 times, most recently from bc579ca to c392caf Compare February 18, 2026 13:16
@Anushreebasics

Copy link
Copy Markdown
Contributor Author

@romani please review

@vivek-0509

Copy link
Copy Markdown
Member

@Anushreebasics Please make CI green

@Anushreebasics Anushreebasics force-pushed the textblock branch 7 times, most recently from e4ebb3a to 2020456 Compare February 19, 2026 17:30
@Anushreebasics

Copy link
Copy Markdown
Contributor Author

@vivek-0509 please review

@Anushreebasics Anushreebasics force-pushed the textblock branch 5 times, most recently from a64857d to 0a271d4 Compare February 20, 2026 08:42
@vivek-0509

vivek-0509 commented Feb 20, 2026

Copy link
Copy Markdown
Member

@Anushreebasics Please ping me once you are done with all the changes, will review after that

@Anushreebasics

Copy link
Copy Markdown
Contributor Author

@vivek-0509 please. review

@vivek-0509 vivek-0509 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please revert all the unrelated formatting changes

Comment on lines +31 to +33
* Checks correct format of
* <a href="https://docs.oracle.com/en/java/javase/17/text-blocks/index.html">Java Text Blocks</a>
* <a href="https://docs.oracle.com/en/java/javase/17/text-blocks/index.html">
* Java Text Blocks</a>

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No formatting changes needed please revert all the unrelated changes

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

Comment on lines +39 to +43
* It ensures that the opening and closing text-block quotes ({@code """}) each appear on their
* own line, with no other item preceding them.
* It ensures that the opening and closing text-block quotes
* ({@code """}) each appear on their own line, with no other
* item preceding them.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

Comment on lines +58 to +60
@StatelessCheck
public class TextBlockGoogleStyleFormattingCheck extends AbstractCheck {
public final class TextBlockGoogleStyleFormattingCheck
extends AbstractCheck {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

revert this align them on the single line as before

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

Comment on lines +62 to +67
/**
* A key is pointing to the warning message text in
* "messages.properties" file.
*/
public static final String MSG_OPEN_QUOTES_ERROR =
"textblock.format.open";

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

keep everything on one line it will not trigger line length violation

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

ast.setLineNo(lineNo);
ast.setColumnNo(columnNo);
return ast;
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please use log(int lineNo, int colNo, String key, Object... args) from AbstractCheck instead of creating synthetic DetailAstImpl nodes. This method exists exactly for cases where there is no real AST node at the violation location.

@Anushreebasics Anushreebasics Feb 20, 2026

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tried [AbstractCheck.log(int, int, String, Object...)], but CI fails because this signature is explicitly forbidden by [signatures.txt:4] and enforced in [pom.xml:2071-2079]. I switched to [log(DetailAST, ...)] with a synthetic node to preserve exact line/column and pass project policy. is this okay?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@romani we need your guidance here
we need to report violations on individual text block content lines. However, TEXT_BLOCK_CONTENT is a single AST node, there is no AST node per content line.

Since log(int lineNo, int colNo, String key, Object... args) is forbidden, I was thinking we log the violation on the TEXT_BLOCK_LITERAL_BEGIN node and mention the exact line number in the violation message

Line {0} has wrong indentation level {1}, each line in text block should be indented at least as much as the opening quotes.

Other option we have is to add this check to the forbiddenapis excludes in pom.xml and use log(int lineNo, int colNo, String key, Object... args) for exact line/column reporting? I see other checks with similar cases are already excluded which have the same case, no AST at the violation location.

What is your opinion on this?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@romani please guide

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@vivek-0509 how should I proceed?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Anushreebasics we need @romani opinion on this to avoid multiple iterations, but as we see there are large number of PRs coming so the reviews will be slightly delayed, we should wait
i am leaning towards below mentioned approach

Since log(int lineNo, int colNo, String key, Object... args) is forbidden, I was thinking we log the violation on the TEXT_BLOCK_LITERAL_BEGIN node and mention the exact line number in the violation message

Comment thread config/import-control.xml Outdated
Comment on lines +70 to +76

<file name="TextBlockGoogleStyleFormattingCheck">
<allow class="com.puppycrawl.tools.checkstyle.DetailAstImpl"/>
<allow class="com.puppycrawl.tools.checkstyle.StatelessCheck"/>
<allow class="com.puppycrawl.tools.checkstyle.utils.TokenUtil"/>
</file>

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not needed please revert

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

@Anushreebasics Anushreebasics force-pushed the textblock branch 3 times, most recently from 06eff46 to 48bcb55 Compare February 20, 2026 16:57
@Anushreebasics

Copy link
Copy Markdown
Contributor Author

@vivek-0509 please review

@vivek-0509 vivek-0509 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Anushreebasics Please revert all unrelated formatting changes, including the ones I mentioned below. There are several others as well, so kindly revert those too.

Comment on lines 162 to 165
if (parent.getType() == TokenTypes.METHOD_DEF) {
quotesAreNotPreceded = !quotesArePrecededWithComma(openingQuotes);
quotesAreNotPreceded = !quotesArePrecededWithComma(
openingQuotes);
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

revert this

Comment on lines +203 to +205
/**
* Determines if the Closing quotes of text block are not preceded by any code.
* Determines if the Closing quotes of text block are not preceded
* by any code.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this also and many more

@DakshRJain737

Copy link
Copy Markdown
Contributor

@Anushreebasics already one PR of mine was open. I am sorry that you had to work one this but my PR is done. Sorry that is didnt say you before that I was already continuing this issue.

@Anushreebasics

Copy link
Copy Markdown
Contributor Author

@DakshRJain737, I have been working on this for a long time

@DakshRJain737

Copy link
Copy Markdown
Contributor

I am really sorry 😞 for that. But my PR was open since December. I left it on Jan 18th because of my university exams.

@romani romani left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

items:

Comment on lines -60 to +62
textblock.format.close=Tekstilohkon lopetuslainausmerkkien (""") on oltava uudella rivill�.
textblock.format.open=Tekstilohkon aloituslainausmerkkien (""") on oltava uudella rivill�.
textblock.vertically.unaligned=Tekstilohkon lainausmerkit eiv�t ole pystysuorassa linjassa.
textblock.format.close=Tekstilohkon lopetuslainausmerkkien (""") on oltava uudella rivill�.
textblock.format.open=Tekstilohkon aloituslainausmerkkien (""") on oltava uudella rivill�.
textblock.line.indentation=Tekstilohkon jokaisen rivin tulee olla sisennetty vähintään yhtä paljon kuin avaavat ja sulkevat lainausmerkit.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I do not see why such lines are changes, please try to make diff only to add single line, as you do in other files.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have not changed line 61 and line 62

final DetailAstImpl content = new DetailAstImpl();
content.setText("");
final DetailAstImpl closingQuotes = new DetailAstImpl();
content.setNextSibling(closingQuotes);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

all test should be done by verifyWithInlineConfigParser.

&lt;/li&gt;
&lt;li&gt;
Each line in the text-block is indented at least as much as
the opening and closing quotes.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please add new Example to show validation in action.
code with violation
very similar code without violation
code with violation
very similar code without violation

@Anushreebasics Anushreebasics force-pushed the textblock branch 15 times, most recently from 4d23b87 to b603562 Compare April 20, 2026 16:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Extend TextBlockGoogleStyleFormatting to check indentation of each line in the blocks

4 participants