Skip to content

Commit

Permalink
ignore paths (foundry-rs#3369)
Browse files Browse the repository at this point in the history
  • Loading branch information
rkrasiuk authored and iFrostizz committed Nov 9, 2022
1 parent b233871 commit 22a17c8
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
27 changes: 26 additions & 1 deletion cli/src/cmd/forge/fmt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,32 @@ impl Cmd for FmtArgs {

fn run(self) -> eyre::Result<Self::Output> {
let config = self.try_load_config_emit_warnings()?;
let inputs = self.inputs(&config);

// collect ignore paths first
let mut ignored = vec![];
for res in config.fmt.ignore.iter().map(|pattern| glob::glob(pattern)) {
match res {
Ok(paths) => ignored.extend(paths.into_iter().collect::<Result<Vec<_>, _>>()?),
Err(err) => {
eyre::bail!("failed to parse ignore glob pattern: {err}")
}
}
}
let ignored: Vec<_> = ignored.into_iter().map(|path| config.__root.0.join(path)).collect();

let mut inputs = vec![];
for input in self.inputs(&config) {
match input {
Input::Path(p) => {
if (p.starts_with(&config.__root.0) && !ignored.contains(&p)) ||
!ignored.contains(&config.__root.0.join(&p))
{
inputs.push(Input::Path(p));
}
}
other => inputs.push(other),
};
}

if inputs.is_empty() {
cli_warn!("Nothing to format.\nHINT: If you are working outside of the project, try providing paths to your source files: `forge fmt <paths>`");
Expand Down
3 changes: 3 additions & 0 deletions config/src/fmt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ pub struct FormatterConfig {
pub number_underscore: NumberUnderscore,
/// Style of single line blocks in statements
pub single_line_statement_blocks: SingleLineBlockStyle,
/// Globs to ignore
pub ignore: Vec<String>,
}

/// Style of uint/int256 types
Expand Down Expand Up @@ -107,6 +109,7 @@ impl Default for FormatterConfig {
quote_style: QuoteStyle::Double,
number_underscore: NumberUnderscore::Preserve,
single_line_statement_blocks: SingleLineBlockStyle::Preserve,
ignore: vec![],
}
}
}

0 comments on commit 22a17c8

Please sign in to comment.