diff --git a/tools/utils_maintenance/code_clean.py b/tools/utils_maintenance/code_clean.py index 13a90e31631..c744f35f47b 100755 --- a/tools/utils_maintenance/code_clean.py +++ b/tools/utils_maintenance/code_clean.py @@ -569,6 +569,32 @@ class edit_generators: return edits + class use_empty_void_arg(EditGenerator): + """ + Use ``()`` instead of ``(void)`` for C++ code. + + Replace: + function(void) {} + With: + function() {} + """ + @staticmethod + def edit_list_from_file(source: str, data: str, _shared_edit_data: Any) -> List[Edit]: + edits: List[Edit] = [] + + # The user might include C & C++, if they forget, it is better not to operate on C. + if source.lower().endswith((".h", ".c")): + return edits + + # `(void)` -> `()`. + for match in re.finditer(r"(\(void\))(\s*{)", data, flags=re.MULTILINE): + edits.append(Edit( + span=match.span(), + content="()" + match.group(2), + content_fail="(__ALWAYS_FAIL__) {", + )) + return edits + class unused_arg_as_comment(EditGenerator): """ Replace `UNUSED(argument)` in C++ code.