mirror of
https://github.com/Aider-AI/aider.git
synced 2025-06-06 20:54:59 +00:00
Added a Linter class for linting files and refactored linting logic in the main function.
This commit is contained in:
parent
dd2ba6e3fc
commit
dc2850b53d
1 changed files with 20 additions and 2 deletions
|
@ -1,3 +1,4 @@
|
||||||
|
import os
|
||||||
import sys
|
import sys
|
||||||
import warnings
|
import warnings
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
@ -9,6 +10,23 @@ warnings.simplefilter("ignore", category=FutureWarning)
|
||||||
from tree_sitter_languages import get_parser # noqa: E402
|
from tree_sitter_languages import get_parser # noqa: E402
|
||||||
|
|
||||||
|
|
||||||
|
class Linter:
|
||||||
|
def __init__(self, encoding="utf-8", root=None):
|
||||||
|
self.encoding = encoding
|
||||||
|
self.root = root
|
||||||
|
|
||||||
|
def get_rel_fname(self, fname):
|
||||||
|
if self.root:
|
||||||
|
os.path.relpath(fname, self.root)
|
||||||
|
else:
|
||||||
|
return fname
|
||||||
|
|
||||||
|
def lint(self, fname):
|
||||||
|
code = Path(fname).read_text()
|
||||||
|
|
||||||
|
display_fname = self.get_rel_fname(fname)
|
||||||
|
return basic_lint(display_fname, code)
|
||||||
|
|
||||||
def basic_lint(fname, code):
|
def basic_lint(fname, code):
|
||||||
lang = filename_to_lang(fname)
|
lang = filename_to_lang(fname)
|
||||||
if not lang:
|
if not lang:
|
||||||
|
@ -65,9 +83,9 @@ def main():
|
||||||
print("Usage: python linter.py <file1> <file2> ...")
|
print("Usage: python linter.py <file1> <file2> ...")
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
|
linter = Linter()
|
||||||
for file_path in sys.argv[1:]:
|
for file_path in sys.argv[1:]:
|
||||||
code = Path(file_path).read_text()
|
errors = linter.lint(file_path)
|
||||||
errors = basic_lint(file_path, code)
|
|
||||||
if errors:
|
if errors:
|
||||||
print(errors)
|
print(errors)
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue