Skip to content

WhitespaceAfter should support LITERAL_CASE token #11666

@turbanoff

Description

@turbanoff

https://checkstyle.org/config_whitespace.html#WhitespaceAfter

I have downloaded the latest cli from: https://checkstyle.org/cmdline.html#Download_and_Run
I have executed the cli and showed it below, as cli describes the problem better than 1,000 words

How it works Now:

/var/tmp $ javac WithSwitch.java
/var/tmp $

/var/tmp $ cat config.xml
<!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="WhitespaceAfter">
            <property name="tokens" value="LITERAL_CASE"/>
        </module>
    </module>
</module>

/var/tmp $ cat WithSwitch.java
package org.cs;

public class WithSwitch {
    public static void main(String[] args) {
        switch (args[0]) {
            case "123":
                return;
            case"1":
                System.out.println(args.length);
            case("23"):
                System.out.println();
        }
    }
}


/var/tmp $ RUN_LOCALE="-Duser.language=en -Duser.country=US"
/var/tmp $ java $RUN_LOCALE -jar checkstyle-10.2-all.jar -c config.xml WithSwitch.java
com.puppycrawl.tools.checkstyle.api.CheckstyleException: cannot initialize module TreeWalker - Token "LITERAL_CASE" was not found in Acceptable tokens list in check com.puppycrawl.tools.checkstyle.checks.whitespace.WhitespaceAfterCheck
        at com.puppycrawl.tools.checkstyle.Checker.setupChild(Checker.java:476)
        at com.puppycrawl.tools.checkstyle.api.AutomaticBean.configure(AutomaticBean.java:201)
        at com.puppycrawl.tools.checkstyle.Main.runCheckstyle(Main.java:403)
        at com.puppycrawl.tools.checkstyle.Main.runCli(Main.java:330)
        at com.puppycrawl.tools.checkstyle.Main.execute(Main.java:189)
com.puppycrawl.tools.checkstyle.api.CheckstyleException: cannot initialize module TreeWalker - Token "LITERAL_CASE" was not found in Acceptable tokens list in check com.puppycrawl.tools.checkstyle.checks.whitespace.WhitespaceAfterCheck
        at com.puppycrawl.tools.checkstyle.Checker.setupChild(Checker.java:476)
        at com.puppycrawl.tools.checkstyle.api.AutomaticBean.configure(AutomaticBean.java:201)
        at com.puppycrawl.tools.checkstyle.Main.runCheckstyle(Main.java:403)
        at com.puppycrawl.tools.checkstyle.Main.runCli(Main.java:330)
        at com.puppycrawl.tools.checkstyle.Main.execute(Main.java:189)
        at com.puppycrawl.tools.checkstyle.Main.main(Main.java:126)
Caused by: com.puppycrawl.tools.checkstyle.api.CheckstyleException: Token "LITERAL_CASE" was not found in Acceptable tokens list in check com.puppycrawl.tools.checkstyle.checks.whitespace.WhitespaceAfterCheck
        at com.puppycrawl.tools.checkstyle.TreeWalker.registerCheck(TreeWalker.java:223)
        at com.puppycrawl.tools.checkstyle.TreeWalker.setupChild(TreeWalker.java:133)
        at com.puppycrawl.tools.checkstyle.api.AutomaticBean.configure(AutomaticBean.java:201)
        at com.puppycrawl.tools.checkstyle.Checker.setupChild(Checker.java:471)
        ... 5 more
Checkstyle ends with 1 errors.

Is your feature request related to a problem? Please describe.
It would be nice if checkstyle could detect missing space after case keyword.

Describe the solution you'd like
WhitespaceAfter could support new literal type - LITERAL_CASE

Additional context
#11489, #11493 and #11494 are similar requests for try/finally/synchronized keywords support

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions