MCPcopy
hub / github.com/Aider-AI/aider / cmd_lint

Method cmd_lint

aider/commands.py:356–409  ·  view source on GitHub ↗

Lint and fix in-chat files or all dirty files if none in chat

(self, args="", fnames=None)

Source from the content-addressed store, hash-verified

354 self.coder.repo.commit(message=commit_message, coder=self.coder)
355
356 def cmd_lint(self, args="", fnames=None):
357 "Lint and fix in-chat files or all dirty files if none in chat"
358
359 if not self.coder.repo:
360 self.io.tool_error("No git repository found.")
361 return
362
363 if not fnames:
364 fnames = self.coder.get_inchat_relative_files()
365
366 # If still no files, get all dirty files in the repo
367 if not fnames and self.coder.repo:
368 fnames = self.coder.repo.get_dirty_files()
369
370 if not fnames:
371 self.io.tool_warning("No dirty files to lint.")
372 return
373
374 fnames = [self.coder.abs_root_path(fname) for fname in fnames]
375
376 lint_coder = None
377 for fname in fnames:
378 try:
379 errors = self.coder.linter.lint(fname)
380 except FileNotFoundError as err:
381 self.io.tool_error(f"Unable to lint {fname}")
382 self.io.tool_output(str(err))
383 continue
384
385 if not errors:
386 continue
387
388 self.io.tool_output(errors)
389 if not self.io.confirm_ask(f"Fix lint errors in {fname}?", default="y"):
390 continue
391
392 # Commit everything before we start fixing lint errors
393 if self.coder.repo.is_dirty() and self.coder.dirty_commits:
394 self.cmd_commit("")
395
396 if not lint_coder:
397 lint_coder = self.coder.clone(
398 # Clear the chat history, fnames
399 cur_messages=[],
400 done_messages=[],
401 fnames=None,
402 )
403
404 lint_coder.add_rel_fname(fname)
405 lint_coder.run(errors)
406 lint_coder.abs_fnames = set()
407
408 if lint_coder and self.coder.repo.is_dirty() and self.coder.auto_commits:
409 self.cmd_commit("")
410
411 def cmd_clear(self, args):
412 "Clear the chat history"

Callers 2

mainFunction · 0.80

Calls 13

cmd_commitMethod · 0.95
get_dirty_filesMethod · 0.80
lintMethod · 0.80
is_dirtyMethod · 0.80
add_rel_fnameMethod · 0.80
tool_errorMethod · 0.45
tool_warningMethod · 0.45
abs_root_pathMethod · 0.45
tool_outputMethod · 0.45
confirm_askMethod · 0.45
cloneMethod · 0.45

Tested by 1