mirror of
https://github.com/ysoftdevs/DependencyCheck.git
synced 2026-04-22 08:18:45 +02:00
added rough rule to look for copy paste errors regarding loggers (i.e. obtaining the logger for the wrong class per PR #247)
Former-commit-id: ca6b2566ea496909ea4ab4f48241bb664b130183
This commit is contained in:
@@ -25,4 +25,37 @@ the work on the Logger.
|
||||
Logger.getLogger(Foo.class).log(Level.FINEST, "Don't do this");
|
||||
]]></example>
|
||||
</rule>
|
||||
<rule name="LoggingWrongClass"
|
||||
message="The logger is obtained for the wrong class"
|
||||
class="net.sourceforge.pmd.lang.rule.XPathRule"
|
||||
language="java">
|
||||
<description><![CDATA[
|
||||
Loggers should be created as fields within the class for general
|
||||
use, rather than chaining the call to getLogger() followed by
|
||||
the work on the Logger.
|
||||
]]></description>
|
||||
<properties>
|
||||
<property name="xpath">
|
||||
<value><![CDATA[
|
||||
//ClassOrInterfaceDeclaration[.//PrimaryExpression[PrimaryPrefix/Name[@Image = 'Logger.getLogger']]
|
||||
and not(@Image = .//PrimaryExpression[PrimaryPrefix/Name[@Image = 'Logger.getLogger']]
|
||||
/PrimarySuffix
|
||||
/Arguments
|
||||
/ArgumentList
|
||||
/Expression
|
||||
/PrimaryExpression
|
||||
/PrimaryPrefix
|
||||
/ResultType
|
||||
/Type
|
||||
/ReferenceType
|
||||
/ClassOrInterfaceType/@Image
|
||||
)] ]]></value>
|
||||
</property>
|
||||
</properties>
|
||||
<example><![CDATA[
|
||||
public class Foo {
|
||||
Logger LOGGER = Logger.getLogger(Bar.class.getName()); //should be Foo.class
|
||||
}
|
||||
]]></example>
|
||||
</rule>
|
||||
</ruleset>
|
||||
|
||||
Reference in New Issue
Block a user