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
new Checker filter SuppressWithPlainTextCommentFilter as akin to Treewalker's SuppressionCommentFilter #4841
Comments
I couldn't get it to work with 8.0 when everything is corrected but I can see why it won't work with 8.1 anyways. This is because I'm not sure there is a decent way to bring this functionality back. |
@rnveach <?xml version="1.0"?>
<!DOCTYPE module PUBLIC
"-//Puppy Crawl//DTD Check Configuration 1.2//EN"
"http://www.puppycrawl.com/dtds/configuration_1_2.dtd">
<module name="Checker">
<module name="FileTabCharacter">
<property name="eachLine" value="true"/>
</module>
<module name="TreeWalker">
</module>
<module name="SuppressWarningsFilter"/>
<module name="SuppressionCommentFilter"/>
<module name="SuppressionCommentFilter">
<property name="offCommentFormat" value="CSOFF\: ([\w\|]+)"/>
<property name="onCommentFormat" value="CSON\: ([\w\|]+)"/>
<property name="checkFormat" value="$1"/>
</module>
</module> |
terrible regression ... we forgot about non-java grammar based Checks at all. |
@rnveach , we can not come back to Holders model to keep context between TreeWalker and Checker. So we need to introduce new Filter - @PhantomThief , @Ricq , please share your ideas too, in case it might now satisfy your use cases. |
I am fine with proposal.
If users care, they can add them as part of the text to match.
Since we aren't verifying it is a comment like you specified, why don't we take |
@MEZk , please share your ideas on what name do you like more. |
I'm fine with the names.
Sounds reasonable. If the filter is for property file, we will need '#' to mark the text as a comment, but still it will be a comment. @romani @rnveach
Yes, but now we have two filters in Checkstyle architecture with separate responsibility. |
All right, please send PR. |
The implementation will resolve my issue with using the suppression in combination with RegexpMultiline in Java files, and supports another use case I have, which is to run simple regular expression checks (for headers, etc.) on JavaScript as well. So, +1 on the fix. One remark: it might become hard for users to distinguish which suppression filter to use. As the original ones now only apply to Java-specific TreeWalker checks, and the new ones will apply to regular Checker checks such as the RegexpSingleline and RegexpMultiline checks. I suggest creating some clear documentation with cross-references between the two sets to prevent confusion. |
documentation will be provided, but as usually nobody will read it. Checkstyle execution will fail if wrong filter is used. |
private WeakReference<FileContents> fileContentsReference = new WeakReference<>(null); should be removed for sure. // CHECKSTYLE:OFF
// CHECKSTYLE:ON |
It is hard to make it for sure, but for now I think it should not parse comment at all. Just match comment line by regexp.
Right now I see that how Checker work with FileSetModules:
so it put FileText in modules, so lets put FileText in Filter too.
ok
it should work how it worked before. It had support for multi-line comments. If that is over complication, we can postpone support of multiline-comments for future. |
FileContents has all required logic to get c lang and cpp comments, block comments, etc. All we need to do is to invoke |
But we can't assume file is Java as romani's example at #4841 (comment) was for properties, which don't have C/C++ styled comments. |
We do not need TreeWalker execution. Look at these methods:
Yes, this is the only problem as for me. However, we can implement additional method: My main point is to avoid copy-paste of the same logic from FileContents to the filters. |
How do you think those methods get called? In the Java grammar...
What about other text base files? XML, json, etc... |
@romani
If you are OK with the proposal, let me know. |
User just need to specify String to match, user has to put comment symbols himself to regexp. All we will do is match some string above violation by user defined regexp. We should forget about term "comment" at all.
I think drop of support of multiline comments will be ok.
Yes
Please be welcome with PR. |
Can someone link the documents for this feature mentioned (some of us do in fact read them). This is assuming that this fix was in fact implemented. |
This fix has not been implemented hence why it is still open. |
Hmm okay. I only pressed as after I updated android studio to 3.0 b7 and the intellij / android studio check style plugin to 5.10.2 I am no longer able to import my rules citing the error that appears in the newest checkstyles. That is instead of the current selected version of checkstyles. Which had me hoping that this had been at last fixed. So I will just downgrade the plugins instead. |
@MEZk , ping. |
@romani Created SuppressWithPlainTextCommentFilter implementation, working on the documentation. |
@romani |
Fix was merged. |
Same as #4884
cat Test.java
cat config.xml
java -jar checkstyle-8.1-all.jar -c config.xml Test.java
expected no errors because there is a suppression comment filter.
while it works on 8.0
The text was updated successfully, but these errors were encountered: