mirror of
https://github.com/blender/blender-dev-tools.git
synced 2025-08-13 14:02:48 +00:00
code_clean: add 'use_nullptr' edit operation
Also correct doc-string for use_brief_types.
This commit is contained in:
@ -496,7 +496,7 @@ class edit_generators:
|
||||
|
||||
class use_brief_types(EditGenerator):
|
||||
"""
|
||||
Use zero before the float suffix.
|
||||
Use less verbose unsigned types.
|
||||
|
||||
Replace:
|
||||
unsigned int
|
||||
@ -526,6 +526,42 @@ class edit_generators:
|
||||
|
||||
return edits
|
||||
|
||||
class use_nullptr(EditGenerator):
|
||||
"""
|
||||
Use ``nullptr`` instead of ``NULL`` for C++ code.
|
||||
|
||||
Replace:
|
||||
NULL
|
||||
With:
|
||||
nullptr
|
||||
"""
|
||||
@staticmethod
|
||||
def edit_list_from_file(source: str, data: str, _shared_edit_data: Any) -> List[Edit]:
|
||||
edits = []
|
||||
|
||||
# The user might exclude C++, if they forget, it is better not to operate on C.
|
||||
if not source.lower().endswith((".h", ".c")):
|
||||
return edits
|
||||
|
||||
# `NULL` -> `nullptr`.
|
||||
for match in re.finditer(r"\bNULL\b", data):
|
||||
edits.append(Edit(
|
||||
span=match.span(),
|
||||
content='nullptr',
|
||||
content_fail='__ALWAYS_FAIL__',
|
||||
))
|
||||
|
||||
# There may be some remaining uses of `unsigned` without any integer type afterwards.
|
||||
# `unsigned` -> `uint`.
|
||||
for match in re.finditer(r"\bunsigned\b", data):
|
||||
edits.append(Edit(
|
||||
span=match.span(),
|
||||
content='uint',
|
||||
content_fail='__ALWAYS_FAIL__',
|
||||
))
|
||||
|
||||
return edits
|
||||
|
||||
class unused_arg_as_comment(EditGenerator):
|
||||
"""
|
||||
Replace `UNUSED(argument)` in C++ code.
|
||||
|
Reference in New Issue
Block a user