-
Notifications
You must be signed in to change notification settings - Fork 8
/
run-clippy.py
59 lines (49 loc) · 1.9 KB
/
run-clippy.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
import argparse
import os
import subprocess
from common import J, RED, GREEN, ENDC, Green, Timer, show_error, Runner, Red
class ClippyRunner(Runner):
def runCmd(self, root, dirtype=None):
if dirtype == "test-cases":
self.CMD = ("cargo +nightly-2023-12-16 clippy --target=wasm32-unknown-unknown -Zbuild-std=std,core,alloc "
"--no-default-features -- -D warnings -A clippy::new_without_default")
else:
self.CMD = ("cargo clippy -- -D warnings -A clippy::new_without_default")
return super().runCmd(root, dirtype)
def clean_up(self, root):
ret = subprocess.run(['du', '-hs', 'target'],
cwd=root,
capture_output=True,
text=True)
if ret.returncode==0:
ret = subprocess.run(['rm', '-rf', 'target'],
cwd=root,
capture_output=True,
text=True)
if ret.returncode!=0:
print(" ?> ", ret.returncode)
print(" -> ", ret.stdout)
print(" e> ", ret.stderr)
print(" -------------- ")
def print_clippy_errors(errors):
if errors:
print(Red(f"\nClippy errors detected in the following directories:"))
for error_dir in errors:
print(f"• {error_dir}")
else:
print(Green(f"\nNo clippy issues found across all directories."))
if __name__ == "__main__":
parser = argparse.ArgumentParser(
description="Run cargo-clippy for specified directories"
)
parser.add_argument(
"--dir",
nargs="+",
required=True,
help="Specify the directories to run cargo-clippy on. Multiple directories can be specified.",
)
args = parser.parse_args()
errors = ClippyRunner().run(args.dir) # errors = run_clippy(args.dir)
print_clippy_errors(errors)
if errors:
exit(1)