-
Notifications
You must be signed in to change notification settings - Fork 2.1k
feat(forge-lint): [claude] check for unwrapped modifiers #10967
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
feat(forge-lint): [claude] check for unwrapped modifiers #10967
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thank you, makes sense. left some nits, pending @0xrusowsky @DaniPopes review
overall the PR looks good, however i'd like to hold it back until we merge: and then make it do a fix suggestion |
\ |
that's merged now so we can rebuild this PR on top of it |
@0xClandestine if u want to see an example of how to generate snippets, you can check:
note that in that case, rather than using the AST, i used the HIR cause i needed semantic info (i think that for you case the AST should be enough) |
41fc4f8
to
bed9ce0
Compare
bed9ce0
to
d7a6829
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please improve the code suggestions, and let's wait for others to voice their opinions on whether to use fn post_source_unit
or not
Yo sorry for the delay thought we were waiting on #11038, I'll give it a shot this evening. If I have issues feel free to get this across the finish line. Thanks for staying on top of this 🤝 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
overall looks good! please add tests for contract calls, and tomorrow i'll do some final cleanup 🙂
…andestine/foundry into feat/claude-unwrapped-modifier-lint
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
note for other reviewers:
i merged the changes that i originally i made on: https://github.com/foundry-rs/foundry/tree/rusowsky/trim-rmv-span which improves the devex and will close
i did it here cause it was easier to iterate and make sure that the indentation logic was correct (using the snippets of this new lint)
@0xClandestine even if there is some extra feedback from others, i think you can already start your PR to the https://github.com/foundry-rs/book (the CI won't pass until the docs are updated). Please update the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thank you, overall lgtm, left couple of optional nits, pls check 🙏
@0xClandestine i'll take care of this round of feedback, as it is mostly targeted to the changes that i did to figure out the correct indentation 🤝 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm!
Motivation
Coauthored by Claude 4 Opus Max
Modifiers in Solidity that contain logic directly in their body can lead to code duplication when used across multiple functions. Since modifiers are inlined at compile time, any logic within them is duplicated for each function that uses the modifier increasing contract size and deployment cost. A common best practice is to extract modifier logic into internal functions that can be called from within the modifier, reducing code duplication and contract size.
Solution
This PR adds a new gas optimization lint
unwrapped-modifier-logic
that detects when modifiers contain logic directly in their body instead of usinginternal/private/public/library
functions.The lint checks for modifiers that contain any statements other than:
internal/private/public/library
functions._;
Example of code that triggers the lint:
Recommended pattern:
PR Checklist
testdata/ModifierLogic.sol
andtestdata/ModifierLogic.stderr
with comprehensive test cases