Skip to content

Add Check Support for Java 21 Unnamed Variables & Patterns Syntax: New Check UnusedLambdaParameterShouldBeUnnamed #15059

@mahfouz72

Description

@mahfouz72

child of #14942
violate the non-use of the lambda parameters. They should be unnamed.

Note: The lambda parameters in the check are the parameters of lambda expressions only. The unused pattern variables in the case label of the switch rule are not a target for this check.


Config

$ 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="UnusedLambdaParameterShouldBeUnnamed"/>
    </module>
</module>

Example

public class Test {
    void test(Object obj) {
        List<String> list = List.of("a", "b", "c");
        List<String> Xss = list.stream().map(character -> "x").toList(); // violation
        List<String> Xs = list.stream().map(_-> "x").toList();
    }
}

Expected Output

$ java -jar checkstyle-10.19.0-all.jar -c config.xml Test.java 
Starting audit...
[ERROR] D:\Test.java:4:45:Unused  lambda parameter should be unnamed [UnusedLambdaParameterShouldBeUnnamed]
Audit done.
Checkstyle ends with 1 errors.

Metadata

Metadata

Assignees

Type

No type
No fields configured for issues without a type.

Projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions