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

Java14 Full Records Support Check Validation: JavaNCSSCheck #8505

Closed
nrmancuso opened this issue Jul 16, 2020 · 1 comment · Fixed by #8575
Closed

Java14 Full Records Support Check Validation: JavaNCSSCheck #8505

nrmancuso opened this issue Jul 16, 2020 · 1 comment · Fixed by #8575

Comments

@nrmancuso
Copy link
Member

nrmancuso commented Jul 16, 2020

Child of #8452
Check documentation: https://checkstyle.sourceforge.io/config_metrics.html#JavaNCSS

From check documentation:
Determines complexity of methods, classes and files by counting the Non Commenting Source Statements (NCSS). This check adheres to the specification for the JavaNCSS-Tool written by Chr. Clemens Lee.

➜  full-record-grammar /usr/lib/jvm/java-14-openjdk/bin/javac --enable-preview --source 14 TestClass.java
Note: TestClass.java uses preview language features.
Note: Recompile with -Xlint:preview for details.
➜  full-record-grammar 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="JavaNCSS">
          <property name="methodMaximum" value="3"/>
      </module>
  </module>
</module>
➜  full-record-grammar cat TestClass.java

class TestClass {

    public void foo() { // violation
        System.out.println("test");
        System.out.println("test");
        System.out.println("test");
        System.out.println("test"); // 4

    }

    public TestClass() { // violation
        System.out.println("test");
        System.out.println("test");
        System.out.println("test");
        System.out.println("test"); // 4

    }

}


record MyRecord1(boolean t, boolean f) {
    public MyRecord1 { // should be violation
        System.out.println("test");
        System.out.println("test");
        System.out.println("test");
        System.out.println("test"); // 4

    }
}

record MyRecord2(boolean a, boolean b) {
    MyRecord2() { // violation
        this(true, false);
        System.out.println("test");
        System.out.println("test");
        System.out.println("test");
        System.out.println("test"); // 4

    }
}

record MyRecord3(boolean a, boolean b) {
    public void foo() { // violation
        System.out.println("test");
        System.out.println("test");
        System.out.println("test");
        System.out.println("test"); // 4

    }
}

➜  full-record-grammar java $RUN_LOCALE -jar ~/IdeaProjects/checkstyle/target/checkstyle-8.35-SNAPSHOT-all.jar -c config.xml TestClass.java
Starting audit...
[ERROR] /home/nick/Desktop/full-record-grammar/TestClass.java:4:5: NCSS for this method is 5 (max allowed is 3). [JavaNCSS]
[ERROR] /home/nick/Desktop/full-record-grammar/TestClass.java:12:5: NCSS for this method is 5 (max allowed is 3). [JavaNCSS]
[ERROR] /home/nick/Desktop/full-record-grammar/TestClass.java:34:5: NCSS for this method is 6 (max allowed is 3). [JavaNCSS]
[ERROR] /home/nick/Desktop/full-record-grammar/TestClass.java:45:5: NCSS for this method is 5 (max allowed is 3). [JavaNCSS]
Audit done.
Checkstyle ends with 4 errors.

This check still works inside of record defintions, but we need to add support for compact constructors.


Final fix summary: new property is created

nrmancuso added a commit to nrmancuso/checkstyle that referenced this issue Jul 29, 2020
nrmancuso added a commit to nrmancuso/checkstyle that referenced this issue Jul 29, 2020
nrmancuso added a commit to nrmancuso/checkstyle that referenced this issue Jul 29, 2020
nrmancuso added a commit to nrmancuso/checkstyle that referenced this issue Jul 29, 2020
nrmancuso added a commit to nrmancuso/checkstyle that referenced this issue Aug 6, 2020
nrmancuso added a commit to nrmancuso/checkstyle that referenced this issue Aug 7, 2020
@pbludov pbludov linked a pull request Aug 8, 2020 that will close this issue
nrmancuso added a commit to nrmancuso/checkstyle that referenced this issue Aug 11, 2020
@pbludov pbludov added this to the 8.36 milestone Aug 12, 2020
@pbludov
Copy link
Member

pbludov commented Aug 12, 2020

Fix is merged.

shiliyu pushed a commit to shiliyu/checkstyle that referenced this issue Sep 1, 2020
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