Skip to content
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): Forge Lint #9590

Open
wants to merge 73 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
73 commits
Select commit Hold shift + click to select a range
f6b7096
add lint cmd, variable lints
0xKitsune Dec 23, 2024
a907147
wip
0xKitsune Dec 23, 2024
e43414e
wip
0xKitsune Dec 23, 2024
bd3f2a5
wip
0xKitsune Dec 23, 2024
d7048ae
wip
0xKitsune Dec 23, 2024
4d27229
wip
0xKitsune Dec 23, 2024
1dfd008
wip
0xKitsune Dec 23, 2024
9960ee8
add keccak256 opt test
0xKitsune Dec 23, 2024
cac3f7a
wip
0xKitsune Dec 23, 2024
68dad34
wip
0xKitsune Dec 23, 2024
da7038d
wip
0xKitsune Dec 23, 2024
11b638d
wip
0xKitsune Dec 23, 2024
72e3b3a
fix div before mul
0xKitsune Dec 23, 2024
dd56c01
update lint args
0xKitsune Dec 24, 2024
aabd8ce
wip
0xKitsune Dec 24, 2024
f0dc57b
update declare lints macro
0xKitsune Dec 24, 2024
3417d49
update with_severity
0xKitsune Dec 24, 2024
7e05472
configure linter
0xKitsune Dec 24, 2024
0d56fe0
wip
0xKitsune Dec 24, 2024
28b6f86
update hash value
0xKitsune Dec 24, 2024
d89b62a
fix read in source
0xKitsune Dec 24, 2024
a68f385
rayon
0xKitsune Dec 24, 2024
1eaa26c
Merge pull request #4 from 0xKitsune/kit/forge-lint
0xKitsune Dec 24, 2024
5b56b91
reorder lint declarations
0xKitsune Dec 24, 2024
57436d7
clippy
0xKitsune Dec 24, 2024
e0e32b5
add placeholder for additional lints
0xKitsune Dec 25, 2024
e522ecb
more placeholders
0xKitsune Dec 25, 2024
af33d92
Merge branch 'foundry-rs:master' into master
0xKitsune Dec 26, 2024
200ba86
wip
0xKitsune Dec 28, 2024
869d622
wip
0xKitsune Dec 28, 2024
eb24955
refactor into sol linter
0xKitsune Dec 28, 2024
39e6b54
impl Linter for SolidityLinter
0xKitsune Dec 28, 2024
664bdc3
fmt
0xKitsune Dec 28, 2024
e9fe6dc
wip
0xKitsune Dec 28, 2024
18202ce
wip
0xKitsune Dec 28, 2024
c19a441
refactor lints into SolLint enum
0xKitsune Dec 28, 2024
d0f552e
update lint trait
0xKitsune Dec 28, 2024
e88bc87
wip
0xKitsune Dec 28, 2024
1203d32
wip
0xKitsune Dec 28, 2024
01bb6da
wip
0xKitsune Dec 28, 2024
9d3abf0
wip
0xKitsune Dec 29, 2024
e8b53ca
wip
0xKitsune Dec 29, 2024
5c5343d
update lint
0xKitsune Dec 29, 2024
919f3b1
update forge lint to use ProjectLinter
0xKitsune Dec 29, 2024
f02c967
wip
0xKitsune Dec 29, 2024
e37043c
include/exclude files from linting
0xKitsune Dec 29, 2024
8c0be73
linter output display note
0xKitsune Dec 29, 2024
9fc264b
configure with severity and description
0xKitsune Dec 29, 2024
f8e2c4d
fmt
0xKitsune Dec 29, 2024
8551634
Merge pull request #5 from 0xKitsune/kit/solc-linter
0xKitsune Dec 29, 2024
641b51a
implementing display
0xKitsune Jan 1, 2025
cbd6b2b
wip
0xKitsune Jan 1, 2025
18dadde
wip
0xKitsune Jan 1, 2025
b86a7cf
implement display for linter output, clippy fixes
0xKitsune Jan 1, 2025
dda0366
add note to update colors
0xKitsune Jan 1, 2025
384110d
update linter output display
0xKitsune Jan 1, 2025
c7dd9b4
remove todos, clean up comments
0xKitsune Jan 1, 2025
45b7b3a
clean up display
0xKitsune Jan 1, 2025
1a01afa
update med finding color
0xKitsune Jan 1, 2025
a4d7bd3
add optional help message
0xKitsune Jan 1, 2025
04c6fcc
display help message
0xKitsune Jan 1, 2025
ff88286
simplify lint args, make severity configurable
0xKitsune Jan 1, 2025
50292ee
updating lints, update tests
0xKitsune Jan 1, 2025
721ec17
add tests for info patterns, fix regex
0xKitsune Jan 2, 2025
1e2d403
remove function mixed case
0xKitsune Jan 2, 2025
ce13d5f
doc comments
0xKitsune Jan 2, 2025
beb716f
clippy
0xKitsune Jan 2, 2025
c06da6e
fmt
0xKitsune Jan 2, 2025
775af51
reorganize, crate level docs
0xKitsune Jan 2, 2025
dbaa805
Merge branch 'foundry-rs:master' into master
0xKitsune Jan 2, 2025
c273575
fix info lints
0xKitsune Jan 2, 2025
7ec6164
Merge branch 'master' of github.com:0xKitsune/foundry
0xKitsune Jan 2, 2025
d421d92
fix merge conflicts, update to solar 0.1.1
0xKitsune Jan 8, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ members = [
"crates/script-sequence/",
"crates/macros/",
"crates/test-utils/",
"crates/lint/",

]
resolver = "2"

