KEMBAR78
Issue #11867: Suppress Line-Length violations for text-block content by mohitsatr · Pull Request #17666 · checkstyle/checkstyle · GitHub
Skip to content

Conversation

@mohitsatr
Copy link
Member

@mohitsatr mohitsatr commented Aug 21, 2025


<module name="SuppressWithPlainTextCommentFilter">
<property name="checkFormat" value="LineLength"/>
<property name="offCommentFormat" value='^.*"""$'/>
Copy link
Member Author

Choose a reason for hiding this comment

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

Screenshot from 2025-08-21 12-50-23

Copy link
Member

@Zopsss Zopsss Aug 21, 2025

Choose a reason for hiding this comment

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

this regex doesn't match if the opening quotes have trailing whitespace

image

Copy link
Member

Choose a reason for hiding this comment

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

it's a very rare case but it can cause false-positive

Copy link
Member

Choose a reason for hiding this comment

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

try ^.*"""\s*$ and """\s*$. I shallow tested it and it was working fine, but still not sure about it.

Copy link
Member Author

Choose a reason for hiding this comment

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

done

<module name="SuppressWithPlainTextCommentFilter">
<property name="checkFormat" value="LineLength"/>
<property name="offCommentFormat" value='^.*"""$'/>
<property name="onCommentFormat" value='^\s*"""\s*(?:[,;]|.+)$'/>
Copy link
Member Author

Choose a reason for hiding this comment

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

Screenshot from 2025-08-21 12-51-23

Copy link
Member

Choose a reason for hiding this comment

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

The regex doesn't match when the closing quotes are followed by characters.

image

Copy link
Member

Choose a reason for hiding this comment

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

try this regex: """(?=\s*[,;+]), again not sure if this will work perfectly or not. We will need to generate diff reports to find out.

Copy link
Member Author

@mohitsatr mohitsatr Aug 26, 2025

Choose a reason for hiding this comment

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

This will not do.

I tried bunch of patterns, but it keep missing cases and becoming more difficult to understand.
if we create regex to catch the following cases, it starts catching the opening quotes too.

testing"""
testing """ + 
testing """,

Copy link
Member Author

@mohitsatr mohitsatr Aug 26, 2025

Choose a reason for hiding this comment

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

I don't think regex would be up for the job to catch such edge cases.
I did not see any case where text block content was followed by closing quotes. maybe we should not worry about such cases.
@romani wdyt?

Copy link
Member

Choose a reason for hiding this comment

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

sorry for the late response,

Yup it is catching opening quotes too:

image

I think achieving this solely by regex is not possible, or too difficult. Maybe we can modify the check itself, add opening quotes token and closing quotes tokens support and introduce a new property called ignoreTextBlocks. If enabled, it'll ignore the text block's content. And I think it should be very easy to implement too.

@romani please give your opinion.

Copy link
Member

Choose a reason for hiding this comment

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

supprssions are always prone to not cover edge cases. Please put most of them to sample to show trasparently that we discovered them but no way to handle them now, and issue is created.
One day some other random hacker from web will improve.

Copy link
Member

Choose a reason for hiding this comment

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

so should we modify the check or not?

Copy link
Member

Choose a reason for hiding this comment

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

No, check is general and not java specific.

For all edge cases we need we need to create new Check , something like JavaLineLengh that can allow violations under some tokens.
Such new Check might be javadoc too, to allow allowances under some javadoc specific tokens.

Copy link
Member Author

@mohitsatr mohitsatr Aug 29, 2025

Choose a reason for hiding this comment

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

issue created #17707

@mohitsatr
Copy link
Member Author

Github, generate report

@github-actions
Copy link
Contributor

String textblock4 =
"""
Contrary to popular belief, Lorem Ipsum is not simply random text. It has roots in a piece of classical Latin literature from 45 BC, making it over 2000 years old. Richard McClintock, a Latin professor at Hampden-Sydney College in Virginia, looked up one of the more obscure Latin words, consectetur, from a Lorem Ipsum passage, and going through the cites of the word in classical literature, discovered the undoubtable source. Lorem Ipsum comes from sections 1.10.32 and 1.10.33 of "de Finibus Bonorum et Malorum" (The Extremes of Good and Evil) by Cicero, written in 45 BC. This book is a treatise on the theory of ethics, very popular during the Renaissance. The first line of Lorem Ipsum, "Lorem ipsum dolor sit amet..", comes from a line in section 1.10.32.
""" + getSampleTest();
Copy link
Member

