Skip to content

feat(forge-lint): support code examples #10844

@0xrusowsky

Description

@0xrusowsky

Component

Forge

Describe the feature you would like

right now lint messages are just "hints" of what should be done, and users must rely on the help link to the lint docs to figure out how to fix the messages.

While this is fine for some rules like the naming ones, it falls short for others such as the asm-keccak256 one. Because of that, we should introduce support for example snippets —which would be directly embedded in the lint, thus minimizing ctx switching for devs—.

currently:

note[asm-keccak256]: hash using inline assembly to save gas
 --> ROOT/testdata/Keccak256.sol:LL:CC
  |
8 |         keccak256(abi.encodePacked(a, b));
  |         ---------
  |
  = help: https://book.getfoundry.sh/reference/forge/forge-lint#asm-keccak256

desired:

note[asm-keccak256]: inefficient hashing mechanism
  --> /Users/rusowsky/dev/ithaca/foundry/master/crates/lint/testdata/Keccak256.sol:13:16
   |
13 |         return keccak256(abi.encodePacked(a, b));
   |                ---------
   |
   = note: consider using inline assembly to optimize gas usage

           - bytes32 hash = keccak256(abi.encodePacked(a, b));
           + bytes32 hash;
           + assembly {
           +     mstore(0x00, a)
           +     mstore(0x20, b)
           +     hash := keccak256(0x00, 0x40)
           + }

   = help: https://book.getfoundry.sh/reference/forge/forge-lint#asm-keccak256

Additional context

No response

Metadata

Metadata

Assignees

Labels

Projects

Status

In Progress

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions