Skip to content

Commit b9799e6

Browse files
committed
refactor: move to new codesize lint group
1 parent 0d04465 commit b9799e6

File tree

5 files changed

+19
-11
lines changed

5 files changed

+19
-11
lines changed

crates/config/src/lint.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ pub enum Severity {
4545
Low,
4646
Info,
4747
Gas,
48+
CodeSize,
4849
}
4950

5051
impl Severity {
@@ -55,6 +56,7 @@ impl Severity {
5556
Self::Low => Paint::yellow(message).bold().to_string(),
5657
Self::Info => Paint::cyan(message).bold().to_string(),
5758
Self::Gas => Paint::green(message).bold().to_string(),
59+
Self::CodeSize => Paint::green(message).bold().to_string(),
5860
}
5961
}
6062
}
@@ -63,7 +65,7 @@ impl From<Severity> for Level {
6365
fn from(severity: Severity) -> Self {
6466
match severity {
6567
Severity::High | Severity::Med | Severity::Low => Self::Warning,
66-
Severity::Info | Severity::Gas => Self::Note,
68+
Severity::Info | Severity::Gas | Severity::CodeSize => Self::Note,
6769
}
6870
}
6971
}
@@ -76,6 +78,7 @@ impl fmt::Display for Severity {
7678
Self::Low => self.color("Low"),
7779
Self::Info => self.color("Info"),
7880
Self::Gas => self.color("Gas"),
81+
Self::CodeSize => self.color("CodeSize"),
7982
};
8083
write!(f, "{colored}")
8184
}
@@ -102,8 +105,9 @@ impl FromStr for Severity {
102105
"low" => Ok(Self::Low),
103106
"info" => Ok(Self::Info),
104107
"gas" => Ok(Self::Gas),
108+
"size" | "codesize" | "code-size" => Ok(Self::CodeSize),
105109
_ => Err(format!(
106-
"unknown variant: found `{s}`, expected `one of `High`, `Med`, `Low`, `Info`, `Gas``"
110+
"unknown variant: found `{s}`, expected `one of `High`, `Med`, `Low`, `Info`, `Gas`, CodeSize`"
107111
)),
108112
}
109113
}

crates/lint/src/sol/codesize/mod.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
use crate::sol::{EarlyLintPass, LateLintPass, SolLint};
2+
3+
mod unwrapped_modifier_logic;
4+
use unwrapped_modifier_logic::UNWRAPPED_MODIFIER_LOGIC;
5+
6+
register_lints!((UnwrappedModifierLogic, late, (UNWRAPPED_MODIFIER_LOGIC)));
File renamed without changes.

crates/lint/src/sol/gas/mod.rs

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,4 @@ use crate::sol::{EarlyLintPass, LateLintPass, SolLint};
33
mod keccak;
44
use keccak::ASM_KECCAK256;
55

6-
mod unwrapped_modifier_logic;
7-
use unwrapped_modifier_logic::UNWRAPPED_MODIFIER_LOGIC;
8-
9-
register_lints!(
10-
(AsmKeccak256, late, (ASM_KECCAK256)),
11-
(UnwrappedModifierLogic, late, (UNWRAPPED_MODIFIER_LOGIC))
12-
);
6+
register_lints!((AsmKeccak256, late, (ASM_KECCAK256)),);

crates/lint/src/sol/mod.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ use thiserror::Error;
2727
#[macro_use]
2828
pub mod macros;
2929

30+
pub mod codesize;
3031
pub mod gas;
3132
pub mod high;
3233
pub mod info;
@@ -38,6 +39,7 @@ static ALL_REGISTERED_LINTS: LazyLock<Vec<&'static str>> = LazyLock::new(|| {
3839
lints.extend_from_slice(med::REGISTERED_LINTS);
3940
lints.extend_from_slice(info::REGISTERED_LINTS);
4041
lints.extend_from_slice(gas::REGISTERED_LINTS);
42+
lints.extend_from_slice(codesize::REGISTERED_LINTS);
4143
lints.into_iter().map(|lint| lint.id()).collect()
4244
});
4345

@@ -109,9 +111,10 @@ impl SolidityLinter {
109111
passes_and_lints.extend(med::create_early_lint_passes());
110112
passes_and_lints.extend(info::create_early_lint_passes());
111113

112-
// Do not apply gas-severity rules on tests and scripts
114+
// Do not apply 'gas' and 'codesize' severity rules on tests and scripts
113115
if !self.path_config.is_test_or_script(path) {
114116
passes_and_lints.extend(gas::create_early_lint_passes());
117+
passes_and_lints.extend(codesize::create_early_lint_passes());
115118
}
116119

117120
// Filter passes based on linter config
@@ -146,11 +149,12 @@ impl SolidityLinter {
146149
passes_and_lints.extend(med::create_late_lint_passes());
147150
passes_and_lints.extend(info::create_late_lint_passes());
148151

149-
// Do not apply gas-severity rules on tests and scripts
152+
// Do not apply 'gas' and 'codesize' severity rules on tests and scripts
150153
if let FileName::Real(ref path) = file.name
151154
&& !self.path_config.is_test_or_script(path)
152155
{
153156
passes_and_lints.extend(gas::create_late_lint_passes());
157+
passes_and_lints.extend(codesize::create_late_lint_passes());
154158
}
155159

156160
// Filter passes based on config

0 commit comments

Comments
 (0)