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

LITERAL_DEFAULT token support in RightCurlyCheck #14782

Open
mahfouz72 opened this issue Apr 11, 2024 · 0 comments
Open

LITERAL_DEFAULT token support in RightCurlyCheck #14782

mahfouz72 opened this issue Apr 11, 2024 · 0 comments

Comments

@mahfouz72
Copy link
Member

Currently RightCurlyCheck accepts a less tokens than LeftCurlyCheck (19 tokens)
This issue aims to add support for LITERAL_DEFAULT token in RightCurlyCheck
this issue is a child issue for #3547

For LeftCurlyCheck:

PS D:\test> cat config.xml                                                   
<?xml version="1.0"?>
<!DOCTYPE module PUBLIC
          "-//Puppy Crawl//DTD Check Configuration 1.3//EN"
          "http://www.puppycrawl.com/dtds/configuration_1_3.dtd">

<module name="Checker">
    <property name="charset" value="UTF-8"/>

 <module name="TreeWalker">

      <module name="LeftCurly">
            <property name="tokens" value="LITERAL_DEFAULT"/>
          <property name="option" value="eol"/>
        </module>
    </module>
</module>
PS D:\test> cat src/Test.java                                                
class Test{

    void test(){
        int x = 1;
        switch(x){
            case 1:
            {        
                System.out.println("x is 1");
                break;
            }
            case 2:
            {    
                System.out.println("x is 2");
                break;
            }
            default:
            {                  // violation
                System.out.println("x is neither 1 nor 2");
             }
        }
    }
}
PS D:\test> java  -jar checkstyle-10.13.0-all.jar -c config.xml src/Test.java
Starting audit...
[ERROR] D:\test\src\Test.java:12:13: '{' at column 17 should be on the previous line. [LeftCurly]
Audit done.

for RightCurlyCheck:

PS D:\test> cat config.xml                                                   
<?xml version="1.0"?>
<!DOCTYPE module PUBLIC
          "-//Puppy Crawl//DTD Check Configuration 1.3//EN"
          "http://www.puppycrawl.com/dtds/configuration_1_3.dtd">

<module name="Checker">
    <property name="charset" value="UTF-8"/>

 <module name="TreeWalker">

      <module name="RightCurly">
            <property name="tokens" value="LITERAL_DEFAULT"/>
          <property name="option" value="alone"/>
        </module>
    </module>
</module>
PS D:\test> cat src/Test.java                                                
class Test{

    void test(){
        int x = 1;
        switch(x){
            case 1:
            {
                System.out.println("x is 1");
                break;
            } case 2:                     
            {
                System.out.println("x is 2");
                break;
            } default: {System.out.println("x is neither 1 nor 2");}       // expecting violation here     
        }
    }
}

Expected:- Violation for the right curly brace for LITERAL_DEFAULT
NOTE:- implementation for LITERAL_CASE is done at #14623 I am just waiting for this to get merged and will enable support for default and testing in another PR (the implementation for case and default is almost the same)

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

No branches or pull requests

1 participant