foundry-rs / foundry

Foundry is a blazing fast, portable and modular toolkit for Ethereum application development written in Rust.
https://getfoundry.sh
Apache License 2.0
8.12k stars 1.68k forks source link

Feature: `forge query` - AST based code search #2408

Open sambacha opened 2 years ago

sambacha commented 2 years ago

Component

Forge

Describe the feature you would like

Forge Query

Provide an AST pattern, and see details about when that pattern was introduced.

This enables a much easier way to understand how or why a pattern was introduced. For instance, you can answer questions such as:

To query the codebase to search for such a pattern, we can specify an AST selector as it would be accepted by Forge Lint.

AST selector is supported on AST Explorer for solidity.

For instance, to search for console.log() calls in javascript, the ESLint selector would be

"CallExpression[callee.object.name=console][callee.property.name=log]"

Other use cases

This could be used to help automate refactoring, finding regressions, etc

Additional context

No response

onbjerg commented 2 years ago

Not entirely sure how this feature would answer those questions without some sort of time scale/log, can you expand on that?

sambacha commented 2 years ago

Not entirely sure how this feature would answer those questions without some sort of time scale/log, can you expand on that?

It would resolve to the git commit, can do a PoC tomorrow or Saturday possibly

sambacha commented 2 years ago

Not entirely sure how this feature would answer those questions without some sort of time scale/log, can you expand on that?

It would resolve to the git commit, can do a PoC tomorrow or Saturday possibly

Waiting for this to land: https://github.com/gakonst/ethers-rs/pull/1567