Skip to content

Issue #146: Add recipe for UnusedImports#151

Open
Aman-Baliyan wants to merge 1 commit intocheckstyle:mainfrom
Aman-Baliyan:super
Open

Issue #146: Add recipe for UnusedImports#151
Aman-Baliyan wants to merge 1 commit intocheckstyle:mainfrom
Aman-Baliyan:super

Conversation

@Aman-Baliyan
Copy link
Contributor

@Aman-Baliyan Aman-Baliyan commented Feb 23, 2026

Issue: #146

Check: https://checkstyle.sourceforge.io/checks/imports/unusedimports.html#UnusedImports

This pr implements a new Recipe for UnusedImportCheck of checkstyle.

@Aman-Baliyan Aman-Baliyan force-pushed the super branch 3 times, most recently from 5eca39d to 2fe7bd1 Compare February 23, 2026 19:07
@Aman-Baliyan
Copy link
Contributor Author

@romani sir, please review

@romani
Copy link
Member

romani commented Feb 25, 2026

I don't see test for suppressed violation, we should not remove import

@Aman-Baliyan
Copy link
Contributor Author

I don't see test for suppressed violation, we should not remove import

okay i will add them

@romani
Copy link
Member

romani commented Feb 26, 2026

Our philosophy is: user have full right to suppression violations anywhere for any reason. We aupfix what is market as violation, we do not touch what user do not want to be changed

@Aman-Baliyan
Copy link
Contributor Author

I don't see test for suppressed violation, we should not remove import

Done added example with suppression

Copy link
Member

@romani romani left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

item:

public J.CompilationUnit visitCompilationUnit(J.CompilationUnit cu,
ExecutionContext executionContext) {

this.sourcePath = cu.getSourcePath();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cu --> compileUnit, compilationUnit


private boolean isAtViolationLocation(J.Import literal) {

final String message = createMessage(literal);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

strange that we rely on message ....
it can be changed by user or be in non English.

why you isAtViolationLocation is so different from:

private boolean isAtViolationLocation(J.Literal literal) {

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i think to not match the violation on the basis of line and column basically what i did is extract each import from lst and match that import with violation message import but as suggested by you that the language is a problem.
so i will try to implement by line or column number

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's do as all other for now, ones we get better model, we will refactor all at ones

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

my exams are going on i will continue this after my exams

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

Successfully merging this pull request may close these issues.

2 participants