From 6474139d04d339014c353b5fd70b92e449fd779c Mon Sep 17 00:00:00 2001 From: Paul Gauthier Date: Sat, 18 May 2024 21:13:19 -0700 Subject: [PATCH] Lint files before fixing errors and commit changes if necessary. --- aider/args.py | 1 + aider/commands.py | 12 +++++++----- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/aider/args.py b/aider/args.py index 018e42ca6..0b8ed74d1 100644 --- a/aider/args.py +++ b/aider/args.py @@ -321,6 +321,7 @@ def get_parser(default_config_files, git_root): "--lint-cmd", action="append", help='Specify lint commands to run for different languages, eg: "python: flake8 --select=..." (can be used multiple times)', + default=[], ) diff --git a/aider/commands.py b/aider/commands.py index 7abd0a831..076d5dcf2 100644 --- a/aider/commands.py +++ b/aider/commands.py @@ -165,26 +165,28 @@ class Commands: return fnames = self.coder.repo.get_dirty_files() - - if fnames: - self.cmd_commit("") - + linted = False for fname in fnames: try: errors = self.coder.linter.lint(fname) + linted = True except FileNotFoundError as err: self.io.tool_error(f"Unable to lint {fname}") self.io.tool_error(str(err)) continue if errors: + # Commit everything before we start fixing lint errors + if self.coder.repo.is_dirty(): + self.cmd_commit("") + 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) - if self.coder.repo.is_dirty(): + if linted and self.coder.repo.is_dirty(): self.cmd_commit("") def cmd_clear(self, args):