OuterTypeNumber

Since Checkstyle 5.0

Description

Checks for the number of types declared at the outer (or root) level in a file.

Rationale: It is considered good practice to only define one outer type per file.

Properties

name description type default value since
max Specify the maximum number of outer types allowed. int 1 5.0

Examples

To configure the check to accept 1 outer type per file:

<module name="Checker">
  <module name="TreeWalker">
    <module name="OuterTypeNumber"/>
  </module>
</module>
        

To configure the check to accept 2 outer types per file:

<module name="Checker">
  <module name="TreeWalker">
    <module name="OuterTypeNumber">
      <property name="max" value="2"/>
    </module>
  </module>
</module>
        

Example of Usage

Violation Messages

All messages can be customized if the default message doesn't suit you. Please see the documentation to learn how to.

Package

com.puppycrawl.tools.checkstyle.checks.sizes

Parent Module

TreeWalker