From d2d6e2565313faf3db50d68a72bf44e02f8787f1 Mon Sep 17 00:00:00 2001 From: Tom Copeland Date: Fri, 4 Nov 2005 14:08:15 +0000 Subject: [PATCH] Implemented MisleadingVariableName in the naming ruleset git-svn-id: https://pmd.svn.sourceforge.net/svnroot/pmd/trunk@3960 51baf565-9d33-0410-a72c-fc3788e3496d --- pmd/etc/changelog.txt | 6 ++- .../pmd/rules/MisleadingVariableNameTest.java | 43 +++++++++++++++++++ pmd/rulesets/naming.xml | 32 ++++++++++++++ pmd/rulesets/scratchpad.xml | 2 +- pmd/xdocs/credits.xml | 2 +- 5 files changed, 81 insertions(+), 4 deletions(-) create mode 100644 pmd/regress/test/net/sourceforge/pmd/rules/MisleadingVariableNameTest.java diff --git a/pmd/etc/changelog.txt b/pmd/etc/changelog.txt index 1b0945f6fe..2a43c72e2d 100644 --- a/pmd/etc/changelog.txt +++ b/pmd/etc/changelog.txt @@ -1,5 +1,5 @@ ????, 2005 - 3.4: -New rules: NonThreadSafeSingleton (design ruleset), DefaultPackage (controversial ruleset) +New rules: NonThreadSafeSingleton (design ruleset), DefaultPackage (controversial ruleset), MisleadingVariableName (naming ruleset) Fixed bug 1292745 - Removed unused source file ExceptionTypeChecking.java Fixed bug 1292609 - The JDK 1.3 parser now correctly handles certain 'assert' usages. Also added a 'JDK 1.3' menu item to the Designer. Fixed bug 1292689 - Description wrong for UnnecessaryLocalBeforeReturn @@ -481,4 +481,6 @@ Moved Ant task to the net.sourceforge.pmd.ant package Added new HTML report format June 25 2002 - 0.1: -Initial release \ No newline at end of file +Initial release + +Using PMD? Get "PMD Applied", the book! http://pmdapplied.com/ \ No newline at end of file diff --git a/pmd/regress/test/net/sourceforge/pmd/rules/MisleadingVariableNameTest.java b/pmd/regress/test/net/sourceforge/pmd/rules/MisleadingVariableNameTest.java new file mode 100644 index 0000000000..0614c541ce --- /dev/null +++ b/pmd/regress/test/net/sourceforge/pmd/rules/MisleadingVariableNameTest.java @@ -0,0 +1,43 @@ +package test.net.sourceforge.pmd.rules; + +import test.net.sourceforge.pmd.testframework.SimpleAggregatorTst; +import test.net.sourceforge.pmd.testframework.TestDescriptor; +import net.sourceforge.pmd.Rule; +import net.sourceforge.pmd.RuleSetNotFoundException; +import net.sourceforge.pmd.PMD; + +public class MisleadingVariableNameTest extends SimpleAggregatorTst { + private Rule rule; + + public void setUp() throws RuleSetNotFoundException { + rule = findRule("naming", "MisleadingVariableName"); + } + + public void testAll() { + runTests(new TestDescriptor[] { + new TestDescriptor(TEST1, "misnamed param", 1, rule), + new TestDescriptor(TEST2, "misnamed local", 1, rule), + new TestDescriptor(TEST3, "all's well", 0, rule), + }); + } + + private static final String TEST1 = + "public class Foo {" + PMD.EOL + + " void main(String m_foo) {" + PMD.EOL + + " }" + PMD.EOL + + "}"; + + private static final String TEST2 = + "public class Foo {" + PMD.EOL + + " void main() {" + PMD.EOL + + " int m_foo = 42;" + PMD.EOL + + " }" + PMD.EOL + + "}"; + + private static final String TEST3 = + "public class Foo {" + PMD.EOL + + " private int m_bar;" + PMD.EOL + + " public static final int m_buz = 42;" + PMD.EOL + + " private void buz(String biz) {}" + PMD.EOL + + "}"; +} diff --git a/pmd/rulesets/naming.xml b/pmd/rulesets/naming.xml index 02e1829851..4ca06d3c99 100644 --- a/pmd/rulesets/naming.xml +++ b/pmd/rulesets/naming.xml @@ -441,6 +441,38 @@ public class SomeClass { ]]> + + + +Detects when a non-field has a name starting with 'm_'. This usually +indicates a field and thus is confusing. + + + + + + + + + 3 + + + + + diff --git a/pmd/rulesets/scratchpad.xml b/pmd/rulesets/scratchpad.xml index 1356087c6f..757764fbf7 100644 --- a/pmd/rulesets/scratchpad.xml +++ b/pmd/rulesets/scratchpad.xml @@ -7,6 +7,7 @@ These are new rules that are still in progress + -