NoCodeInFile

Since Checkstyle 8.33

Description

Checks whether file contains code. Java compiler is not raising errors on files with no code or all commented out. Files which are considered to have no code:

  • File with no text
  • File with single-line comment(s)
  • File with a multi line comment(s).

Examples

To configure the check:

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

Example:

// the violation is on first line of file
// public class Example1 {
// single-line comment is not code
// }
        

Example:

// the violation is on first line of file
/*
 public class Example2 {
 block comment is not code
 }
*/
        

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

Parent Module

TreeWalker