3 from .ast_validator import RuleCollection, rule
4 from lib.utils import Schema
6 class SyntaxRule(RuleCollection):
7 NodeAssigment = Schema(ast.Subscript,
8 value=Schema(ast.Name, id='__lzLut__'),
10 TrivialValue = Schema(Schema.Union(
15 BoolOperators = Schema(Schema.Union(ast.Or, ast.And))
17 TrivialTest = Schema(ast.Compare,
19 ops=[Schema.Union(ast.Eq)],
20 comparators=[ast.Constant])
22 InlineIf = Schema(ast.IfExp,
23 test=Schema.Union(TrivialTest, TrivialValue),
27 TrivialLogic = Schema(ast.BoolOp,
30 Schema.Union(TrivialTest, ast.Name)
33 TrivialReturn = Schema(Schema.Union(
41 @rule(ast.If, None, "dynamic-logic")
42 def __dynamic_logic(self, reducer, node):
44 Conditional branching could interfering dependency resolving
48 @rule(ast.While, None, "while-loop")
49 def __while_loop(self, reducer, node):
51 loop construct may impact with readability.
55 @rule(ast.For, None, "for-loop")
56 def __for_loop(self, reducer, node):
58 loop construct may impact with readability.
62 @rule(ast.ClassDef, None, "class-def")
63 def __class_definition(self, reducer, node):
65 use of custom class is not recommended
69 @rule(ast.Dict, None, "complex-struct")
70 def __complex_datastruct(self, reducer, node):
72 use of complex data structure is not recommended
76 @rule(ast.Subscript, NodeAssigment, "side-effect-option")
77 def __side_effect(self, reducer, node):
79 Option modifying other options dynamically unpredictable behaviour
83 @rule(ast.Return, None, "non-trivial-value")
84 def __nontrivial_return(self, reducer, node):
86 Option default should be kept as constant or simple membership check
88 return SyntaxRule.TrivialReturn == node.value