1
- # src/code_validator/rules_library/basic_rules.py
2
-
3
1
"""Contains concrete implementations of executable validation rules.
4
2
5
3
This module defines the handler classes for both "short" (pre-defined) and
@@ -77,10 +75,10 @@ def execute(self, tree: ast.Module | None, source_code: str | None = None) -> bo
77
75
True if no PEP8 violations are found, False otherwise.
78
76
"""
79
77
if not source_code :
80
- self ._console .print ("Source code is empty, skipping PEP8 check." , level = " WARNING" )
78
+ self ._console .print ("Source code is empty, skipping PEP8 check." , level = LogLevel . WARNING )
81
79
return True
82
80
83
- self ._console .print (f"Rule { self .config .rule_id } : Running flake8 linter..." , level = " DEBUG" )
81
+ self ._console .print (f"Rule { self .config .rule_id } : Running flake8 linter..." , level = LogLevel . DEBUG )
84
82
85
83
params = self .config .params
86
84
args = [sys .executable , "-m" , "flake8" , "-" ]
@@ -102,19 +100,20 @@ def execute(self, tree: ast.Module | None, source_code: str | None = None) -> bo
102
100
103
101
if process .returncode != 0 and process .stdout :
104
102
linter_output = process .stdout .strip ()
105
- self ._console .print (f"Flake8 found issues:\n { linter_output } " , level = " DEBUG" )
103
+ self ._console .print (f"Flake8 found issues:\n { linter_output } " , level = LogLevel . DEBUG )
106
104
return False
107
105
elif process .returncode != 0 :
108
- self ._console .print (f"Flake8 exited with code { process .returncode } :\n { process .stderr } " , level = "ERROR" )
106
+ self ._console .print (f"Flake8 exited with code { process .returncode } :\n { process .stderr } " ,
107
+ level = LogLevel .ERROR )
109
108
return False
110
109
111
- self ._console .print ("PEP8 check passed." , level = "DEBUG" )
110
+ self ._console .print ("PEP8 check passed." , level = LogLevel . ERROR )
112
111
return True
113
112
except FileNotFoundError :
114
- self ._console .print ("flake8 not found. Is it installed in the venv?" , level = " CRITICAL" )
113
+ self ._console .print ("flake8 not found. Is it installed in the venv?" , level = LogLevel . CRITICAL )
115
114
return False
116
115
except Exception as e :
117
- self ._console .print (f"An unexpected error occurred while running flake8: { e } " , level = " CRITICAL" )
116
+ self ._console .print (f"An unexpected error occurred while running flake8: { e } " , level = LogLevel . CRITICAL )
118
117
return False
119
118
120
119
@@ -157,11 +156,11 @@ def execute(self, tree: ast.Module | None, source_code: str | None = None) -> bo
157
156
The boolean result of applying the constraint to the selected nodes.
158
157
"""
159
158
if not tree :
160
- self ._console .print ("AST not available, skipping rule." , level = " WARNING" )
159
+ self ._console .print ("AST not available, skipping rule." , level = LogLevel . WARNING )
161
160
return True
162
161
163
- self ._console .print (f"Applying selector: { self ._selector .__class__ .__name__ } " , level = " DEBUG" )
162
+ self ._console .print (f"Applying selector: { self ._selector .__class__ .__name__ } " , level = LogLevel . DEBUG )
164
163
selected_nodes = self ._selector .select (tree )
165
164
166
- self ._console .print (f"Applying constraint: { self ._constraint .__class__ .__name__ } " , level = " DEBUG" )
167
- return self ._constraint .check (selected_nodes )
165
+ self ._console .print (f"Applying constraint: { self ._constraint .__class__ .__name__ } " , level = LogLevel . DEBUG )
166
+ return self ._constraint .check (selected_nodes )
0 commit comments