code_clean: add use_empty_void_arg cleanup operation

Removes the use of (void) in C++ for functions with no arguments
This commit is contained in:
Campbell Barton 2023-07-02 19:37:20 +10:00
parent 345d1a4b44
commit feb83e66c6

@ -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.