fix dependency check logic cause config always disabled
[lunaix-os.git] / lunaix-os / scripts / build-tools / lcfg2 / rules.py
1 import ast
2
3 from .ast_validator import RuleCollection, rule
4 from lib.utils import Schema
5
6 class SyntaxRule(RuleCollection):
7     NodeAssigment = Schema(ast.Subscript, 
8                             value=Schema(ast.Name, id='__lzLut__'), 
9                             ctx=ast.Store)
10
11     TrivialReturn  = Schema(Schema.Union(
12         ast.Constant,
13         ast.JoinedStr
14     ))
15
16     def __init__(self):
17         super().__init__()
18     
19     @rule(ast.If, None, "dynamic-logic")
20     def __dynamic_logic(self, reducer, node):
21         """
22         Conditional branching could interfering dependency resolving
23         """
24         return False
25     
26     @rule(ast.While, None, "while-loop")
27     def __while_loop(self, reducer, node):
28         """
29         loop construct may impact with readability.
30         """
31         return False
32     
33     @rule(ast.For, None, "for-loop")
34     def __for_loop(self, reducer, node):
35         """
36         loop construct may impact with readability.
37         """
38         return False
39     
40     @rule(ast.ClassDef, None, "class-def")
41     def __class_definition(self, reducer, node):
42         """
43         use of custom class is not recommended
44         """
45         return False
46     
47     @rule(ast.Dict, None, "complex-struct")
48     def __complex_datastruct(self, reducer, node):
49         """
50         use of complex data structure is not recommended
51         """
52         return False
53     
54     @rule(ast.Subscript, NodeAssigment, "side-effect-option")
55     def __side_effect(self, reducer, node):
56         """
57         Option modifying other options dynamically unpredictable behaviour
58         """
59         return False
60     
61     @rule(ast.Return, None, "non-trivial-value")
62     def __nontrivial_return(self, reducer, node):
63         """
64         Use of non-trivial value as default value
65         """
66         return SyntaxRule.TrivialReturn == node.value