Choose a reason for hiding this comment

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

please also add a case where closing quotes are followed by some string.

Copy link
Member 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 +209 to +212
<li>
<a href="https://github.com/search?q=path%3Asrc%2Fmain%2Fresources%20path%3A**%2Fgoogle_checks.xml+repo%3Acheckstyle%2Fcheckstyle+SuppressWithPlainTextCommentFilter">
Google Style</a>
</li>
Copy link
Member

Choose a reason for hiding this comment

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

we need to add documentation of using this suppression in google_style.xml

Copy link
Member Author

@mohitsatr mohitsatr Aug 29, 2025

Choose a reason for hiding this comment

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

done.
also updated the docs #17706

Copy link
Member

@romani romani left a comment

Choose a reason for hiding this comment

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

items:


String textblock2 =
"""
Contrary to popular belief, Lorem Ipsum is not simply random text. It has roots in a piece of classical Latin literature from 45 BC, making it over 2000 years old. Richard McClintock, a Latin professor at Hampden-Sydney College in Virginia, looked up one of the more obscure Latin words, consectetur, from a Lorem Ipsum passage, and going through the cites of the word in classical literature, discovered the undoubtable source. Lorem Ipsum comes from sections 1.10.32 and 1.10.33 of "de Finibus Bonorum et Malorum" (The Extremes of Good and Evil) by Cicero, written in 45 BC. This book is a treatise on the theory of ethics, very popular during the Renaissance. The first line of Lorem Ipsum, "Lorem ipsum dolor sit amet..", comes from a line in section 1.10.32.
Copy link
Member

Choose a reason for hiding this comment

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

we do not need insanely long text, please shorten it to be slightly but visually catch-able above limit

Copy link
Member Author

Choose a reason for hiding this comment

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

done

@mohitsatr
Copy link
Member Author

mohitsatr commented Aug 29, 2025

why build errors?

[ERROR] [checkstyle] [ERROR] /home/circleci/project/src/it/resources/com/google/checkstyle/test/chapter4formatting/rule44columnlimit/InputColumnLimitEdgeCase.java:7: Line should not be longer than 100 symbols [lineLength]
[ERROR] [checkstyle] [ERROR] /home/circleci/project/src/it/resources/com/google/checkstyle/test/chapter4formatting/rule44columnlimit/InputColumnLimitEdgeCase.java:12: Line should not be longer than 100 symbols [lineLength]
[ERROR] [checkstyle] [ERROR] /home/circleci/project/src/it/resources/com/google/checkstyle/test/chapter4formatting/rule44columnlimit/InputColumnLimitEdgeCase.java:18: Line should not be longer than 100 symbols [lineLength]
[ERROR] [checkstyle] [ERROR] /home/circleci/project/src/it/resources/com/google/checkstyle/test/chapter4formatting/rule44columnlimit/InputFormattedColumnLimitEdgeCase.java:12: Line should not be longer than 100 symbols [lineLength]
[ERROR] [checkstyle] [ERROR] /home/circleci/project/src/it/resources/com/google/checkstyle/test/chapter4formatting/rule44columnlimit/InputFormattedColumnLimitEdgeCase.java:18: Line should not be longer than 100 symbols [lineLength]

@romani
Copy link
Member

romani commented Aug 29, 2025

put whole folder rule44columnlimit to

<!-- test resources are weird by design, no validations in them -->
<suppress id="lineLength"
files="src[\\/]it[\\/]resources[\\/].*[\\/]Input.*ColumnLimit\.java"/>

this Check is by design needs violation here.
All other Inputs be validated to not be wild for no reason.

Copy link
Member

@romani romani left a comment

Choose a reason for hiding this comment

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

Items

Copy link
Member

@romani romani left a comment

Choose a reason for hiding this comment

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

ok to merge.

@romani romani merged commit e81bf10 into checkstyle:master Sep 7, 2025
119 checks passed
@mohitsatr mohitsatr deleted the supp-linelength branch September 8, 2025 05:09
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.

LineLength gets triggered on multi-line strings for Google Checks

3 participants