[PATCH] D140772: [clang-tidy] Fix minor bug in add_new_check.py
Chris Cotter via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Fri Dec 30 10:13:20 PST 2022
ccotter added inline comments.
================
Comment at: clang-tools-extra/clang-tidy/add_new_check.py:324-328
doc_files = []
- for subdir in list(filter(lambda s: not s.endswith('.rst') and not s.endswith('.py'),
- os.listdir(docs_dir))):
+ for subdir in list(filter(os.path.isdir, os.listdir(docs_dir))):
for file in filter(lambda s: s.endswith('.rst'), os.listdir(os.path.join(docs_dir, subdir))):
doc_files.append([subdir, file])
doc_files.sort()
----------------
carlosgalvezp wrote:
> It feels this whole code could be made much simpler, readable and safer by just doing:
>
> doc_files = glob.glob(os.path.join(docs_dir, "**", "*.rst"), recursive=True)
I gave this a shot, but realized the the glob returned the relative path `../docs/clang-tidy/checks/<subdir>/<check>.rst`, and the existing logic only adds `[<subdir>, <check>.rst]` to the list. Python3.10's `glob.glob` has root_dir which would do the trick for us, but I don't think we can rely on Python3 yet? I think using glob might not improve the readability all that much since I'd have to strip out the `docs_dir` subpath, but happy to give that a go based on your feedback.
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D140772/new/
https://reviews.llvm.org/D140772
More information about the cfe-commits
mailing list