Skip to content

AvoidStarImport: new property maxAllowedStarImports to allow atmost one star import in a file #19496

@Aman-Baliyan

Description

@Aman-Baliyan

I have read check documentation: https://checkstyle.org/checks/imports/avoidstarimport.html#AvoidStarImport
I have downloaded the latest cli from: https://checkstyle.org/cmdline.html#Download_and_Run
I have executed the cli and showed it below, as cli describes the problem better than 1,000 words

How it works Now:

/var/tmp $ cat config.xml
<module name="Checker">
    <property name="localeLanguage" value="en"/>

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


/var/tmp $ cat YOUR_FILE.java
package temp;

import java.util.*;

public class Test {

}


/var/tmp $ RUN_LOCALE="-Duser.language=en -Duser.country=US"
/var/tmp $ java -jar checkstyle-13.2.0-all.jar -c config.xml Test.java
Starting audit...
[ERROR] C:\Users\amanc\Downloads\Ai_Interviewer\PracticeCheckStyle\src\temp\Test.java:3:17: Using the '.*' form of import should be avoided - java.util.*. [AvoidStarImport]
Audit done.
Checkstyle ends with 1 errors.

Is your feature request related to a problem? Please describe.
According to openjdk guidelines - https://cr.openjdk.org/~alundblad/styleguide/index-v6.html#toc-import-statements one star import is allowed but AvoidStarImport did not support this rule.

Describe the solution you'd like
We can create a new property in AvoidStarImport module which allow single star import.

Starting audit...
Audit done.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions