Skip to content

Commit 0fdcd45

Browse files
committed
rename to DenyLevel and integrate Config.deny_warnings
1 parent e5716c1 commit 0fdcd45

File tree

8 files changed

+44
-33
lines changed

8 files changed

+44
-33
lines changed

crates/config/src/lint.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@ pub struct LinterConfig {
2626
/// Defaults to true. Set to false to disable automatic linting during builds.
2727
pub lint_on_build: bool,
2828

29-
/// Set the failure threshold.
30-
pub fail_on: FailOn,
29+
/// Set the minimum level threshold for diagnostics.
30+
pub deny: DenyLevel,
3131

3232
/// Configurable patterns that should be excluded when performing `mixedCase` lint checks.
3333
///
@@ -42,23 +42,23 @@ impl Default for LinterConfig {
4242
severity: Vec::new(),
4343
exclude_lints: Vec::new(),
4444
ignore: Vec::new(),
45-
fail_on: FailOn::Never,
45+
deny: DenyLevel::Never,
4646
mixed_case_exceptions: vec!["ERC".to_string()],
4747
}
4848
}
4949
}
5050

5151
/// Diagnostic level (minimum) at which the process should finish with a non-zero exit.
5252
#[derive(Debug, Clone, Copy, PartialEq, Eq, ValueEnum, Default, Serialize, Deserialize)]
53-
#[serde(rename_all = "kebab-case")]
54-
pub enum FailOn {
53+
#[serde(rename_all = "lowercase")]
54+
pub enum DenyLevel {
5555
/// Always exit with zero code.
5656
#[default]
5757
Never,
5858
/// Exit with a non-zero code if any warnings are found.
59-
Warning,
59+
Warnings,
6060
/// Exit with a non-zero code if any notes or warnings are found.
61-
Note,
61+
Notes,
6262
}
6363

6464
/// Severity of a lint.

crates/forge/src/cmd/build.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ use foundry_config::{
2121
value::{Dict, Map, Value},
2222
},
2323
filter::expand_globs,
24+
lint::DenyLevel,
2425
};
2526
use serde::Serialize;
2627
use std::path::PathBuf;
@@ -176,7 +177,11 @@ impl BuildArgs {
176177
let _ = compiler.lower_asts();
177178
Ok(())
178179
})?;
179-
linter.lint(&input_files, config.lint.fail_on, &mut compiler)?;
180+
linter.lint(
181+
&input_files,
182+
if config.deny_warnings { DenyLevel::Warnings } else { config.lint.deny },
183+
&mut compiler,
184+
)?;
180185
}
181186
}
182187

crates/forge/src/cmd/geiger.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use clap::{Parser, ValueHint};
22
use eyre::Result;
33
use foundry_cli::opts::BuildOpts;
4-
use foundry_config::{impl_figment_convert, lint::FailOn};
4+
use foundry_config::{impl_figment_convert, lint::DenyLevel};
55
use std::path::PathBuf;
66

77
/// CLI arguments for `forge geiger`.
@@ -51,7 +51,7 @@ impl GeigerArgs {
5151
lint: Some(vec!["unsafe-cheatcode".to_string()]),
5252
json: false,
5353
build: self.build,
54-
fail_on: Some(FailOn::Note),
54+
deny: Some(DenyLevel::Notes),
5555
};
5656

5757
// Run the lint command with the geiger-specific configuration

crates/forge/src/cmd/lint.rs

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ use foundry_cli::{
1111
use foundry_compilers::{solc::SolcLanguage, utils::SOLC_EXTENSIONS};
1212
use foundry_config::{
1313
filter::expand_globs,
14-
lint::{FailOn, Severity},
14+
lint::{DenyLevel, Severity},
1515
};
1616
use std::path::PathBuf;
1717

@@ -40,7 +40,7 @@ pub struct LintArgs {
4040
/// Specifies the minimum diagnostic level at which the process should finish with a non-zero.
4141
/// exit code.
4242
#[arg(long, value_name = "LEVEL")]
43-
pub fail_on: Option<FailOn>,
43+
pub deny: Option<DenyLevel>,
4444

4545
#[command(flatten)]
4646
pub(crate) build: BuildOpts,
@@ -105,6 +105,13 @@ impl LintArgs {
105105
// Override default severity config with user-defined severity
106106
let severity = self.severity.unwrap_or(config.lint.severity.clone());
107107

108+
// Override default `deny` level config < `deny_warnings` config < user-defined `deny` level
109+
let deny = self.deny.unwrap_or(if config.deny_warnings {
110+
DenyLevel::Warnings
111+
} else {
112+
config.lint.deny
113+
});
114+
108115
if project.compiler.solc.is_none() {
109116
return Err(eyre!("Linting not supported for this language"));
110117
}
@@ -126,8 +133,7 @@ impl LintArgs {
126133
Ok(())
127134
})?;
128135

129-
// Override default fail_on level config with user-defined severity
130-
linter.lint(&input, self.fail_on.unwrap_or(config.lint.fail_on), &mut compiler)?;
136+
linter.lint(&input, deny, &mut compiler)?;
131137

132138
Ok(())
133139
}

crates/forge/tests/cli/config.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1088,7 +1088,7 @@ severity = []
10881088
exclude_lints = []
10891089
ignore = []
10901090
lint_on_build = true
1091-
fail_on = "never"
1091+
deny = "never"
10921092
mixed_case_exceptions = ["ERC"]
10931093
10941094
[doc]
@@ -1316,7 +1316,7 @@ exclude = []
13161316
"exclude_lints": [],
13171317
"ignore": [],
13181318
"lint_on_build": true,
1319-
"fail_on": "never",
1319+
"deny": "never",
13201320
"mixed_case_exceptions": [
13211321
"ERC"
13221322
]

crates/forge/tests/cli/lint.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ forgetest!(can_use_config_mixed_case_exception, |prj, cmd| {
187187
ignore: vec!["src/ContractWithLints.sol".into()],
188188
lint_on_build: true,
189189
mixed_case_exceptions: vec!["MIXED".to_string()],
190-
fail_on: foundry_config::lint::FailOn::Never,
190+
deny: foundry_config::lint::DenyLevel::Never,
191191
};
192192
});
193193
cmd.arg("lint").assert_success().stderr_eq(str![[""]]);
@@ -537,34 +537,34 @@ forgetest!(can_fail_on_lints, |prj, cmd| {
537537

538538
// -- LINT ALL SEVERITIES [OUTPUT: WARN + NOTE] ----------------------------
539539

540-
cmd.forge_fuse().arg("lint").assert_success(); // FailOn::Never (default)
540+
cmd.forge_fuse().arg("lint").assert_success(); // DenyLevel::Never (default)
541541

542542
prj.update_config(|config| {
543-
config.lint.fail_on = foundry_config::lint::FailOn::Warning;
543+
config.lint.deny = foundry_config::lint::DenyLevel::Warnings;
544544
});
545545
cmd.forge_fuse().arg("lint").assert_failure();
546546

547547
prj.update_config(|config| {
548-
config.lint.fail_on = foundry_config::lint::FailOn::Note;
548+
config.lint.deny = foundry_config::lint::DenyLevel::Notes;
549549
});
550550

551551
cmd.forge_fuse().arg("lint").assert_failure();
552552

553553
// -- ONLY LINT LOW SEVERITIES [OUTPUT: NOTE] ------------------------------
554554

555555
prj.update_config(|config| {
556-
config.lint.fail_on = foundry_config::lint::FailOn::Never;
556+
config.lint.deny = foundry_config::lint::DenyLevel::Never;
557557
config.lint.severity = vec![LintSeverity::Info, LintSeverity::Gas, LintSeverity::CodeSize];
558558
});
559559
cmd.forge_fuse().arg("lint").assert_success();
560560

561561
prj.update_config(|config| {
562-
config.lint.fail_on = foundry_config::lint::FailOn::Warning;
562+
config.lint.deny = foundry_config::lint::DenyLevel::Warnings;
563563
});
564564
cmd.forge_fuse().arg("lint").assert_success();
565565

566566
prj.update_config(|config| {
567-
config.lint.fail_on = foundry_config::lint::FailOn::Note;
567+
config.lint.deny = foundry_config::lint::DenyLevel::Notes;
568568
});
569569
cmd.forge_fuse().arg("lint").assert_failure();
570570
});

