This is an archive of the discontinued LLVM Phabricator instance.

[clang-tidy] Fix minor bug in add_new_check.py
ClosedPublic

Authored by ccotter on Dec 29 2022, 8:14 PM.

Details

Summary

While rebuilding the list of checks in add_new_check.py,
check is a file is a subdirectory before traversing it.

Test plan: Ran ./add_new_check.py --update-docs and confirmed the list.rst file was unchanged.

Diff Detail

Event Timeline

ccotter created this revision.Dec 29 2022, 8:14 PM
Herald added a project: Restricted Project. · View Herald Transcript
ccotter requested review of this revision.Dec 29 2022, 8:14 PM
Herald added a project: Restricted Project. · View Herald TranscriptDec 29 2022, 8:14 PM
Herald added a subscriber: cfe-commits. · View Herald Transcript
ccotter retitled this revision from Fix minor bug in add_new_check.py to [clang-tidy] Fix minor bug in add_new_check.py.Dec 29 2022, 8:14 PM
carlosgalvezp accepted this revision.Dec 30 2022, 12:54 AM

LGTM, I have a suggestion for further improvement.

clang-tools-extra/clang-tidy/add_new_check.py
324–328

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)
This revision is now accepted and ready to land.Dec 30 2022, 12:54 AM
ccotter updated this revision to Diff 485710.Dec 30 2022, 10:08 AM

Fix isdir check

ccotter edited the summary of this revision. (Show Details)Dec 30 2022, 10:09 AM
ccotter added inline comments.Dec 30 2022, 10:13 AM
clang-tools-extra/clang-tidy/add_new_check.py
324–328

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.

carlosgalvezp added inline comments.Dec 30 2022, 10:32 AM
clang-tools-extra/clang-tidy/add_new_check.py
324–328

Good point, I was thinking of something along these lines:

from pathlib import Path

for doc_file in map(lambda s: Path(s), glob.glob(os.path.join(docs_dir, "*", "*.rst"))):
  doc_files.append([doc_file.parts[-1], doc_file.parts[-2])

The current patch is already a great cleanup so I'm fine with it as well :)

carlosgalvezp added inline comments.Dec 30 2022, 10:33 AM
clang-tools-extra/clang-tidy/add_new_check.py
324–328

Sorry, I meant:

doc_files.append([doc_file.parts[-2], doc_file.parts[-1])
carlosgalvezp accepted this revision.Dec 30 2022, 10:35 AM

Thanks for the fix!

@carlosgalvezp - could you also help commit this if it looks good?

@carlosgalvezp - could you also help commit this if it looks good?

Sure thing, thanks for the fix!

This revision was automatically updated to reflect the committed changes.