![]() This works by defining two 'static' lists in hack. The first is the list of all flags in the project which use a `-` or an `_` in their name. All files being processed by verify-flags-underscore.py (or all files in the repo if no filename arguments are given) will be searched for flag declaration using a simple regex. Its not super smart. If a flag is found which is not in the static list it will complain/reject the commit until a human adds it to the list. If we do not keep a static list of flags it takes >.2 seconds to find them 'all' at runtime. Since this is run in pre-commit saving every part of a second helps. After it finds all of the flags it runs all of the arguments (or all files in repo if no arguments) looking for usage of those flags which includes an `_`. There are lots of places where these are false positives. For example we have a flag named oom-adj-score but the kernel calls it oom_adj_score. To handle this we keep a second 'whitelist' of lines which are allowed to use these flag names with an `_`. Running the entire git repo looking for flags in every golang file and looking in every single file for bad usage takes about 8.75 seconds. Running it in the precommit hook where we only check things that changed takes about .06 seconds. |
||
---|---|---|
.. | ||
pre-commit |