mirror of
https://github.com/Aider-AI/aider.git
synced 2025-06-02 10:45:00 +00:00
Added a new command to run the linter on dirty files, fix problems, and then commit.
This commit is contained in:
parent
7b8e603249
commit
04084883e8
4 changed files with 38 additions and 1 deletions
|
@ -311,6 +311,12 @@ def get_parser(default_config_files, git_root):
|
||||||
help="Commit all pending changes with a suitable commit message, then exit",
|
help="Commit all pending changes with a suitable commit message, then exit",
|
||||||
default=False,
|
default=False,
|
||||||
)
|
)
|
||||||
|
group.add_argument(
|
||||||
|
"--lint",
|
||||||
|
action="store_true",
|
||||||
|
help="Run the linter on all dirty files, fix problems and then commit.",
|
||||||
|
default=False,
|
||||||
|
)
|
||||||
|
|
||||||
##########
|
##########
|
||||||
group = parser.add_argument_group("Other Settings")
|
group = parser.add_argument_group("Other Settings")
|
||||||
|
|
|
@ -153,6 +153,30 @@ class Commands:
|
||||||
commit_message = args.strip()
|
commit_message = args.strip()
|
||||||
self.coder.repo.commit(message=commit_message)
|
self.coder.repo.commit(message=commit_message)
|
||||||
|
|
||||||
|
def cmd_lint(self, args):
|
||||||
|
"Run the linter on all dirty files, fix problems and then commit"
|
||||||
|
|
||||||
|
if not self.coder.repo:
|
||||||
|
self.io.tool_error("No git repository found.")
|
||||||
|
return
|
||||||
|
|
||||||
|
if not self.coder.repo.is_dirty():
|
||||||
|
self.io.tool_error("No more changes to commit.")
|
||||||
|
return
|
||||||
|
|
||||||
|
fnames = self.coder.repo.get_dirty_files()
|
||||||
|
|
||||||
|
for fname in fnames:
|
||||||
|
errors = self.coder.linter.lint(fname)
|
||||||
|
if errors:
|
||||||
|
self.io.tool_error(errors)
|
||||||
|
|
||||||
|
abs_file_path = self.coder.abs_root_path(fname)
|
||||||
|
self.coder.abs_fnames.add(abs_file_path)
|
||||||
|
self.coder.run(errors)
|
||||||
|
|
||||||
|
self.cmd_commit("")
|
||||||
|
|
||||||
def cmd_clear(self, args):
|
def cmd_clear(self, args):
|
||||||
"Clear the chat history"
|
"Clear the chat history"
|
||||||
|
|
||||||
|
|
|
@ -24,7 +24,8 @@ class Linter:
|
||||||
py_cmd = f"flake8 --select={fatal} --show-source" # noqa: F841
|
py_cmd = f"flake8 --select={fatal} --show-source" # noqa: F841
|
||||||
|
|
||||||
self.languages = dict(
|
self.languages = dict(
|
||||||
python=self.py_lint,
|
# python=self.py_lint,
|
||||||
|
python="pre-commit run --files"
|
||||||
)
|
)
|
||||||
|
|
||||||
def set_linter(self, lang, cmd):
|
def set_linter(self, lang, cmd):
|
||||||
|
@ -41,8 +42,10 @@ class Linter:
|
||||||
cmd = cmd.split()
|
cmd = cmd.split()
|
||||||
try:
|
try:
|
||||||
subprocess.check_output(cmd, cwd=self.root).decode()
|
subprocess.check_output(cmd, cwd=self.root).decode()
|
||||||
|
print("zero")
|
||||||
return # zero exit status
|
return # zero exit status
|
||||||
except subprocess.CalledProcessError as err:
|
except subprocess.CalledProcessError as err:
|
||||||
|
print("non-zero")
|
||||||
return err.output.decode() # non-zero exit status
|
return err.output.decode() # non-zero exit status
|
||||||
|
|
||||||
def lint(self, fname):
|
def lint(self, fname):
|
||||||
|
|
|
@ -355,6 +355,10 @@ def main(argv=None, input=None, output=None, force_git_root=None, return_coder=F
|
||||||
coder.commands.cmd_commit("")
|
coder.commands.cmd_commit("")
|
||||||
return
|
return
|
||||||
|
|
||||||
|
if args.lint:
|
||||||
|
coder.commands.cmd_lint("")
|
||||||
|
return
|
||||||
|
|
||||||
if args.show_repo_map:
|
if args.show_repo_map:
|
||||||
repo_map = coder.get_repo_map()
|
repo_map = coder.get_repo_map()
|
||||||
if repo_map:
|
if repo_map:
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue