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

Parameter name should be provided after @param tag #14833

Open
0xbakry opened this issue Apr 26, 2024 · 1 comment
Open

Parameter name should be provided after @param tag #14833

0xbakry opened this issue Apr 26, 2024 · 1 comment

Comments

@0xbakry
Copy link
Contributor

0xbakry commented Apr 26, 2024

Based on #14803 (comment)

$ cat Test.java
public class Test {

  /**
   * @param some text
   */
  public int method(String str)
  {
     return 1;
  }
}


$ java -jar checkstyle-10.12.8-SNAPSHOT-all.jar -j Test.java

|--JAVADOC_TAG -> JAVADOC_TAG [3:5]
|   |--PARAM_LITERAL -> @param [3:5]
|   |--WS ->   [3:11]
|   |--PARAMETER_NAME -> some [3:12]                 // HERE 1
|   |--WS ->   [3:16]
|   `--DESCRIPTION -> DESCRIPTION [3:17]
|       |--TEXT -> text [3:17]
|       |--NEWLINE -> \n [3:21]
|       |--LEADING_ASTERISK ->    * [4:0]
|       |--TEXT -> / [4:4]
|       |--NEWLINE -> \n [4:5]
|       |--TEXT ->   public void test(String str) [5:0]            // HERE 2
|       |--NEWLINE -> \n [5:30]
|       |--TEXT ->   { [6:0]
|       |--NEWLINE -> \n [6:3]
|       |--TEXT ->   } [7:0]

For @param tag if there's a description without the parameter_name it will consider the first word in the Description as the parameter name (look at // HERE 1).

This is not related to the checker itself, it's more related to the parser that builds the AST from the beginning.

As an initial solution, if we are not going to update the parser directly, we may check on the parameters in the method definition ( look at HERE 2).

Example of using a check on such code:
CLI:

$ cat Test.java
public class Test {

  /**
   * @param some text
   */
  public int method(String str)
  {
     return 1;
  }
}

$ 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">
    <property name="charset" value="UTF-8"/>

    <module name="TreeWalker">
       <module name="NonEmptyAtclauseDescription"/>
    </module>

</module>

$ java -jar checkstyle-10.12.8-SNAPSHOT-all.jar -c config.xml Test.java
Starting audit...
Audit done.

Expected: It should produce a violation since parameter_name is not providerd.

@0xbakry
Copy link
Contributor Author

0xbakry commented Apr 30, 2024

@romani please take a look here

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