Changeset View
Changeset View
Standalone View
Standalone View
test/lint/check-doc.py
Show All 24 Lines | |||||
REGEX_DOC = r'AddArg\(\s*"(-[^"=]+?)(?:=|")' | REGEX_DOC = r'AddArg\(\s*"(-[^"=]+?)(?:=|")' | ||||
# list false positive unknows arguments | # list false positive unknows arguments | ||||
SET_FALSE_POSITIVE_UNKNOWNS = set(['-zmqpubhashblock', | SET_FALSE_POSITIVE_UNKNOWNS = set(['-zmqpubhashblock', | ||||
'-zmqpubhashtx', | '-zmqpubhashtx', | ||||
'-zmqpubrawblock', | '-zmqpubrawblock', | ||||
'-zmqpubrawtx']) | '-zmqpubrawtx']) | ||||
# list false positive undocumented arguments | |||||
SET_FALSE_POSITIVE_UNDOCUMENTED = set(['-benchmark', | |||||
'-blockminsize', | |||||
'-dbcrashratio', | |||||
'-debugnet', | |||||
'-forcecompactdb', | |||||
'-parkdeepreorg', | |||||
# Remove after May 2020 upgrade | |||||
'-phononactivationtime', | |||||
'-replayprotectionactivationtime', | |||||
'-rpcssl', | |||||
'-socks', | |||||
'-tor', | |||||
'-usehd', | |||||
'-whitelistalwaysrelay']) | |||||
def main(): | def main(): | ||||
top_level = check_output(TOP_LEVEL, shell=True, | top_level = check_output(TOP_LEVEL, shell=True, | ||||
universal_newlines=True).strip() | universal_newlines=True).strip() | ||||
source_files = [] | source_files = [] | ||||
test_files = [] | test_files = [] | ||||
for extension in EXTENSIONS: | for extension in EXTENSIONS: | ||||
source_files += glob.glob(top_level + | source_files += glob.glob(top_level + | ||||
FOLDER_SRC + extension, recursive=True) | FOLDER_SRC + extension, recursive=True) | ||||
test_files += glob.glob(top_level + FOLDER_TEST + | test_files += glob.glob(top_level + FOLDER_TEST + | ||||
extension, recursive=True) | extension, recursive=True) | ||||
files = set(source_files) - set(test_files) | files = set(source_files) - set(test_files) | ||||
args_used = set() | args_used = set() | ||||
args_docd = set() | args_docd = set() | ||||
for file in files: | for file in files: | ||||
with open(file, 'r', encoding='utf-8') as f: | with open(file, 'r', encoding='utf-8') as f: | ||||
content = f.read() | content = f.read() | ||||
args_used |= set(re.findall(re.compile(REGEX_ARG), content)) | args_used |= set(re.findall(re.compile(REGEX_ARG), content)) | ||||
args_docd |= set(re.findall(re.compile(REGEX_DOC), content)) | args_docd |= set(re.findall(re.compile(REGEX_DOC), content)) | ||||
args_used |= SET_FALSE_POSITIVE_UNKNOWNS | args_used |= SET_FALSE_POSITIVE_UNKNOWNS | ||||
args_docd |= SET_FALSE_POSITIVE_UNDOCUMENTED | |||||
args_need_doc = args_used - args_docd | args_need_doc = args_used - args_docd | ||||
args_unknown = args_docd - args_used | args_unknown = args_docd - args_used | ||||
pp = PrettyPrinter() | pp = PrettyPrinter() | ||||
print("Args used : {}".format(len(args_used))) | print("Args used : {}".format(len(args_used))) | ||||
print("Args documented : {}".format(len(args_docd))) | print("Args documented : {}".format(len(args_docd))) | ||||
print("Args undocumented: {}".format(len(args_need_doc))) | print("Args undocumented: {}".format(len(args_need_doc))) | ||||
pp.pprint(args_need_doc) | pp.pprint(args_need_doc) | ||||
print("Args unknown : {}".format(len(args_unknown))) | print("Args unknown : {}".format(len(args_unknown))) | ||||
pp.pprint(args_unknown) | pp.pprint(args_unknown) | ||||
if __name__ == "__main__": | if __name__ == "__main__": | ||||
main() | main() |