I'm using checkstyle 3.0 version and getting following error:
Consider using special escape sequence instead of octal value or
Unicode escaped value. [IllegalTokenText]
I want to ignore/suppress this warning(IllegalTokenText). I have tried using supressionCommentFilter but I think it works for checkstyle release 3.2 and above.
Please guide me how can I ignore/suppress checkstyle warnings in 3.0 version.
Cheers :)
Like others have been saying 3.0 is very very old, and no filters were around back then.
Since your client doesn't want to upgrade Checkstyle, your only options are:
1) Remove IllegalTokenText (or set its severity to ignore) in your configuration
2) Convince them to upgrade. Many improvements, bug fixes, and new checks have been added since then all of which they are missing out on.
3)
I am assuming (since I am not that familiar with the old code) that Checkstyle is still expandable back in that day like it is now. You could try to create a custom listener to act like a filter in the old Checkstyle to suppress the violation you want to ignore. 3.0 didn't have filter support back then, and you can't add it in. First make sure you can add a listener through the configuration, otherwise, this may not even be an option.
Checkstyle 3.0 source: https://github.com/checkstyle/checkstyle/tree/release3_0
How to write a listener: http://checkstyle.sourceforge.net/writinglisteners.html (Note this is the newer version documentation)
4)
Similar to the writting a custom listener, write a custom IllegalTokenText with suppression support.
How to write a check: http://checkstyle.sourceforge.net/writingchecks.html (Note this is the newer version documentation)
I don't see any other options then these.
Related
Look at the below-given image of Intellij IDEA -
When we use a function it automatically provides the argument name and when we copy a code-snippet then that argument name is not copied(it is just for our reference).
I want to do the same in my vs-code editor but, I can't find any way to do it.
Looks like Inline Parameters for VSCode extension you looking for.
There is a new version of VS Code, there they had given support for Parameter hint highlight See the release notes
This feature, called "parameter hints", requires support from the language server, so whether or not this is currently supported varies from language to language.
For C++, clangd has experimental support for this (enabled by adding --inlay-hints=true to "clangd.arguments") starting from clangd 13.
I'm not familiar with the status for other languages, so will let others answer on that front.
In our project we use checkstyle as static analyzer (as maven plugin, I mean maven-checkstyle-plugin). I am new to this tool, and there is one thing I want to find out - what is the difference between failOnError and failOnViolation?
I think the plugin documentation is pretty clear, but the minimum expectation is going to be:
Do you want a log of the errors before failing the build? Then use failOnViolation
Or
Do you want to fail the build immediately, without waiting for errors to be logged? Then use failsOnError
Of course, if you set logViolationsToConsole to false (or on the CLI as -Dcheckstyle.console=false), then both act almost identically and can cause some confusion.
I have two situations I need a checkstyle check for. Let's say I have a bunch of objects with the annotation #BusinessLogic. I want to do a first pass through all *.java files creating a Set with the full classnames of these objects. Let's say ONE of the classes here is MyBusinessLogic. NEXT, and as part of a custom checkstyle checker, I want to go through and fail the build if there is any lines of code that say "new MyBusinessLogic()" in any of the code. We want to force DI when objects are annotated with #BusinessLogic. Is this possible with checkstyle? I am not sure checkstyle does a dual pass.
Another option I am considering is some gradle plugin perhaps that scans all java files and writes to a file the list of classes annotated with #BusinessLogic and then running checkstyle after that where my checker reads in the file?
My next situation is I have a library delivered as a jar so in that jar, I also have classes annotated with #BusinessLogic and I need to make sure those are also added to my list of classes that should not be newed up manually and only created with dependency injection.
Follow up question from the previous question here after reading through checkstyle docs:
How to enforce this pattern via gradle plugins?
thanks,
Dean
Is it possible to write a dual pass checkstyle check?
Possible, yes, but not officially supported. Support would come at https://github.com/checkstyle/checkstyle/issues/3540 but it hasn't been agreed on.
Multi-file validation is possible with FileSets (still not officially supported), but it becomes harder with TreeWalker checks. This is because TreeWalker doesn't chain finishProcessing to the checks. You can implement your own TreeWalker that will chain this finishProcessing to implementation of AbstractChecks.
You will have to do everything in 1 pass with this method. Log all new XXX and classes with annotation #YYY. In the finishProcessing method, correlate the information obtained between the 2 and print a violation when you have a match.
I have a library delivered as a jar
Checkstyle does not support reading JARs or bytecode. You can always create a hard coded list as an alternative. The only other way is build your own reader into Checkstyle.
How to check The value of the local variable is not used and The value of the field is not used using Checkstyle? In Eclipse there is a warning about that. But there's no in Checkstyle (i use sun_checks.xml, slightly modified).
I tried to write my own check, but being a newbie, only found how to calculate variable declarations (using TokenTypes.VARIABLE_DEF), but i am not sure how to find namely usage of these variables and fields...
Checkstyle can't do that, I'm afraid, but PMD (rule) and FindBugs (rule) can.
Checkstyle and PMD operate only on the Java source, and it is harder to deduce field and variable use only from the source. FindBugs operates on the compiled class files, so it has an easier job in this case. PMD can only detect unused private fields and variables, which can be found by looking at a single source file.
Writing an "unused private field/variable detector" for Checkstyle is possible, if tedious. I would recommend going with the PMD tool for this, which also features a light-weight Eclipse plugin.
Checkstyle 9.3 introduced the UnusedLocalVariable check which reports unused local variables. It does not detect unused fields.
To enable this check:
<module name="UnusedLocalVariable"/>
As of Checkstyle 10.1, this check still has some limitations: it doesn't report unused method arguments nor unused pattern variables. But at least it covers the most common cases with local variables.
References:
Checkstyle 9.3 Release Notes
UnusedLocalVariable module documentation
Github issue
In the context of webkit in chromium source code ,it says it is source compatible but not binary compatible. Does it suggest that we build .dll file of webkit and build it with chrome binary ?
(This answer doesn't talk about the specific context of WebKit - it's not clear what exactly you mean by the various "it says" parts. I've tried to give a more general answer.)
Suppose we have a library called LibFoo, and you have built an application called SuperBar which uses LibFoo v1.
Now LibFoo v1.1 comes out.
If this is binary compatible, then you should be able to just drop in the new binary, and SuperBar will work using the new code without any other changes
If this is only source compatible then you need to rebuild SuperBar against v1.1 before you'll be able to use it
I would think of it from the point of view of Linking
Linking is the process of taking a class or interface and combining it into the run-time state of the Java Virtual Machine so that it can be executed.
Linking a class or interface involves verifying and preparing that
class or interface, its direct superclass, its direct superinterfaces,
and its element type (if it is an array type), if necessary.
If introducing a new change breaks the linking, then it is not source (code) compatible (as well as binary compatible)
If introducing a new change does not break the linking, then it is at least binary compatible