-
Notifications
You must be signed in to change notification settings - Fork 1.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
addons/namingng.py: Improve file name checking feature. #5802
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it's not very obvious to me what basename does.. can you give an example why you want to match both source_file and basename?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Certainly, there are multiple use cases. For clarity: the original code attempted to distill the basename from the dump filename (by removing the
.dump
suffix) and only tested that. With this patch the code tests filenames of all files, also including header files. Both the basename and the full path (source_file
) are tested, which gives some added flexibility.On my system I get file naming violations on system includes, such as
/...../gcc-arm-none-eabi-10.3-2021.10/arm-none-eabi/include/sys/_sigset.h
that don't follow my rules because the basename starts with_
. Of course I can make a suppression for it, but a different approach is to make a pattern that matches and accepts such filenames. In the example this is any absolute path ("/.*\\.[ch]\\Z"
) but it may also be based on a particular path (".*arm-none-eabi/include"
).Another use case is where under a particular path a different convention is followed. Again from own experience, when developing for embedded systems we get a lot of boilerplate, e.g. CMSIS and the STM32 HAL, that we don't necessarily want to completely ignore or rename. So we can make a few different rules, such as
"Drivers/CMSIS/<insert regexp>"
,"Drivers/STM32[^/]*/<insert regexp>"
, etc.Yet another use case is that this allows to validate the naming and structure of directories as well, e.g. by having all
RE_FILE
rules prefixed, like"[A-Z][a-z]*/[a-z][a-z0-9_]*[a-z0-9]\\.[ch]\\Z"
which would allow "Core/file_1.c" but not "tmp/hack.c" or "Core/tmp/quickfix.c" or "HEADERS/hdr.h".Of course there are various other ways to solve such cases, where different paths need different rules, or where a different tool should validate directory naming and structure, but as we're validating the filename of all files, it seemed natural to (ab)use
RE_FILE
for this.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ps. I will add a unit test, but that depends on the namingng CLI patch going through first.