forked from phoedos/pmd
added FunctionNameTooShort test in bestpractices category for Kotlin, with unit test cases
This commit is contained in:
@@ -0,0 +1,39 @@
|
||||
<?xml version="1.0"?>
|
||||
|
||||
<ruleset name="Best Practices"
|
||||
xmlns="http://pmd.sourceforge.net/ruleset/2.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://pmd.sourceforge.net/ruleset/2.0.0 https://pmd.sourceforge.io/ruleset_2_0_0.xsd">
|
||||
|
||||
<description>
|
||||
Rules which enforce generally accepted best practices.
|
||||
</description>
|
||||
|
||||
<rule name="FunctionNameTooShort"
|
||||
since="7.0"
|
||||
language="kotlin"
|
||||
message="Function names should have non-cryptic and clear names."
|
||||
class="net.sourceforge.pmd.lang.rule.XPathRule"
|
||||
typeResolution="true"
|
||||
externalInfoUrl="https://pmd.github.io/pmd/pmd_rules_kotlin_bestpractices.html#functionametooshort">
|
||||
<description>
|
||||
Function names should be easy to understand and describe the intention. Makes developers happy.
|
||||
</description>
|
||||
<priority>3</priority>
|
||||
<properties>
|
||||
<property name="version" value="3.1"/>
|
||||
<property name="xpath">
|
||||
<value><![CDATA[
|
||||
//FunctionDeclaration/SimpleIdentifier/T-Identifier[string-length(@Text) < 3]
|
||||
]]></value>
|
||||
</property>
|
||||
</properties>
|
||||
<example>
|
||||
<![CDATA[
|
||||
fun cl() {} // violation, no unavailable attribute added to the function declaration
|
||||
|
||||
fun calculateLayout() // no violation
|
||||
]]>
|
||||
</example>
|
||||
</rule>
|
||||
</ruleset>
|
@@ -2,18 +2,16 @@
|
||||
# BSD-style license; for more info see http://pmd.sourceforge.net/license.html
|
||||
#
|
||||
|
||||
rulesets.filenames=
|
||||
|
||||
rulesets.filenames=\
|
||||
category/kotlin/bestpractices.xml
|
||||
#
|
||||
# categories without rules
|
||||
#
|
||||
|
||||
# category/kotlin/bestpractices.xml,\
|
||||
# category/kotlin/errorprone.xml
|
||||
|
||||
# category/kotlin/codestyle.xml
|
||||
# category/kotlin/design.xml
|
||||
# category/kotlin/documentation.xml
|
||||
# category/kotlin/errorprone.xml
|
||||
# category/kotlin/multithreading.xml
|
||||
# category/kotlin/performance.xml
|
||||
# category/kotlin/security.xml
|
||||
|
@@ -0,0 +1,7 @@
|
||||
#
|
||||
# BSD-style license; for more info see http://pmd.sourceforge.net/license.html
|
||||
#
|
||||
|
||||
rulesets.filenames=\
|
||||
category/kotlin/bestpractices.xml
|
||||
|
@@ -0,0 +1,11 @@
|
||||
/**
|
||||
* BSD-style license; for more info see http://pmd.sourceforge.net/license.html
|
||||
*/
|
||||
|
||||
package net.sourceforge.pmd.lang.kotlin.rule.bestpractices;
|
||||
|
||||
import net.sourceforge.pmd.testframework.PmdRuleTst;
|
||||
|
||||
public class FunctionNameTooShortTest extends PmdRuleTst {
|
||||
// no additional unit tests
|
||||
}
|
@@ -0,0 +1,28 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<test-data
|
||||
xmlns="http://pmd.sourceforge.net/rule-tests"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://pmd.sourceforge.net/rule-tests http://pmd.sourceforge.net/rule-tests_1_0_0.xsd">
|
||||
|
||||
<test-code>
|
||||
<description>Good example #1</description>
|
||||
<expected-problems>0</expected-problems>
|
||||
<code><![CDATA[
|
||||
class GoodBar {
|
||||
fun checkLayout() // good
|
||||
}
|
||||
]]></code>
|
||||
</test-code>
|
||||
<test-code>
|
||||
<description>Bad example #1</description>
|
||||
<expected-problems>2</expected-problems>
|
||||
<expected-linenumbers>2,3</expected-linenumbers>
|
||||
<code><![CDATA[
|
||||
class BadBar {
|
||||
fun cl() // bad
|
||||
fun c() // bad
|
||||
fun clr() // good
|
||||
}
|
||||
]]></code>
|
||||
</test-code>
|
||||
</test-data>
|
Reference in New Issue
Block a user