Skip to content

Commit ecc3718

Browse files
driazatifacebook-github-bot
authored andcommitted
Fix clang-tidy path filtering (#60225)
Summary: PR #60048 neglected to include the `--paths` option for file filtering, so it ended up passing every changed file in the diff to clang-tidy (cpp files outside `torch/csrc/`, yaml/sh files, etc.). This adds that back in to make the filtering work properly again. Tested it manually by printing out the files to lint and running ```bash curl -L https://github.com/pytorch/pytorch/pull/60018.diff > diff python tools/clang_tidy.py --diff-file diff --paths torch/csrc/ curl -L https://github.com/pytorch/pytorch/pull/60222.diff > diff python tools/clang_tidy.py --diff-file diff --paths torch/csrc/ ``` Should fix #60192 and fix #60193, the files tripping errors there shouldn't have been passed to clang-tidy in the first place (supporting aten/ for clang-tidy is a separate task) Pull Request resolved: #60225 Reviewed By: zhouzhuojie Differential Revision: D29216251 Pulled By: driazati fbshipit-source-id: b5d7fb7161d33eb7958a6f1ccc25809942045209
1 parent 38c3116 commit ecc3718

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

tools/clang_tidy.py

+5-1
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,6 @@ def find_changed_lines(diff: str) -> Dict[str, List[Tuple[int, int]]]:
142142
for file, start, end in matches:
143143
start_line, _ = start.split(",")
144144
end_line, _ = end.split(",")
145-
print(file, start_line, end_line)
146145

147146
files[file].append((start_line, end_line))
148147

@@ -330,6 +329,11 @@ def main() -> None:
330329
if options.diff_file:
331330
with open(options.diff_file, "r") as f:
332331
changed_files = find_changed_lines(f.read())
332+
changed_files = {
333+
filename: v
334+
for filename, v in changed_files.items()
335+
if any(filename.startswith(path) for path in options.paths)
336+
}
333337
line_filters = [
334338
{"name": name, "lines": lines} for name, lines, in changed_files.items()
335339
]

0 commit comments

Comments
 (0)