1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
use crate::linter::{Rule, RuleResult};
use sv_parser::{unwrap_node, PortDirection, RefNode, SyntaxTree};

pub struct OutputWithVar;

impl Rule for OutputWithVar {
    fn check(&self, _syntax_tree: &SyntaxTree, node: &RefNode) -> RuleResult {
        match node {
            RefNode::AnsiPortDeclaration(x) => {
                let dir = unwrap_node!(x.clone(), PortDirection);
                let is_output = match dir {
                    Some(RefNode::PortDirection(PortDirection::Output(_))) => true,
                    _ => false,
                };
                let var = unwrap_node!(x.clone(), VarDataTypeVar);
                if is_output && var.is_none() {
                    RuleResult::Fail
                } else {
                    RuleResult::Pass
                }
            }
            _ => RuleResult::Pass,
        }
    }

    fn name(&self) -> String {
        String::from("output_with_var")
    }

    fn hint(&self) -> String {
        String::from("`output` must have `var`")
    }

    fn reason(&self) -> String {
        String::from("")
    }
}