crates/lint/src/linter/mod.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ pub use late::{LateLintPass, LateLintVisitor};
66

77
use eyre::Result;
88
use foundry_compilers::Language;
9-
use foundry_config::lint::{FailOn, Severity};
9+
use foundry_config::lint::{DenyLevel, Severity};
1010
use solar::{
1111
interface::{
1212
Session, Span,
@@ -43,8 +43,8 @@ pub trait Linter: Send + Sync {
4343
/// The `compiler` should have already been configured with all the sources necessary,
4444
/// as well as having performed parsing and lowering.
4545
///
46-
/// Should return an error based on the configured [`FailOn`] level and the emitted diagnostics.
47-
fn lint(&self, input: &[PathBuf], fail_on: FailOn, compiler: &mut Compiler) -> Result<()>;
46+
/// Should return an error based on the configured [`DenyLevel`] and the emitted diagnostics.
47+
fn lint(&self, input: &[PathBuf], deny: DenyLevel, compiler: &mut Compiler) -> Result<()>;
4848
}
4949

5050
pub trait Lint {

crates/lint/src/sol/mod.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use crate::{
77
};
88
use foundry_common::comments::Comments;
99
use foundry_compilers::{ProjectPathsConfig, solc::SolcLanguage};
10-
use foundry_config::lint::{FailOn, Severity};
10+
use foundry_config::lint::{DenyLevel, Severity};
1111
use rayon::prelude::*;
1212
use solar::{
1313
ast::{self as ast, visit::Visit as VisitAST},
@@ -239,7 +239,7 @@ impl<'a> Linter for SolidityLinter<'a> {
239239
fn lint(
240240
&self,
241241
input: &[PathBuf],
242-
fail_on: FailOn,
242+
deny: DenyLevel,
243243
compiler: &mut Compiler,
244244
) -> eyre::Result<()> {
245245
compiler.enter_mut(|compiler| {
@@ -266,18 +266,18 @@ impl<'a> Linter for SolidityLinter<'a> {
266266

267267
// Handle diagnostics and fail if necessary.
268268
const MSG: &str = "aborting due to ";
269-
match (fail_on, compiler.dcx().warn_count(), compiler.dcx().note_count()) {
270-
// Fail on warnings.
271-
(FailOn::Warning, w, n) if w > 0 => {
269+
match (deny, compiler.dcx().warn_count(), compiler.dcx().note_count()) {
270+
// Deny warnings.
271+
(DenyLevel::Warnings, w, n) if w > 0 => {
272272
if n > 0 {
273273
Err(eyre::eyre!("{MSG}{w} linter warning(s); {n} note(s) were also emitted\n"))
274274
} else {
275275
Err(eyre::eyre!("{MSG}{w} linter warning(s)\n"))
276276
}
277277
}
278278

279-
// Fail on any diagnostic.
280-
(FailOn::Note, w, n) if w > 0 || n > 0 => match (w, n) {
279+
// Deny any diagnostic.
280+
(DenyLevel::Notes, w, n) if w > 0 || n > 0 => match (w, n) {
281281
(w, n) if w > 0 && n > 0 => {
282282
Err(eyre::eyre!("{MSG}{w} linter warning(s) and {n} note(s)\n"))
283283
}

0 commit comments

Comments
 (0)