Skip to content

Commit 65f0f3a

Browse files
committed
fix: update pre-commit configuration and improve argument formatting in clang_tidy
1 parent f018506 commit 65f0f3a

3 files changed

Lines changed: 52 additions & 17 deletions

File tree

.pre-commit-config.yaml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
ci:
2+
autofix_prs: true
3+
14
repos:
25
- repo: https://github.com/pre-commit/pre-commit-hooks
36
rev: v6.0.0
@@ -10,7 +13,7 @@ repos:
1013
- id: check-toml
1114
- id: requirements-txt-fixer
1215
- repo: https://github.com/astral-sh/ruff-pre-commit
13-
rev: v0.14.2
16+
rev: v0.15.8
1417
hooks:
1518
# Run the linter.
1619
- id: ruff-check

cpp_linter_hooks/clang_tidy.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,9 @@
1111
parser = ArgumentParser()
1212
parser.add_argument("--version", default=DEFAULT_CLANG_TIDY_VERSION)
1313
parser.add_argument("--compile-commands", default=None, dest="compile_commands")
14-
parser.add_argument("--no-compile-commands", action="store_true", dest="no_compile_commands")
14+
parser.add_argument(
15+
"--no-compile-commands", action="store_true", dest="no_compile_commands"
16+
)
1517
parser.add_argument("-v", "--verbose", action="store_true")
1618

1719

@@ -51,7 +53,9 @@ def run_clang_tidy(args=None) -> Tuple[int, str]:
5153

5254
if compile_db_path:
5355
if hook_args.verbose:
54-
print(f"Using compile_commands.json from: {compile_db_path}", file=sys.stderr)
56+
print(
57+
f"Using compile_commands.json from: {compile_db_path}", file=sys.stderr
58+
)
5559
other_args = ["-p", compile_db_path] + other_args
5660

5761
command = ["clang-tidy"] + other_args

tests/test_clang_tidy.py

Lines changed: 42 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,12 @@ def test_compile_commands_explicit(tmp_path):
7272
db_dir = tmp_path / "build"
7373
db_dir.mkdir()
7474
(db_dir / "compile_commands.json").write_text("[]")
75-
with patch("cpp_linter_hooks.clang_tidy.subprocess.run", return_value=_MOCK_RUN) as mock_run, \
76-
patch("cpp_linter_hooks.clang_tidy.resolve_install"):
75+
with (
76+
patch(
77+
"cpp_linter_hooks.clang_tidy.subprocess.run", return_value=_MOCK_RUN
78+
) as mock_run,
79+
patch("cpp_linter_hooks.clang_tidy.resolve_install"),
80+
):
7781
run_clang_tidy([f"--compile-commands={db_dir}", "dummy.cpp"])
7882
cmd = mock_run.call_args[0][0]
7983
assert "-p" in cmd
@@ -85,8 +89,12 @@ def test_compile_commands_auto_detect(tmp_path, monkeypatch):
8589
build_dir = tmp_path / "build"
8690
build_dir.mkdir()
8791
(build_dir / "compile_commands.json").write_text("[]")
88-
with patch("cpp_linter_hooks.clang_tidy.subprocess.run", return_value=_MOCK_RUN) as mock_run, \
89-
patch("cpp_linter_hooks.clang_tidy.resolve_install"):
92+
with (
93+
patch(
94+
"cpp_linter_hooks.clang_tidy.subprocess.run", return_value=_MOCK_RUN
95+
) as mock_run,
96+
patch("cpp_linter_hooks.clang_tidy.resolve_install"),
97+
):
9098
run_clang_tidy(["dummy.cpp"])
9199
cmd = mock_run.call_args[0][0]
92100
assert "-p" in cmd
@@ -99,8 +107,12 @@ def test_compile_commands_auto_detect_fallback(tmp_path, monkeypatch):
99107
out_dir = tmp_path / "out"
100108
out_dir.mkdir()
101109
(out_dir / "compile_commands.json").write_text("[]")
102-
with patch("cpp_linter_hooks.clang_tidy.subprocess.run", return_value=_MOCK_RUN) as mock_run, \
103-
patch("cpp_linter_hooks.clang_tidy.resolve_install"):
110+
with (
111+
patch(
112+
"cpp_linter_hooks.clang_tidy.subprocess.run", return_value=_MOCK_RUN
113+
) as mock_run,
114+
patch("cpp_linter_hooks.clang_tidy.resolve_install"),
115+
):
104116
run_clang_tidy(["dummy.cpp"])
105117
cmd = mock_run.call_args[0][0]
106118
assert "-p" in cmd
@@ -109,8 +121,12 @@ def test_compile_commands_auto_detect_fallback(tmp_path, monkeypatch):
109121

110122
def test_compile_commands_none(tmp_path, monkeypatch):
111123
monkeypatch.chdir(tmp_path)
112-
with patch("cpp_linter_hooks.clang_tidy.subprocess.run", return_value=_MOCK_RUN) as mock_run, \
113-
patch("cpp_linter_hooks.clang_tidy.resolve_install"):
124+
with (
125+
patch(
126+
"cpp_linter_hooks.clang_tidy.subprocess.run", return_value=_MOCK_RUN
127+
) as mock_run,
128+
patch("cpp_linter_hooks.clang_tidy.resolve_install"),
129+
):
114130
run_clang_tidy(["dummy.cpp"])
115131
cmd = mock_run.call_args[0][0]
116132
assert "-p" not in cmd
@@ -122,8 +138,12 @@ def test_compile_commands_conflict_guard(tmp_path, monkeypatch):
122138
build_dir = tmp_path / "build"
123139
build_dir.mkdir()
124140
(build_dir / "compile_commands.json").write_text("[]")
125-
with patch("cpp_linter_hooks.clang_tidy.subprocess.run", return_value=_MOCK_RUN) as mock_run, \
126-
patch("cpp_linter_hooks.clang_tidy.resolve_install"):
141+
with (
142+
patch(
143+
"cpp_linter_hooks.clang_tidy.subprocess.run", return_value=_MOCK_RUN
144+
) as mock_run,
145+
patch("cpp_linter_hooks.clang_tidy.resolve_install"),
146+
):
127147
run_clang_tidy(["-p", "./custom", "dummy.cpp"])
128148
cmd = mock_run.call_args[0][0]
129149
assert cmd.count("-p") == 1
@@ -136,8 +156,12 @@ def test_compile_commands_no_flag(tmp_path, monkeypatch):
136156
build_dir = tmp_path / "build"
137157
build_dir.mkdir()
138158
(build_dir / "compile_commands.json").write_text("[]")
139-
with patch("cpp_linter_hooks.clang_tidy.subprocess.run", return_value=_MOCK_RUN) as mock_run, \
140-
patch("cpp_linter_hooks.clang_tidy.resolve_install"):
159+
with (
160+
patch(
161+
"cpp_linter_hooks.clang_tidy.subprocess.run", return_value=_MOCK_RUN
162+
) as mock_run,
163+
patch("cpp_linter_hooks.clang_tidy.resolve_install"),
164+
):
141165
run_clang_tidy(["--no-compile-commands", "dummy.cpp"])
142166
cmd = mock_run.call_args[0][0]
143167
assert "-p" not in cmd
@@ -165,8 +189,12 @@ def test_compile_commands_explicit_with_p_conflict(tmp_path, capsys):
165189
db_dir = tmp_path / "build"
166190
db_dir.mkdir()
167191
(db_dir / "compile_commands.json").write_text("[]")
168-
with patch("cpp_linter_hooks.clang_tidy.subprocess.run", return_value=_MOCK_RUN) as mock_run, \
169-
patch("cpp_linter_hooks.clang_tidy.resolve_install"):
192+
with (
193+
patch(
194+
"cpp_linter_hooks.clang_tidy.subprocess.run", return_value=_MOCK_RUN
195+
) as mock_run,
196+
patch("cpp_linter_hooks.clang_tidy.resolve_install"),
197+
):
170198
run_clang_tidy([f"--compile-commands={db_dir}", "-p", "./other", "dummy.cpp"])
171199
captured = capsys.readouterr()
172200
assert "Warning" in captured.err

0 commit comments

Comments
 (0)