Skip to content

Commit

Permalink
MAINT Minor improvements to format.py
Browse files Browse the repository at this point in the history
Fail if command returns nonzero exit code when formatting
Use same flags when checking as when formatting as much as possible
  • Loading branch information
hoodmane committed Aug 21, 2024
1 parent 1c54402 commit d3cfa9a
Showing 1 changed file with 10 additions and 10 deletions.
20 changes: 10 additions & 10 deletions tools/cross/format.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,23 +83,23 @@ def filter_files_by_exts(


def clang_format(files: List[str], check: bool = False) -> bool:
cmd = [CLANG_FORMAT, "--verbose"]
if check:
result = subprocess.run(
[CLANG_FORMAT, "--verbose", "--dry-run", "--Werror"] + files
)
return result.returncode == 0
cmd += ["--dry-run", "--Werror"]
else:
subprocess.run([CLANG_FORMAT, "--verbose", "-i"] + files)
return True
cmd.append("-i")
result = subprocess.run(cmd + files)
return result.returncode == 0


def prettier(files: List[str], check: bool = False) -> bool:
cmd = [PRETTIER]
if check:
result = subprocess.run([PRETTIER, "--check"] + files)
return result.returncode == 0
cmd.append("--check")
else:
subprocess.run([PRETTIER, "--write"] + files)
return True
cmd.append("--write")
result = subprocess.run(cmd + files)
return result.returncode == 0


def git_get_modified_files(
Expand Down

0 comments on commit d3cfa9a

Please sign in to comment.