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

Indentation: Switch expression doesn't pass with LeftCurlies on newlines #14014

Closed
jungm opened this issue Nov 10, 2023 · 2 comments · Fixed by #14024
Closed

Indentation: Switch expression doesn't pass with LeftCurlies on newlines #14014

jungm opened this issue Nov 10, 2023 · 2 comments · Fixed by #14024

Comments

@jungm
Copy link
Contributor

jungm commented Nov 10, 2023

I have read check documentation: https://checkstyle.sourceforge.io/checks/misc/indentation.html
I have downloaded the latest checkstyle 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

$ javac Test.java
$ cat Test.java
public class Test
{
    public void test()
    {
        String otherValue = switch("test") 
        {  // violation
            case "test" -> "hi";

            default -> null;
        };
    }
}
$ cat config.xml
<?xml version="1.0"?>
<!DOCTYPE module PUBLIC
        "-//Checkstyle//DTD Checkstyle Configuration 1.3//EN"
        "https://checkstyle.org/dtds/configuration_1_3.dtd">
<module name="Checker">
  <module name="TreeWalker">
    <module name="Indentation"/>
  </module>
</module>
$ RUN_LOCALE="-Duser.language=en -Duser.country=US"
$ java $RUN_LOCALE -jar checkstyle-10.12.4-all.jar -c config.xml Test.java
Starting audit...
[ERROR] /home/markus/tmp/checkstyle-test/Test.java:6:9: '{' has incorrect indentation level 8, expected level should be 12. [Indentation]
Audit done.
Checkstyle ends with 1 errors.

$ javac Test.java
$ cat Test.java
public class Test
{
    public void test()
    {
        String otherValue = switch("test") 
            {
            case "test" -> "hi";

            default -> null;
        };
    }
}
$ java $RUN_LOCALE -jar checkstyle-10.12.4-all.jar -c config.xml Test.java
Starting audit...
[ERROR] /home/markus/tmp/checkstyle-test/Test.java:6:13: 'switch lcurly' has incorrect indentation level 12, expected level should be 8. [Indentation]
Audit done.
Checkstyle ends with 1 errors.

Describe what you expect in detail.
Checkstyle can be passed, following the suggested outputs of the Indendation check is just an infinite loop.
Note that I intentionally left out the LeftCurly module with option=nl as it's not needed to reproduce this

jungm added a commit to jungm/checkstyle that referenced this issue Nov 12, 2023
@jungm
Copy link
Contributor Author

jungm commented Nov 12, 2023

After some digging I found a solution to this, any chance this can be approved so I can officially PR it and it can get reviewed? Or can I just PR anyways?

@romani
Copy link
Member

romani commented Nov 12, 2023

@jungm , issue is approved, thanks for pinning.
Please be careful with this module, it has a lot of issues already opened, if we find solution that is not breaking other functionality we can merge, do not hesitate to raise and discuss some challenges in PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants