CodeNarc - CodeNarc - Imports 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

## Imports Rules ("rulesets/imports.xml")

### DuplicateImport Rule

Checks for a duplicate import statements.

### ImportFromSamePackage Rule

Checks for an import of a class that is within the same package as the importing class.

### ImportFromSunPackages Rule

New in CodeNarc 0.14 Avoid importing anything from the 'sun.*' packages. These packages are not portable and are likely to change.

Example of violations:

        import sun.misc.foo
        import sun.misc.foo as Foo

        public class MyClass{}

### MisorderedStaticImports Rule

New in CodeNarc 0.14 Checks for static import statements which should never be after nonstatic imports.

This rule has one property `comesBefore`, which defaults to true. If you like your static imports to come after the others, then set this property to false.

Examples of violations:

        import my.something.another
        import static foo.bar

        public class MyClass{}

### UnnecessaryGroovyImport Rule

Checks for an import from any package that is already automatically imported for Groovy files. A Groovy file does not need to include an import for classes from java.lang, java.util, java.io, java.net, groovy.lang and groovy.util, as well as the classes java.math.BigDecimal and java.math.BigInteger.

### UnusedImport Rule

Checks for import statements for classes that are never referenced within the source file. Also checks static imports.

Known limitations:

- Does not check for unused imports containing wildcards (e.g. `import org.codenarc.*`)
- Misses unused imports if the class/alias name is contained within strings, comments or other (longer) names (i.e., if that string shows up almost anywhere within the source code).

### NoWildcardImports Rule

Since CodeNarc 0.21

Wildcard imports, static or otherwise, should not be used.

Example of violations:

        import my.something.*
        import static foo.bar.*

        public class MyClass{}