Since Checkstyle 5.3
Checks that the outer type name and the file name match. For example,
the class Foo must be in a file named
Foo.java.
To configure the check:
<module name="Checker">
<module name="TreeWalker">
<module name="OuterTypeFilename"/>
</module>
</module>
Example of class Test in a file named Test.java
public class Test { // OK
}
Example of class Foo in a file named Test.java
class Foo { // violation
}
Example of interface Foo in a file named Test.java
interface Foo { // violation
}
Example of enum Foo in a file named Test.java
enum Foo { // violation
}
Example of record Foo in a file named Test.java
record Foo { // violation
}
All messages can be customized if the default message doesn't suit you. Please see the documentation to learn how to.
com.puppycrawl.tools.checkstyle.checks