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
38
39
40
41
42
pub mod bundler;
pub mod layout;
pub mod lint;
pub mod naming;
pub mod style;

use crate::types;
use crate::COPS;
use crate::NODE_HANDLERS;
use crate::TOKENS_HANLDERS;
use std::sync::Once;

static INIT: Once = Once::new();

pub fn init() {
    INIT.call_once(|| {
        bundler::init();
        layout::init();
        lint::init();
        naming::init();
        style::init();
    });
}

pub fn register_node_handler(
    node_name: &'static str,
    cop_name: &'static str,
    handler: types::NodeHandler,
) {
    let mut map = NODE_HANDLERS.lock().unwrap();

    let entry = map.entry(node_name).or_insert(vec![]);
    entry.push((cop_name, handler));
}

pub fn register_tokens_handler(handler: types::TokensHandler, cop_name: &'static str) {
    TOKENS_HANLDERS.lock().unwrap().push((cop_name, handler));
}

pub fn register(cop_name: &'static str) {
    COPS.lock().unwrap().push(cop_name);
}