Skip to content

lint: add post-increment-decrement gas lint#13986

Open
ParthSinghPS wants to merge 1 commit intofoundry-rs:masterfrom
ParthSinghPS:feat/lint-post-increment-decrement
Open

lint: add post-increment-decrement gas lint#13986
ParthSinghPS wants to merge 1 commit intofoundry-rs:masterfrom
ParthSinghPS:feat/lint-post-increment-decrement

Conversation

@ParthSinghPS
Copy link
Copy Markdown
Contributor

What this PR does

Adds a new post-increment-decrement lint rule in the gas category that flags
i++ and i-- when used in for loop update expressions, suggesting ++i and
--i instead.

Why

Post-increment (i++) and post-decrement (i--) return the value before
modification, requiring an extra copy operation under the hood. In for loop
update expressions the return value is always discarded, so the copy is
pure overhead. Pre-increment (++i) skips the copy entirely.

The lint is intentionally scoped to for loop update expressions only. Outside
of loops, i++ vs ++i is a semantic choice the developer may have made
deliberately.

Changes

  • crates/lint/src/sol/gas/increment.rs: new EarlyLintPass implementation
  • crates/lint/src/sol/gas/mod.rs: registered the new lint
  • crates/lint/testdata/PostIncrementDecrement.sol: test cases covering
    triggering and non-triggering patterns
  • crates/lint/testdata/PostIncrementDecrement.stderr: blessed test output

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: No status

Development

Successfully merging this pull request may close these issues.

1 participant