checkstyle / checkstyle

Checkstyle is a development tool to help programmers write Java code that adheres to a coding standard. By default it supports the Google Java Style Guide and Sun Code Conventions, but is highly configurable. It can be invoked with an ANT task and a command line program.
https://checkstyle.org
GNU Lesser General Public License v2.1
8.28k stars 3.65k forks source link

Add Check Support for Java 21 Unnamed Variables & Patterns Syntax: NoWhitespaceAfter #15224

Closed mahfouz72 closed 3 weeks ago

mahfouz72 commented 1 month ago

child of https://github.com/checkstyle/checkstyle/issues/14942 Check doc: https://checkstyle.org/checks/whitespace/nowhitespaceafter.html#NoWhitespaceAfter


D:\CS\test
javac src/Test.java
D:\CS\test
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="NoWhitespaceAfter">

    </module>
  </module>
</module>
D:\CS\test
cat src/Test.java
public class Test {
    void m(Object o) {
        if (o instanceof ColoredPoint(int x, _   , String c) ) {}
    }
    record ColoredPoint(int x, int y   , String c) { }
}
D:\CS\test
java  -jar checkstyle-10.17.0-all.jar -c config.xml src/Test.java
Starting audit...
Audit done.

Describe what you want in detail.

This check's behavior is correct, we can just add a new test case for unnamed variables. The check doesn't enforce no whitespace after int y then space after _ should not violation

romani commented 1 month ago

Please define line and the expected violation.

nrmancuso commented 1 month ago

Same as https://github.com/checkstyle/checkstyle/issues/15225#issuecomment-2227100628

mahfouz72 commented 1 month ago

@nrmancuso

Same as https://github.com/checkstyle/checkstyle/issues/15225#issuecomment-2228355458

D:\CS\test 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="NoWhitespaceAfter">

    </module>
  </module>
</module>
D:\CS\test cat src\Test.java
public class Test {
    record Point(int x, int y  ,int z) { }
}
D:\CS\test java  -jar checkstyle-10.17.0-all.jar -c config.xml src/Test.java
Starting audit...
Audit done.
nrmancuso commented 1 month ago

We should not be placing violations on this code, I am approving this issue for new test case only.

rnveach commented 3 weeks ago

@mahfouz72 Can you clarify specifically what we are talking about in the first post.

I assume we are talking about line 3's .{space}. However, I don't see how this transfers over to line 4. There is no period, but there is an extra space after _ which is a variable name, not related to a period.

Also you have expected violation but then later say this behavior is correct.

mahfouz72 commented 3 weeks ago

@rnveach first post is updated. This was a bug issue before but then we agreed to not violate this example and just add an input and move on https://github.com/checkstyle/checkstyle/issues/15224#issuecomment-2254252543

rnveach commented 3 weeks ago

First post is still not clear. What exactly were we examining and found not to be an issue.

mahfouz72 commented 3 weeks ago

similarity between these 2 examples

 if (o instanceof ColoredPoint(int x, _   , String c) ) {}  
    record ColoredPoint(int x, int y   , String c) { }

https://github.com/checkstyle/checkstyle/issues/15224#issuecomment-2227100841

rnveach commented 3 weeks ago

It is still not clear what specifically is the target of this issue. What line/column are we talking about. The _ and y and what comes after it?

mahfouz72 commented 3 weeks ago

It is still not clear what specifically is the target of this issue

NoWhitespaceAfter Unnamed patterns as stated im issue title

The _ and y and what comes after it?

Yes. the check doesn't emforces no whitspace after int y then space after _ should not violation

rnveach commented 3 weeks ago

Yes. the check doesn't emforces no whitspace after int y then space after _ should not violation

Please add info like this to the first post. It makes it clearer what we are examining for validation.

mahfouz72 commented 3 weeks ago

@rnveach done