Issue #18227: added TextBlockGoogleStyleFormatting to check indentation#18947
Issue #18227: added TextBlockGoogleStyleFormatting to check indentation#18947Anushreebasics wants to merge 1 commit into
Conversation
bc579ca to
c392caf
Compare
|
@romani please review |
|
@Anushreebasics Please make CI green |
e4ebb3a to
2020456
Compare
|
@vivek-0509 please review |
a64857d to
0a271d4
Compare
|
@Anushreebasics Please ping me once you are done with all the changes, will review after that |
|
@vivek-0509 please. review |
vivek-0509
left a comment
There was a problem hiding this comment.
Please revert all the unrelated formatting changes
| * 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> |
There was a problem hiding this comment.
No formatting changes needed please revert all the unrelated changes
| * 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. |
| @StatelessCheck | ||
| public class TextBlockGoogleStyleFormattingCheck extends AbstractCheck { | ||
| public final class TextBlockGoogleStyleFormattingCheck | ||
| extends AbstractCheck { |
There was a problem hiding this comment.
revert this align them on the single line as before
| /** | ||
| * A key is pointing to the warning message text in | ||
| * "messages.properties" file. | ||
| */ | ||
| public static final String MSG_OPEN_QUOTES_ERROR = | ||
| "textblock.format.open"; |
There was a problem hiding this comment.
keep everything on one line it will not trigger line length violation
| ast.setLineNo(lineNo); | ||
| ast.setColumnNo(columnNo); | ||
| return ast; | ||
| } |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
@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?
There was a problem hiding this comment.
@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
|
|
||
| <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> | ||
|
|
06eff46 to
48bcb55
Compare
48bcb55 to
4ffbf28
Compare
|
@vivek-0509 please review |
There was a problem hiding this comment.
@Anushreebasics Please revert all unrelated formatting changes, including the ones I mentioned below. There are several others as well, so kindly revert those too.
| if (parent.getType() == TokenTypes.METHOD_DEF) { | ||
| quotesAreNotPreceded = !quotesArePrecededWithComma(openingQuotes); | ||
| quotesAreNotPreceded = !quotesArePrecededWithComma( | ||
| openingQuotes); | ||
| } |
| /** | ||
| * 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. |
2ab7ad7 to
3be8b3b
Compare
|
@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. |
|
@DakshRJain737, I have been working on this for a long time |
|
I am really sorry 😞 for that. But my PR was open since December. I left it on Jan 18th because of my university exams. |
| 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. |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
I have not changed line 61 and line 62
| final DetailAstImpl content = new DetailAstImpl(); | ||
| content.setText(""); | ||
| final DetailAstImpl closingQuotes = new DetailAstImpl(); | ||
| content.setNextSibling(closingQuotes); |
There was a problem hiding this comment.
all test should be done by verifyWithInlineConfigParser.
| </li> | ||
| <li> | ||
| Each line in the text-block is indented at least as much as | ||
| the opening and closing quotes. |
There was a problem hiding this comment.
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
4d23b87 to
b603562
Compare
…dentation checks
b603562 to
3936065
Compare
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