|
1 | 1 | use super::{install, watch::WatchArgs};
|
2 | 2 | use clap::Parser;
|
3 |
| -use eyre::Result; |
| 3 | +use eyre::{Result, eyre}; |
4 | 4 | use forge_lint::{linter::Linter, sol::SolidityLinter};
|
5 | 5 | use foundry_cli::{
|
6 | 6 | opts::{BuildOpts, solar_pcx_from_build_opts},
|
@@ -112,17 +112,18 @@ impl BuildArgs {
|
112 | 112 | sh_println!("{}", serde_json::to_string_pretty(&output.output())?)?;
|
113 | 113 | }
|
114 | 114 |
|
115 |
| - // Only run the `SolidityLinter` if there are no compilation errors |
116 |
| - if output.output().errors.iter().all(|e| !e.is_error()) { |
117 |
| - self.lint(&project, &config)?; |
| 115 | + // Only run the `SolidityLinter` if lint on build and no compilation errors. |
| 116 | + if config.lint.lint_on_build && !output.output().errors.iter().any(|e| e.is_error()) { |
| 117 | + self.lint(&project, &config, self.paths.as_deref()) |
| 118 | + .map_err(|err| eyre!("Lint failed: {err}"))?; |
118 | 119 | }
|
119 | 120 |
|
120 | 121 | Ok(output)
|
121 | 122 | }
|
122 | 123 |
|
123 |
| - fn lint(&self, project: &Project, config: &Config) -> Result<()> { |
| 124 | + fn lint(&self, project: &Project, config: &Config, files: Option<&[PathBuf]>) -> Result<()> { |
124 | 125 | let format_json = shell::is_json();
|
125 |
| - if project.compiler.solc.is_some() && config.lint.lint_on_build && !shell::is_quiet() { |
| 126 | + if project.compiler.solc.is_some() && !shell::is_quiet() { |
126 | 127 | let linter = SolidityLinter::new(config.project_paths())
|
127 | 128 | .with_json_emitter(format_json)
|
128 | 129 | .with_description(!format_json)
|
@@ -156,6 +157,10 @@ impl BuildArgs {
|
156 | 157 | .project_paths::<SolcLanguage>()
|
157 | 158 | .input_files_iter()
|
158 | 159 | .filter(|p| {
|
| 160 | + // Lint only specified build files, if any. |
| 161 | + if let Some(files) = files { |
| 162 | + return files.iter().any(|file| &curr_dir.join(file) == p); |
| 163 | + } |
159 | 164 | skip.is_match(p)
|
160 | 165 | && !(ignored.contains(p) || ignored.contains(&curr_dir.join(p)))
|
161 | 166 | })
|
|
0 commit comments