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",
action="append",
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
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):