[Codenarc-user] [ANN] Announcing CodeNarc 0.11
Brought to you by:
chrismair
From: <chr...@wa...> - 2010-11-15 15:35:03
|
The CodeNarc Team is proud to announce the release of version 0.11. CodeNarc is a static analysis tool for Groovy source code. Version 0.11 adds over 50 new rules to the product (bringing the total to 130+ rules) and a few really great features. See The CodeNarc 0.11 Unofficial Guide. New Features @SuppressWarnings Support. All rules now recognize the java.lang.SuppressWarnings annotation on fields, methods, and classes. If this annotation is added then there will be no violations produced. Better "codenarc create-rule" support. CodeNarc is now on the Google App Engine! The CodeNarc Web Console lets you enter source code and execute CodeNarc to see the violations. There are also predefined example scripts such as ReturnFromFinallyBlock. New Rules (Basic Rules) BooleanMethodReturnsNull Rule (basic): Checks for a method with Boolean return type that returns an explicit null. DeadCode Rule (basic) : Checks for dead code that appears after a return statement or after an exception is thrown. DoubleNegative Rule (basic) : Checks for using a double negative, which is always positive. DuplicateCaseStatement Rule (basic) : Check for duplicate case statements in a switch block, such as two equal integers or strings. ExplicitArrayListInstantiation Rule (basic) : This rule checks for the explicit instantiation of an ArrayList. In Groovy, it is best to write new ArrayList() as [], which creates the same object. ExplicitCallToAndMethod Rule (basic) : This rule detects when the and(Object) method is called directly in code instead of using the & operator. ExplicitCallToCompareToMethod Rule (basic) : This rule detects when the compareTo(Object) method is called directly in code instead of using the <=>, >, >=, <, and <= operators. ExplicitCallToDivMethod Rule (basic) : This rule detects when the div(Object) method is called directly in code instead of using the / operator. ExplicitCallToEqualsMethod Rule (basic) : This rule detects when the equals(Object) method is called directly in code instead of using the == or != operator. ExplicitCallToGetAtMethod Rule (basic) : This rule detects when the getAt(Object) method is called directly in code instead of using the [] index operator. ExplicitCallToLeftShiftMethod Rule (basic) : This rule detects when the leftShift(Object) method is called directly in code instead of using the \<\< operator. ExplicitCallToMinusMethod Rule (basic) : This rule detects when the minus(Object) method is called directly in code instead of using the - operator. ExplicitCallToMultiplyMethod Rule (basic) : This rule detects when the multiply(Object) method is called directly in code instead of using the * operator. ExplicitCallToModMethod Rule (basic) : This rule detects when the mod(Object) method is called directly in code instead of using the % operator. ExplicitCallToOrMethod Rule (basic) : This rule detects when the or(Object) method is called directly in code instead of using the | operator. ExplicitCallToPlusMethod Rule (basic) : This rule detects when the plus(Object) method is called directly in code instead of using the + operator. ExplicitCallToPowerMethod Rule (basic) : This rule detects when the power(Object) method is called directly in code instead of using the ** operator. ExplicitCallToRightShiftMethod Rule (basic) : This rule detects when the rightShift(Object) method is called directly in code instead of using the \>\> operator. ExplicitCallToXorMethod Rule (basic) : This rule detects when the xor(Object) method is called directly in code instead of using the ^ operator. ExplicitHashMapInstantiation Rule (basic) : This rule checks for the explicit instantiation of a HashMap. In Groovy, it is best to write new HashMap() as [:], which creates the same object. ExplicitHashSetInstantiation Rule (basic) : This rule checks for the explicit instantiation of a HashSet. In Groovy, it is best to write new HashSet() as [] as Set, which creates the same object. ExplicitLinkedListInstantiation Rule (basic) : This rule checks for the explicit instantiation of a LinkedList. In Groovy, it is best to write new LinkedList() as [] as Queue, which creates the same object. ExplicitStackInstantiation Rule (basic) : This rule checks for the explicit instantiation of a Stack. In Groovy, it is best to write new Stack() as [] as Stack, which creates the same object. ExplicitTreeSetInstantiation Rule (basic) : This rule checks for the explicit instantiation of a TreeSet. In Groovy, it is best to write new TreeSet()>> as [] as SortedSet, which creates the same object. GStringAsMapKey Rule (basic) A GString should not be used as a map key since its hashcode is not guaranteed to be stable. InvertedIfElse Rule (basic) : An inverted if-else statement is one in which there is a single if statement with a single else branch and the boolean test of the if is negated. RemoveAllOnSelf Rule (basic) : Don't use removeAll to clear a collection. ReturnsNullInsteadOfEmptyArray Rule (basic) : If you have a method or closure that returns an array, then when there are no results return a zero-length (empty) array rather than null. ReturnsNullInsteadOfEmptyCollection Rule (basic) : If you have a method or closure that returns a collection, then when there are no results return a zero-length (empty) collection rather than null. SerialVersionUID Rule (basic) : A serialVersionUID is normally intended to be used with Serialization. It needs to be of type long, static, and final. DRY (Don't Repeat Yourself) Rules DuplicateNumberLiteral Rule (dry) : This rule checks for duplicate number literals within the current class. DuplicateStringLiteral Rule (dry) : This rule checks for duplicate String literals within the current class. Exceptions Rules CatchIllegalMonitorStateException Rule (exceptions) : Dubious catching of IllegalMonitorStateException. ConfusingClassNamedException Rule (exceptions) : This class is not derived from another exception, but ends with 'Exception'. ReturnNullFromCatchBlock Rule (exceptions) : Returning null from a catch block often masks errors and requires the client to handle error codes. Concurrency Rules UseOfNotifyMethod Rule (concurrency) : Checks for code that calls notify() rather than notifyAll(). SynchronizedOnGetClass Rule (concurrency) : Checks for synchronization on getClass() rather than class literal. JUnit Rules UseAssertEqualsInsteadOfAssertTrue Rule (junit) : This rule detects JUnit assertions in object equality. UseAssertTrueInsteadOfAssertEqualsRule Rule (junit) : This rule detects JUnit calling assertEquals where the first parameter is a boolean. UseAssertNullInsteadOfAssertEquals Rule (junit) : This rule detects JUnit calling assertEquals where the first or second parameter is null. UseAssertSameInsteadOfAssertTrue Rule (junit) : This rule detects JUnit calling assertTrue or assertFalse where the first or second parameter is an Object#is() call testing for reference equality. JUnitFailWithoutMessage Rule (junit) : This rule detects JUnit calling the fail() method without an argument. JUnitStyleAssertions Rule (junit) : This rule detects calling JUnit style assertions like assertEquals, assertTrue, assertFalse, assertNull, assertNotNull. Naming Rules ConfusingMethodName Rule (naming) : Checks for very confusing method names. The referenced methods have names that differ only by capitalization. ObjectOverrideMisspelledMethodName Rule (naming) : Verifies that the names of the most commonly overridden methods of Object: equals, hashCode and toString, are correct. Size Rules MethodCount Rule (size) : Checks if the number of methods within a class exceeds the number of lines specified by the maxMethod property. Unnecessary Code Rules UnnecessaryConstructor Rule (unnecessary) : This rule detects when a constructor is not necessary; i.e., when there's only one constructor, it's public, has an empty body, and takes no arguments. UnnecessaryCollectionCall Rule (unnecessary) : Checks for useless calls to collections. UnnecessaryOverridingMethod Rule (unnecessary) : Checks for an overriding method that merely calls the same method defined in a superclass. UnnecessaryReturnKeyword Rule (unnecessary) : In Groovy, the return keyword is often optional. Potential Breaking Changes CodeNarc now requires Groovy 1.7. Keep in mind that it can still run against (analyze) older Groovy code. The following three rules were moved from the "basic" ruleset into the new "unnecessary" ruleset. Likewise, the three rule classes were moved from the org.codenarc.rule.basic package into org.codenarc.rule.unnecessary. You will need to adjust your ruleset configuration if you included one of these rules specifically in a custom ruleset, or configured them as part of the "basic" ruleset. UnnecessaryBooleanExpressionRule UnnecessaryIfStatementRule UnnecessaryTernaryExpressionRule AbstractAstVisitor - If you implemented your own rule by subclassing AbstractAstVisitor then your code might break. It is a compile error and the breakage will be clear and obvious. In order to support @SuppressWarnings, we needed to change AbstractAstVisitor. The method visitMethodNode became visitMethodNodeEx, visitClass became visitClassEx, visitConstructorOrMethod became visitConstructorOrMethodEx, visitField became visitFieldEx, visitProperty became visitPropertyEx, and visitConstructor became visitConstructorEx. From within these new methods there is no need to call super.visitX. In the rare case that the simple renaming does not fix your problem then please contact the mailing list. Vote for CodeNarc at DZone Vote for IDEA Support for CodeNarc Visit the CodeNarc Home Page |