Lint files before fixing errors and commit changes if necessary.

This commit is contained in:
Paul Gauthier 2024-05-18 21:13:19 -07:00
parent d79a629db0
commit 6474139d04
2 changed files with 8 additions and 5 deletions

View file

@ -321,6 +321,7 @@ def get_parser(default_config_files, git_root):
"--lint-cmd", "--lint-cmd",
action="append", action="append",
help='Specify lint commands to run for different languages, eg: "python: flake8 --select=..." (can be used multiple times)', help='Specify lint commands to run for different languages, eg: "python: flake8 --select=..." (can be used multiple times)',
default=[],
) )

View file

@ -165,26 +165,28 @@ class Commands:
return return
fnames = self.coder.repo.get_dirty_files() fnames = self.coder.repo.get_dirty_files()
linted = False
if fnames:
self.cmd_commit("")
for fname in fnames: for fname in fnames:
try: try:
errors = self.coder.linter.lint(fname) errors = self.coder.linter.lint(fname)
linted = True
except FileNotFoundError as err: except FileNotFoundError as err:
self.io.tool_error(f"Unable to lint {fname}") self.io.tool_error(f"Unable to lint {fname}")
self.io.tool_error(str(err)) self.io.tool_error(str(err))
continue continue
if errors: if errors:
# Commit everything before we start fixing lint errors
if self.coder.repo.is_dirty():
self.cmd_commit("")
self.io.tool_error(errors) self.io.tool_error(errors)
abs_file_path = self.coder.abs_root_path(fname) abs_file_path = self.coder.abs_root_path(fname)
self.coder.abs_fnames.add(abs_file_path) self.coder.abs_fnames.add(abs_file_path)
self.coder.run(errors) self.coder.run(errors)
if self.coder.repo.is_dirty(): if linted and self.coder.repo.is_dirty():
self.cmd_commit("") self.cmd_commit("")
def cmd_clear(self, args): def cmd_clear(self, args):