Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WhitespaceAfter should support LITERAL_CASE token #11666

Closed
turbanoff opened this issue May 22, 2022 · 5 comments
Closed

WhitespaceAfter should support LITERAL_CASE token #11666

turbanoff opened this issue May 22, 2022 · 5 comments

Comments

@turbanoff
Copy link

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

@nrmancuso
Copy link
Member

@turbanoff is there any relevant specification in Google style guide, as in #11489?

@turbanoff
Copy link
Author

Hm, it seems missing space in case of "string" or 'c' is not directly forbidden by Google Style Guide

            case"1":
                System.out.println(args.length);

So, it's not directly relevant.

@as23415672
Copy link
Contributor

I'm on it

as23415672 added a commit to cs304-2022/checkstyle that referenced this issue May 24, 2022
as23415672 added a commit to cs304-2022/checkstyle that referenced this issue May 24, 2022
as23415672 added a commit to cs304-2022/checkstyle that referenced this issue May 24, 2022
as23415672 added a commit to cs304-2022/checkstyle that referenced this issue May 24, 2022
as23415672 added a commit to cs304-2022/checkstyle that referenced this issue May 24, 2022
as23415672 added a commit to cs304-2022/checkstyle that referenced this issue May 24, 2022
as23415672 added a commit to cs304-2022/checkstyle that referenced this issue May 24, 2022
@romani
Copy link
Member

romani commented May 26, 2022

I reviewed at https://checkstyle.org/styleguides/google-java-style-20180523/javaguide.html#s2.1-file-name
all "case" examples, where is always a space, and it is good point in general to have space there.
Let's active it by default and in Google style config.

https://checkstyle.org/styleguides/google-java-style-20180523/javaguide.html#s4.6.2-horizontal-whitespace

Separating any reserved word, such as if, for or catch, from an open parenthesis (() that follows it on that line

It should support this rule.

@romani
Copy link
Member

romani commented May 29, 2022

Fix is merged

@romani romani closed this as completed May 29, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants