Skip to content

Commit 4092248

Browse files
committed
support to print --dry-run output
1 parent 69abc70 commit 4092248

File tree

2 files changed

+12
-14
lines changed

2 files changed

+12
-14
lines changed

cpp_linter_hooks/clang_format.py

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,27 +6,24 @@
66

77
def run_clang_format(args) -> int:
88
if expect_version:
9-
dry_run_cmd = [f'clang-format-{expect_version}', '-dry-run', '--Werror']
10-
edit_cmd = [f'clang-format-{expect_version}', '-i']
9+
command = [f'clang-format-{expect_version}', '-i']
1110
else:
12-
dry_run_cmd = ['clang-format', '-dry-run', '--Werror']
13-
edit_cmd = ["clang-format", '-i']
11+
command = ["clang-format", '-i']
1412
for arg in args:
1513
if arg == expect_version or arg.startswith("--version"):
1614
continue
17-
dry_run_cmd.append(arg)
18-
edit_cmd.append(arg)
15+
command.append(arg)
1916

20-
retval = 0
2117
try:
22-
sp = subprocess.run(dry_run_cmd, stdout=subprocess.PIPE)
23-
retval = sp.returncode
24-
output = sp.stdout.decode("utf-8")
25-
if retval != 0:
26-
subprocess.run(edit_cmd, stdout=subprocess.PIPE)
18+
if "--dry-run" in command:
19+
sp = subprocess.run(command, stdout=subprocess.PIPE)
20+
retval = -1 # Not a fail just identify it's a dry-run.
21+
output = sp.stdout.decode("utf-8")
22+
retval = subprocess.run(command, stdout=subprocess.PIPE)
2723
return retval, output
2824
except FileNotFoundError as e:
29-
return 1, e
25+
retval = 1
26+
return retval, e
3027

3128

3229
def main() -> int:

cpp_linter_hooks/clang_tidy.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@ def run_clang_tidy(args) -> int:
1919
output = sp.stdout.decode("utf-8")
2020
return retval, output
2121
except FileNotFoundError as e:
22-
return 1, e
22+
retval = 1
23+
return retval, e
2324

2425

2526
def main() -> int:

0 commit comments

Comments
 (0)