mirror of
https://github.com/Aider-AI/aider.git
synced 2025-06-01 18:25:00 +00:00
Refactored linter to aggregate lint results and return a unified LintResult object.
This commit is contained in:
parent
84edf3039c
commit
553f39a529
1 changed files with 16 additions and 13 deletions
|
@ -86,32 +86,35 @@ class Linter:
|
||||||
|
|
||||||
def py_lint(self, fname, rel_fname, code):
|
def py_lint(self, fname, rel_fname, code):
|
||||||
result = ''
|
result = ''
|
||||||
res = basic_lint(rel_fname, code)
|
basic_res = basic_lint(rel_fname, code)
|
||||||
if res:
|
compile_res = lint_python_compile(fname, code)
|
||||||
result += res
|
|
||||||
|
|
||||||
res = lint_python_compile(fname, code)
|
|
||||||
if res:
|
|
||||||
result += res
|
|
||||||
|
|
||||||
fatal = "E9,F821,F823,F831,F406,F407,F701,F702,F704,F706"
|
fatal = "E9,F821,F823,F831,F406,F407,F701,F702,F704,F706"
|
||||||
flake8 = f"flake8 --select={fatal} --show-source"
|
flake8 = f"flake8 --select={fatal} --show-source"
|
||||||
|
|
||||||
try:
|
try:
|
||||||
res = self.run_cmd(flake8, rel_fname, code)
|
flake_res = self.run_cmd(flake8, rel_fname, code)
|
||||||
except FileNotFoundError:
|
except FileNotFoundError:
|
||||||
pass
|
flake_res = None
|
||||||
if res:
|
|
||||||
result += res
|
|
||||||
|
|
||||||
return result
|
text = ''
|
||||||
|
lines = set()
|
||||||
|
for res in [basic_res, compile_res, flake_res]:
|
||||||
|
if not res:
|
||||||
|
continue
|
||||||
|
if text:
|
||||||
|
text += '\n'
|
||||||
|
text += res.text
|
||||||
|
lines.update(res.lines)
|
||||||
|
|
||||||
|
return LintResult(text, lines)
|
||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
class LintResult:
|
class LintResult:
|
||||||
text: str
|
text: str
|
||||||
lines: list
|
lines: list
|
||||||
|
|
||||||
|
|
||||||
def lint_python_compile(fname, code):
|
def lint_python_compile(fname, code):
|
||||||
try:
|
try:
|
||||||
compile(code, fname, "exec") # USE TRACEBACK BELOW HERE
|
compile(code, fname, "exec") # USE TRACEBACK BELOW HERE
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue