Skip to content

feat(forge lint): unused imports #10662

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

Open
wants to merge 13 commits into
base: master
Choose a base branch
from
Open

Conversation

0xrusowsky
Copy link
Contributor

@0xrusowsky 0xrusowsky commented May 29, 2025

Adds a new lint rule for unused imports.

ref:

Closes #10633

@grandizzy
Copy link
Collaborator

hey @0xrusowsky anything else needed for this one or can go to review?

@0xrusowsky
Copy link
Contributor Author

@grandizzy Dani said that it could be easier to implement this feature in solar directly. I was waiting for him to provide some guidance on how to do it.

Copy link
Member

@DaniPopes DaniPopes left a comment

Choose a reason for hiding this comment

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

this is better suited as a builtin lint in solar because its easier to implement during lowering inside of the internal data structures. but because the lint infrastructure is present only in foundry, for now we can store the unused imports as structs in gcx, and gated with a -Z flag that's enabled by forge lint. this way we can also implement it and test it directly in solar test files

I have a vibe coded WIP branch here paradigmxyz/solar@main...dani/unused-imports, I'll try to get this over the line

@0xrusowsky
Copy link
Contributor Author

0xrusowsky commented Jun 23, 2025

i see, makes total sense!
if u have other stuff i'm happy to finish it myself 🙂

@DaniPopes
Copy link
Member

on second thought, this can be implemented using only the AST, like in solhint: https://github.com/protofire/solhint/blob/4dd80890cff0d00051f67f8133877f26482588bb/lib/rules/best-practices/no-unused-import.js#L44

I've done that here in 2 passes: https://github.com/paradigmxyz/solar/blob/c03deb7132224167398f6b829d3c1c88946a1c1e/crates/sema/src/ast_lowering/unused.rs#L7

I think for now it's ok if you just copy the implementation in and we worry about upstreaming it later when we also upstream the lint infra

@0xrusowsky 0xrusowsky requested a review from DaniPopes June 24, 2025 14:47
@0xrusowsky 0xrusowsky marked this pull request as ready for review June 24, 2025 14:51
@grandizzy grandizzy changed the title chore(forge lint): unused imports feat(forge lint): unused imports Jun 24, 2025
@jenpaff jenpaff moved this to Ready For Review in Foundry Jun 24, 2025
Comment on lines +416 to +420
solar-ast = { git = "https://github.com/paradigmxyz/solar.git", branch = "main" }
solar-parse = { git = "https://github.com/paradigmxyz/solar.git", branch = "main" }
solar-interface = { git = "https://github.com/paradigmxyz/solar.git", branch = "main" }
solar-sema = { git = "https://github.com/paradigmxyz/solar.git", branch = "main" }
solar-data-structures = { git = "https://github.com/paradigmxyz/solar.git", branch = "main" }
Copy link
Member

Choose a reason for hiding this comment

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

OK with pinning to main. Context here: #10662 (review)

yash-atreya
yash-atreya previously approved these changes Jun 27, 2025
Copy link
Member

@yash-atreya yash-atreya left a comment

Choose a reason for hiding this comment

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

lgtm!
ci fixes and conflict resolution remain

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Ready For Review
Development

Successfully merging this pull request may close these issues.

feat(forge lint): new lint rule: "unused imports"
4 participants