javacheckstyle

How to check empty line between license header and package name in Checkstyle


Could anyone say how to check the presence of empty line between license header and package name, if it is possible. I mean:

/*
 * My license
 */
            <-- I need an empty line here and I want checkstyle to check it
package com.foo;

Solution

  • You can use the EmptyLineSeparator check including the PACKAGE_DEF in the tokens parameter for your use case.

    A simple example:

    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE module
      PUBLIC "-//Puppy Crawl//DTD Check Configuration 1.3//EN" "http://www.puppycrawl.com/dtds/configuration_1_3.dtd">
    <module name="Checker">
        <module name="TreeWalker">
            <module name="EmptyLineSeparator">
                <property name="tokens" value="PACKAGE_DEF"/>
            </module>
        </module>
    </module>