CodeNarc - CodeNarc - Enhanced Classpath Rules

##### General

- Home
- Downloads
- Javadocs
- Mailing Lists
- Bug Tracker
- SourceForge Project
- GitHub Project

##### Running

- Ant Task Usage
- Command-Line
- Run as a Test
- Other Tools/Frameworks

##### Using

- Creating a RuleSet
- Creating a Rule
- Configuring Rules
- Starter RuleSet (All)

##### Report Types

- HTML Report
- XML Report
- Text and IDE Reports

##### Sample Reports

- Sample HTML Report
- Sample XML Report

##### Rules

- Rule Index
- Basic Rules
- Braces Rules
- Concurrency Rules
- Convention Rules
- Design Rules
- DRY Rules
- Enhanced Rules
- Exceptions Rules
- Formatting Rules
- Generic Rules
- Grails Rules
- Groovyism Rules
- Imports Rules
- JDBC Rules
- JUnit Rules
- Logging Rules
- Naming Rules
- Size/Complexity Rules
- Security Rules
- Serialization Rules
- Unnecessary Rules
- Unused Rules

##### Developing

- Developer Guide

##### Project Documentation

- Project Information
- Project Reports

## Enhanced Classpath Rules ("rulesets/enhanced.xml")

These rules use a later compilation phase for parsing of the Groovy source code, allowing CodeNarc to use a richer and more complete Abstract Syntax Tree (AST). The downside is that the later compiler phase requires CodeNarc to have the application classes being analyzed, as well as any referenced classes, on the classpath.

Note that these rules may be reorganized and moved to a other rulesets or packages. If possible, include them individually within your ruleset -- refer to them using the rule name, e.g. "CloneWithoutCloneable", rather that pulling in the entire "rulesets/enhanced.xml" ruleset, to protect against future reorganization.

### CloneWithoutCloneable Rule

Since CodeNarc 0.19

The method clone() should only be declared if the class implements the Cloneable interface.

NOTE: This is a CodeNarc Enhanced Classpath Rule. It requires CodeNarc to have the application classes being analyzed, as well as any referenced classes, on the classpath.

Example of violations:

        class ValueClass {
            ValueClass clone() {
            }
        }

### JUnitAssertEqualsConstantActualValue Rule

Since CodeNarc 0.19

Reports usages of `org.junit.Assert.assertEquals([message,] expected, actual)` where the `actual` parameter is a constant or a literal. Most likely it was intended to be the `expected` value.

NOTE: This is a CodeNarc Enhanced Classpath Rule. It requires CodeNarc to have the application classes being analyzed, as well as any referenced classes, on the classpath.

Example of violations:

        assertEquals(result, 2)
        assertEquals("Message", result, 2)
        assertEquals(result, 2.3d, 0.5d)
        assertEquals("Message", result, 2.3d, 0.5d)

### UnsafeImplementationAsMap Rule

Since CodeNarc 0.19

Reports incomplete interface implementations created by map-to-interface coercions.

By default, this rule does not apply to test files.

NOTE: This is a CodeNarc Enhanced Classpath Rule. It requires CodeNarc to have the application classes being analyzed, as well as any referenced classes, on the classpath.

Example of violations:

        [mouseClicked: { ... }] as MouseListener
        //not all MouseListener methods are implemented which can lead to UnsupportedOperationException-s