Skip to main content

forge_lint/sol/info/
screaming_snake_case.rs

1use super::ScreamingSnakeCase;
2use crate::{
3    linter::{EarlyLintPass, LintContext},
4    sol::{
5        Severity, SolLint,
6        naming::{check_screaming_snake_case, emit_rename},
7    },
8};
9use solar::ast::{VarMut, VariableDefinition};
10
11declare_forge_lint!(
12    SCREAMING_SNAKE_CASE_CONSTANT,
13    Severity::Info,
14    "screaming-snake-case-const",
15    "constant name is not `SCREAMING_SNAKE_CASE`"
16);
17
18declare_forge_lint!(
19    SCREAMING_SNAKE_CASE_IMMUTABLE,
20    Severity::Info,
21    "screaming-snake-case-immutable",
22    "immutable name is not `SCREAMING_SNAKE_CASE`"
23);
24
25impl<'ast> EarlyLintPass<'ast> for ScreamingSnakeCase {
26    fn check_variable_definition(
27        &mut self,
28        ctx: &LintContext,
29        var: &'ast VariableDefinition<'ast>,
30    ) {
31        if let (Some(name), Some(mutability)) = (var.name, var.mutability)
32            && let Some(expected) = check_screaming_snake_case(name.as_str())
33        {
34            let lint = match mutability {
35                VarMut::Constant => &SCREAMING_SNAKE_CASE_CONSTANT,
36                VarMut::Immutable => &SCREAMING_SNAKE_CASE_IMMUTABLE,
37            };
38            emit_rename(ctx, lint, name.span, expected);
39        }
40    }
41}