Skip to content

Commit 5966965

Browse files
committed
[chore] Path changes, fixes, and improvements
Delete unnecessary comments from code. Wherever the level was specified as a string, the LogLevel structure is used.
1 parent 1a1cdbf commit 5966965

File tree

3 files changed

+19
-24
lines changed

3 files changed

+19
-24
lines changed

src/code_validator/components/ast_utils.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ def enrich_ast_with_parents(tree: ast.Module) -> None:
1515
"""
1616
for node in ast.walk(tree):
1717
for child in ast.iter_child_nodes(node):
18-
# Dynamically add a reference to the parent node.
1918
child.parent = node
2019

2120

@@ -37,4 +36,4 @@ def get_full_name(node: ast.AST) -> str | None:
3736
if isinstance(node, ast.Attribute):
3837
base = get_full_name(node.value)
3938
return f"{base}.{node.attr}" if base else node.attr
40-
return None
39+
return None

src/code_validator/core.py

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -45,14 +45,12 @@ def _parse_ast_tree(self) -> bool:
4545
enrich_ast_with_parents(self._ast_tree)
4646
return True
4747
except SyntaxError as e:
48-
# Ищем правило check_syntax, чтобы вывести его кастомное сообщение
4948
for rule in self._validation_rules:
5049
if getattr(rule.config, "type", None) == "check_syntax":
51-
self._console.print(rule.config.message, level="ERROR")
50+
self._console.print(rule.config.message, level=LogLevel.ERROR)
5251
self._failed_rules.append(rule.config.rule_id)
5352
return False
54-
# Если такого правила нет, выводим стандартное сообщение
55-
self._console.print(f"Syntax Error found: {e}", level="ERROR")
53+
self._console.print(f"Syntax Error found: {e}", level=LogLevel.ERROR)
5654
return False
5755

5856
def _load_and_parse_rules(self) -> None:
@@ -75,7 +73,7 @@ def run(self) -> bool:
7573
"""Runs the entire validation process."""
7674
try:
7775
self._load_source_code()
78-
self._load_and_parse_rules() # Загружаем правила до парсинга AST
76+
self._load_and_parse_rules()
7977

8078
if not self._parse_ast_tree():
8179
return False
@@ -84,17 +82,16 @@ def run(self) -> bool:
8482
raise
8583

8684
for rule in self._validation_rules:
87-
# check_syntax уже обработан в _parse_ast_tree, пропускаем его
8885
if getattr(rule.config, "type", None) == "check_syntax":
8986
continue
9087

9188
self._console.print(f"Executing rule: {rule.config.rule_id}", level=LogLevel.DEBUG)
9289
is_passed = rule.execute(self._ast_tree, self._source_code)
9390
if not is_passed:
94-
self._console.print(rule.config.message, level="ERROR")
91+
self._console.print(rule.config.message, level=LogLevel.ERROR)
9592
self._failed_rules.append(rule.config.rule_id)
9693
if getattr(rule.config, "is_critical", False) or self._config.stop_on_first_fail:
97-
self._console.print("Critical rule failed. Halting validation.", level="WARNING")
94+
self._console.print("Critical rule failed. Halting validation.", level=LogLevel.WARNING)
9895
break
9996

100-
return not self._failed_rules
97+
return not self._failed_rules

src/code_validator/rules_library/basic_rules.py

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
# src/code_validator/rules_library/basic_rules.py
2-
31
"""Contains concrete implementations of executable validation rules.
42
53
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
7775
True if no PEP8 violations are found, False otherwise.
7876
"""
7977
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)
8179
return True
8280

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)
8482

8583
params = self.config.params
8684
args = [sys.executable, "-m", "flake8", "-"]
@@ -102,19 +100,20 @@ def execute(self, tree: ast.Module | None, source_code: str | None = None) -> bo
102100

103101
if process.returncode != 0 and process.stdout:
104102
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)
106104
return False
107105
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)
109108
return False
110109

111-
self._console.print("PEP8 check passed.", level="DEBUG")
110+
self._console.print("PEP8 check passed.", level=LogLevel.ERROR)
112111
return True
113112
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)
115114
return False
116115
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)
118117
return False
119118

120119

@@ -157,11 +156,11 @@ def execute(self, tree: ast.Module | None, source_code: str | None = None) -> bo
157156
The boolean result of applying the constraint to the selected nodes.
158157
"""
159158
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)
161160
return True
162161

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)
164163
selected_nodes = self._selector.select(tree)
165164

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

Comments
 (0)