Expand Down Expand Up @@ -147,6 +149,7 @@ forge = { path = "crates/forge" }

forge-doc = { path = "crates/doc" }
forge-fmt = { path = "crates/fmt" }
forge-lint = { path = "crates/lint" }
forge-verify = { path = "crates/verify" }
forge-script = { path = "crates/script" }
forge-sol-macro-gen = { path = "crates/sol-macro-gen" }
Expand Down Expand Up @@ -174,7 +177,9 @@ foundry-block-explorers = { version = "0.9.0", default-features = false }
foundry-compilers = { version = "0.12.9", default-features = false }
foundry-fork-db = "0.10.0"
solang-parser = "=0.3.3"
solar-ast = { version = "=0.1.1", default-features = false }
solar-parse = { version = "=0.1.1", default-features = false }
solar-interface = { version = "=0.1.1", default-features = false }

## revm
revm = { version = "19.0.0", default-features = false }
Expand Down
2 changes: 2 additions & 0 deletions crates/forge/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ chrono.workspace = true
# bin
forge-doc.workspace = true
forge-fmt.workspace = true
forge-lint.workspace = true
forge-verify.workspace = true
forge-script.workspace = true
forge-sol-macro-gen.workspace = true
Expand Down Expand Up @@ -88,6 +89,7 @@ serde_json.workspace = true
similar = { version = "2", features = ["inline"] }
solang-parser.workspace = true
solar-parse.workspace = true
solar-interface.workspace = true
strum = { workspace = true, features = ["derive"] }
thiserror.workspace = true
tokio = { workspace = true, features = ["time"] }
Expand Down
76 changes: 76 additions & 0 deletions crates/forge/bin/cmd/lint.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
use clap::{Parser, ValueHint};
use eyre::Result;
use forge_lint::{
linter::{ProjectLinter, Severity},
sol::SolidityLinter,
};
use foundry_cli::utils::LoadConfig;
use foundry_config::impl_figment_convert_basic;
use std::{collections::HashSet, path::PathBuf};

/// CLI arguments for `forge lint`.
#[derive(Clone, Debug, Parser)]
pub struct LintArgs {
/// The project's root path.
///
/// By default root of the Git repository, if in one,
/// or the current working directory.
#[arg(long, value_hint = ValueHint::DirPath, value_name = "PATH")]
root: Option<PathBuf>,

/// Include only the specified files when linting.
#[arg(long, value_hint = ValueHint::FilePath, value_name = "FILES", num_args(1..))]
include: Option<Vec<PathBuf>>,

/// Exclude the specified files when linting.
#[arg(long, value_hint = ValueHint::FilePath, value_name = "FILES", num_args(1..))]
exclude: Option<Vec<PathBuf>>,

/// Specifies which lints to run based on severity.
///
/// Supported values: `high`, `med`, `low`, `info`, `gas`.
#[arg(long, value_name = "SEVERITY", num_args(1..))]
severity: Option<Vec<Severity>>,
}

