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
use crate::cop;
use crate::cop::register_node_handler;
use crate::source;
use crate::types;

static MSG: &str = "Avoid the use of `BEGIN` blocks.";
static COP_NAME: &str = "Style/BeginBlock";

pub fn init() {
    register_node_handler("preexe", COP_NAME, on_preexe);

    cop::register(COP_NAME);
}

pub fn on_preexe(node: &types::Node, file: &source::File) {
    if let types::Node::Preexe(node) = node {
        file.add_offense(COP_NAME, node.keyword_l, MSG);
    }
}

#[cfg(test)]
mod tests {
    #[test]
    fn it_works() {
        crate::expect_offense!(
            "
            BEGIN { test }
        "
        );
    }
}