svlint/opt/rustwide/workdir/src/syntaxrules/
prefix_module.rs1use crate::config::ConfigOption;
2use crate::linter::{check_prefix, SyntaxRule, SyntaxRuleResult};
3use sv_parser::{unwrap_node, NodeEvent, RefNode, SyntaxTree};
4
5#[derive(Default)]
6pub struct PrefixModule;
7
8impl SyntaxRule for PrefixModule {
9 fn check(
10 &mut self,
11 syntax_tree: &SyntaxTree,
12 event: &NodeEvent,
13 option: &ConfigOption,
14 ) -> SyntaxRuleResult {
15 let node = match event {
16 NodeEvent::Enter(x) => x,
17 NodeEvent::Leave(_) => {
18 return SyntaxRuleResult::Pass;
19 }
20 };
21 match node {
22 RefNode::ModuleAnsiHeader(x) => {
23 check_prefix(unwrap_node!(*x, ModuleIdentifier), &syntax_tree, &option.prefix_module)
24 }
25 RefNode::ModuleNonansiHeader(x) => {
26 check_prefix(unwrap_node!(*x, ModuleIdentifier), &syntax_tree, &option.prefix_module)
27 }
28 _ => SyntaxRuleResult::Pass,
29 }
30 }
31
32 fn name(&self) -> String {
33 String::from("prefix_module")
34 }
35
36 fn hint(&self, option: &ConfigOption) -> String {
37 String::from(format!(
38 "Prefix `module` identifier with \"{}\".",
39 &option.prefix_module
40 ))
41 }
42
43 fn reason(&self) -> String {
44 String::from("Naming convention simplifies audit.")
45 }
46}