-
-
Notifications
You must be signed in to change notification settings - Fork 3.9k
Issue #11867: Suppress Line-Length violations for text-block content #17666
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
src/main/resources/google_checks.xml
Outdated
|
|
||
| <module name="SuppressWithPlainTextCommentFilter"> | ||
| <property name="checkFormat" value="LineLength"/> | ||
| <property name="offCommentFormat" value='^.*"""$'/> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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*(?:[,;]|.+)$'/> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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 """,
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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:
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
issue created #17707
|
Github, generate report |
| 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(); |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
| <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> |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
There was a problem hiding this 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. |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
481a6f7 to
3155ce5
Compare
|
why build errors? |
|
put whole folder rule44columnlimit to checkstyle/config/checkstyle-non-main-files-suppressions.xml Lines 67 to 69 in 1e22276
this Check is by design needs violation here. |
3155ce5 to
7ddea2b
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Items
src/test/java/com/puppycrawl/tools/checkstyle/internal/XdocsPagesTest.java
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok to merge.




resolves #11867
Diff Regression config: https://gist.githubusercontent.com/mohitsatr/2f62c8fabd1ea8fbc7ceaf6f8b4d19b5/raw/6281804ddac26777baac8e4fef9eef76aa076a82/master_linelength.xml
Diff Regression patch config: https://gist.githubusercontent.com/mohitsatr/f4bc1e92062712f41048c8282e8e283c/raw/1f9b1df02f6be4017d7b3909c41c70676a9bea3c/patch_linelength.xml