Struct doomdooz_lib::source::File

source ·
pub struct File<'a> {
    pub parser_result: ParserResult,
    /* private fields */
}

Fields§

§parser_result: ParserResult

Implementations§

Examples found in repository?
src/source.rs (line 63)
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
    pub fn process(&self) {
        let ast = self.parser_result.ast.as_ref();

        if let Some(ast) = ast {
            self.iterate_nodes(&*ast);
            for (cop_name, handler) in TOKENS_HANLDERS.lock().unwrap().iter() {
                if self.is_enabled(cop_name) {
                    handler(&self.parser_result.tokens, self);
                }
            }
        }
    }

    fn iterate_nodes(&self, node: &types::Node) {
        let call_handlers = |node_type| {
            if let Some(handlers) = NODE_HANDLERS.lock().unwrap().get(node_type) {
                for (cop_name, handler) in handlers {
                    if self.is_enabled(cop_name) {
                        handler(node, self);
                    }
                }
            }
        };

        call_handlers(node.str_type());

        // TODO: implement all types
        match node {
            types::Node::Begin(n) => {
                for statement in &n.statements {
                    self.iterate_nodes(&statement);
                }
            }
            types::Node::Module(n) => {
                if let Some(body) = &n.body {
                    self.iterate_nodes(&body);
                }
            }
            types::Node::Class(n) => {
                if let Some(body) = &n.body {
                    self.iterate_nodes(&body);
                }
            }
            types::Node::Block(n) => {
                if let Some(body) = &n.body {
                    self.iterate_nodes(&body);
                }
            }
            types::Node::Lvasgn(n) => {
                if let Some(body) = &n.value {
                    self.iterate_nodes(&body);
                }
            }
            types::Node::Send(n) => {
                call_handlers(&("send_".to_owned() + &n.method_name));
            }
            _ => (),
        }
    }
Examples found in repository?
src/cop/style/begin_block.rs (line 17)
15
16
17
18
19
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);
    }
}
More examples
Hide additional examples
src/cop/style/end_block.rs (line 17)
15
16
17
18
19
pub fn on_postexe(node: &types::Node, file: &source::File) {
    if let types::Node::Postexe(node) = node {
        file.add_offense(COP_NAME, node.keyword_l, MSG);
    }
}
src/cop/style/send.rs (line 18)
15
16
17
18
19
20
21
pub fn on_def(node: &types::Node, file: &source::File) {
    if let types::Node::Send(node) = node {
        if node.method_name == "send" {
            file.add_offense(COP_NAME, node.selector_l.unwrap(), MSG)
        }
    }
}
src/cop/style/alias.rs (line 21)
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
pub fn on_alias(node: &types::Node, file: &source::File) {
    if CONFIG.get_string(COP_NAME, "EnforcedStyle") == "prefer_alias_method" {
        if let types::Node::Alias(node) = node {
            file.add_offense(COP_NAME, node.expression_l, MSG_ALIAS_METHOD);
        }
    }
}

pub fn on_alias_method(node: &types::Node, file: &source::File) {
    if CONFIG.get_string(COP_NAME, "EnforcedStyle") == "prefer_alias" {
        if let types::Node::Send(node) = node {
            file.add_offense(COP_NAME, node.expression_l, MSG_ALIAS);
        }
    }
}
src/cop/naming/ascii_identifiers.rs (line 21)
17
18
19
20
21
22
23
24
pub fn on_tokens(tokens: &Vec<types::Token>, file: &source::File) {
    for token in tokens {
        if should_scheck(&token) && !is_ascci(&token.token_value) {
            let offense = first_offense_range(&token);
            file.add_offense(COP_NAME, offense, IDENTIFIER_MSG);
        }
    }
}
src/cop/lint/empty_interpolation.rs (line 20)
15
16
17
18
19
20
21
22
23
24
25
pub fn on_dstr(node: &types::Node, file: &source::File) {
    if let types::Node::Dstr(node) = node {
        for part in &node.parts {
            if let types::Node::Begin(part) = part {
                if part.statements.is_empty() {
                    file.add_offense(COP_NAME, part.expression_l, MSG);
                }
            }
        }
    }
}

Auto Trait Implementations§

Blanket Implementations§

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.