I'm starting to use Static Code Analysis tools like Checkstyle, PMD and FindBugs.
PMD allows to mark code as reviewed, by adding a comment to the end of the line:
System.out.println("Test"); // NOPMD by edward on 9/23/14 10:22 AM
I really don't like trailing comments and so does CheckStyle ("Don't use trailing comments."). Is there a way to tell PMD that a specific code is reviewed, without using trailing comments?
Another way of tackling this could be to configure Checkstyle to make an exception from the TrailingComment rule for suppression comments like this:
<module name="TrailingComment">
<property name="legalComment" value="^NOPMD .*"/>
</module>
You can try to add #SuppressWarnings("PMD") to the class or method where you get the warning. However, this is not the best solution, because it will disable all warnings on the marked target. Here, you can read more about suppressing.
You could maybe try FaultHunter, which is very similar to PMD, and can suppress warnings by kind (e.g. #SuppressWarnings("FH.UnusedConstructor")) and even on method level.
Related
Our SonarQube project is reporting violations across our codebase, because we have braces at the start of line instead of end of line.
Right or wrong, this is our accepted style. So how can we remove the end of line requirement and add a start of line requirement, and modify it a bit for else statements as
if()
{
} else {
}
Assuming it's a Java Project, you may look for rules related to braces.
To see all java related rules dealing with braces, use:
https://yoursonarhost/coding_rules#languages=java|q=braces
From your example, squid:LeftCurlyBraceStartLineCheck seems the wright rule.
Also possible to search with filter on specific Quality Profile, f.e.:
https://yoursonarhost/coding_rules#qprofile=java-sonar-way-74224|activation=true|q=braces
Then deactivate the rule that doesn't work for you or change it's severity. If no appropriate rule exists you may roll your own, based on those other brace rules, see sources:
Sonarsource Java Analyzer sources
I tried with PMD but it have only 'Cyclomatic Complexity'.
I find 'Fan out' rule in checkstyle.
Which tool has all these three rules?
I achieved with Checkstyle tool.
Is there a way to perform conditional execution of snippet in pom.xml?
my requirement is to copy a file/directory to deploy structure based on variable defined in pom.xml...
eg:
< if >
< equals arg1="package" arg2="package"/>
< then>
....
< /then>
< /if>
Not sure how can I achieve this!
Any pointers would be highly appreciated.
Thanks,
SR
Probably you'll need to use Maven AntRun Plugin for that.
In general, there's no conditional expressions in POM. The only thing similar somehow to this are build profiles that can be activated on some specified conditions, however they probably don't fit into your current case.
And, at the end, my suggestion here. We don't know exactly what your case is about and don't even have any real code snippet, however from my experience it's really unusual to have to use such hackin' stuff in Maven. For me it smells like some problems with Maven understanding, project structure or stuff like that. I may be wrong and maybe your case really needs that, but consider other options to fit into Maven default approach and conventions instead.
Well, you can use Maven's profiles, to do that.
Or you can take a look at Maven's Ant Tasks.
Is there a way to perform conditional execution of snippet in pom.xml?
my requirement is to copy a file/directory to deploy structure based on variable defined in pom.xml...
eg:
< if >
< equals arg1="package" arg2="package"/>
< then>
....
< /then>
< /if>
Not sure how can I achieve this!
Any pointers would be highly appreciated.
Thanks,
SR
Probably you'll need to use Maven AntRun Plugin for that.
In general, there's no conditional expressions in POM. The only thing similar somehow to this are build profiles that can be activated on some specified conditions, however they probably don't fit into your current case.
And, at the end, my suggestion here. We don't know exactly what your case is about and don't even have any real code snippet, however from my experience it's really unusual to have to use such hackin' stuff in Maven. For me it smells like some problems with Maven understanding, project structure or stuff like that. I may be wrong and maybe your case really needs that, but consider other options to fit into Maven default approach and conventions instead.
Well, you can use Maven's profiles, to do that.
Or you can take a look at Maven's Ant Tasks.
I am about to employ Checkstyle on a project to improve coding standards and discovered in my research that I can also setup Checkstyle to return some coding metrics as well as some other useful checks. However there seems to be a glaring omission, which is Lines of Code. I know its a horrible metric but I've been asked to produce it! Does anyone know if Checkstyle can return lines of code on the project and if so how?
Cheers
Checkstyle calculates mutiple LOC-like metrics:
FileLength (com.puppycrawl.tools.checkstyle.checks.sizes) The default maximum is 2000.
ExecutableStatementCount and JavaNCSS, i.e., Non Commenting Source Statements. In a way, it is close to SLOC (source lines of code) or even better LLOC (logical lines of code). LLOC, ExecutableStatementCount and JavaNCSS are aware of the fact that one statement can be spread over multiple physical lines of code and that one physical line of code can contain multiple statements. JavaNCSS adheres to the specification for the JavaNCSS-Tool written by Chr. Clemens Lee. The specification can be found on http://www.kclee.de/clemens/java/javancss/#specification
The HONEST answer is that Checkstyle simply doesn't offer LOC or LLOC.
In fact, as far as I can see, no Eclipse Juno Plugin for Java offers this eminently useful feature.
I wonder why so is that now . . .
Even very crude IDEs like GPS gives a full catalogue of all the usual metrics.
It seems to say something about the people at IBM and Oracle.