impl_figment_convert_basic!(LintArgs);

impl LintArgs {
pub fn run(self) -> Result<()> {
let config = self.try_load_config_emit_warnings()?;
let project = config.project()?;

// Get all source files from the project
let mut sources =
project.paths.read_input_files()?.keys().cloned().collect::<Vec<PathBuf>>();

// Add included paths to sources
if let Some(include_paths) = &self.include {
let included =
include_paths.iter().filter(|path| path.exists()).cloned().collect::<Vec<_>>();
sources.extend(included);
}

// Remove excluded files from sources
if let Some(exclude_paths) = &self.exclude {
let excluded = exclude_paths.iter().cloned().collect::<HashSet<_>>();
sources.retain(|path| !excluded.contains(path));
}

if sources.is_empty() {
sh_println!("Nothing to lint")?;
std::process::exit(0);
}

let linter = if project.compiler.solc.is_some() {
SolidityLinter::new().with_severity(self.severity)
} else {
todo!("Linting not supported for this language");
};

let output = ProjectLinter::new(linter).lint(&sources)?;
sh_println!("{}", &output)?;

Ok(())
}
}
1 change: 1 addition & 0 deletions crates/forge/bin/cmd/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ pub mod generate;
pub mod init;
pub mod inspect;
pub mod install;
pub mod lint;
pub mod remappings;
pub mod remove;
pub mod selectors;
Expand Down
1 change: 1 addition & 0 deletions crates/forge/bin/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ fn run() -> Result<()> {
}
}
ForgeSubcommand::Fmt(cmd) => cmd.run(),
ForgeSubcommand::Lint(cmd) => cmd.run(),
ForgeSubcommand::Config(cmd) => cmd.run(),
ForgeSubcommand::Flatten(cmd) => cmd.run(),
ForgeSubcommand::Inspect(cmd) => cmd.run(),
Expand Down
6 changes: 5 additions & 1 deletion crates/forge/bin/opts.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use crate::cmd::{
bind::BindArgs, bind_json, build::BuildArgs, cache::CacheArgs, clone::CloneArgs,
compiler::CompilerArgs, config, coverage, create::CreateArgs, doc::DocArgs, eip712, flatten,
fmt::FmtArgs, geiger, generate, init::InitArgs, inspect, install::InstallArgs,
fmt::FmtArgs, geiger, generate, init::InitArgs, inspect, install::InstallArgs, lint::LintArgs,
remappings::RemappingArgs, remove::RemoveArgs, selectors::SelectorsSubcommands, snapshot,
soldeer, test, tree, update,
};
Expand Down Expand Up @@ -140,6 +140,10 @@ pub enum ForgeSubcommand {
/// Format Solidity source files.
Fmt(FmtArgs),

/// Lint Solidity source files
#[command(visible_alias = "l")]
Lint(LintArgs),

/// Get specialized information about a smart contract.
#[command(visible_alias = "in")]
Inspect(inspect::InspectArgs),
Expand Down
33 changes: 33 additions & 0 deletions crates/lint/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@

[package]
name = "forge-lint"

version.workspace = true
edition.workspace = true
rust-version.workspace = true
authors.workspace = true
license.workspace = true
homepage.workspace = true
repository.workspace = true

[lints]
workspace = true

[dependencies]
# lib
foundry-common.workspace = true
foundry-compilers.workspace = true

solar-parse.workspace = true
solar-ast.workspace = true
solar-interface.workspace = true

eyre.workspace = true
rayon.workspace = true
thiserror.workspace = true
serde_json.workspace = true
auto_impl.workspace = true
yansi.workspace = true
serde = { workspace = true, features = ["derive"] }
regex = "1.11"
clap = { version = "4", features = ["derive"] }
5 changes: 5 additions & 0 deletions crates/lint/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
//! # forge-lint
//!
//! Types, traits, and utilities for linting Solidity projects.
pub mod linter;
pub mod sol;
Loading
Loading