1#[macro_export]
11macro_rules! declare_forge_lint {
12 ($id:ident, $severity:expr, $str_id:expr, $desc:expr) => {
13 pub static $id: SolLint = SolLint {
14 id: $str_id,
15 severity: $severity,
16 description: $desc,
17 help: concat!("https://getfoundry.sh/forge/linting/", $str_id),
18 };
19 };
20}
21
22#[macro_export]
30macro_rules! register_lints {
31 (@register $registry:ident, $config:ident, $pass:ident, early $(, $ctor:expr)?) => {
32 register_lints!(@call $registry, $config, $pass, register_early_pass $(, $ctor)?);
33 };
34 (@register $registry:ident, $config:ident, $pass:ident, late $(, $ctor:expr)?) => {
35 register_lints!(@call $registry, $config, $pass, register_late_pass $(, $ctor)?);
36 };
37 (@register $registry:ident, $config:ident, $pass:ident, project $(, $ctor:expr)?) => {
38 register_lints!(@call $registry, $config, $pass, register_project_pass $(, $ctor)?);
39 };
40
41 (@call $registry:ident, $config:ident, $pass:ident, $method:ident, $ctor:expr) => {{
42 let config = std::sync::Arc::clone($config);
43 $registry.$method($pass::LINT_IDS, move || ($ctor)(std::sync::Arc::clone(&config)));
44 }};
45 (@call $registry:ident, $config:ident, $pass:ident, $method:ident) => {
46 $registry.$method($pass::LINT_IDS, $pass::default);
47 };
48
49 ( $( $module:ident: $( ($pass:ident, $kind:ident, ($($lint:ident),* $(,)?) $(, $ctor:expr)?) ),+ $(,)? ; )* ) => {
50 $(
51 use $module::*;
52
53 $(
54 #[derive(Debug, Default, Clone, Copy, Eq, PartialEq)]
55 pub struct $pass;
56
57 impl $pass {
58 const LINT_IDS: &'static [&'static str] = &[$($lint.id),*];
59 }
60 )+
61 )*
62
63 pub const REGISTERED_LINTS: &[SolLint] = &[$($($($lint,)*)+)*];
64
65 pub fn register_lints(
66 registry: &mut solar_lint::LintRegistry,
67 config: &std::sync::Arc<foundry_config::lint::LintSpecificConfig>,
68 ) {
69 let _ = config;
70 $($( register_lints!(@register registry, config, $pass, $kind $(, $ctor)?); )+)*
71 }
72 };
73}