Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
B
blender-dev-tools
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
blender
blender-dev-tools
Commits
6bef8953
Commit
6bef8953
authored
Oct 11, 2022
by
Campbell Barton
Browse files
Options
Downloads
Patches
Plain Diff
code_clean: add unused_arg_as_comment edit generator
parent
d35b4ed0
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
utils_maintenance/code_clean.py
+39
-0
39 additions, 0 deletions
utils_maintenance/code_clean.py
with
39 additions
and
0 deletions
utils_maintenance/code_clean.py
+
39
−
0
View file @
6bef8953
...
@@ -526,6 +526,45 @@ class edit_generators:
...
@@ -526,6 +526,45 @@ class edit_generators:
return
edits
return
edits
class
unused_arg_as_comment
(
EditGenerator
):
"""
Replace `UNUSED(argument)` in C++ code.
Replace:
void function(int UNUSED(arg)) {...}
With:
void function(int /*arg*/) {...}
"""
@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
# `UNUSED(arg)` -> `/*arg*/`.
for
match
in
re
.
finditer
(
r
"
\b(UNUSED)
"
# # Opening parenthesis.
r
"
\(
"
# Capture the identifier as group 1.
r
"
([
"
+
""
.
join
(
list
(
IDENTIFIER_CHARS
))
+
"
]+)
"
# # Capture any non-identifier characters as group 2.
# (e.g. `[3]`) which need to be added outside the comment.
r
"
([^\)]*)
"
# Closing parenthesis of `UNUSED(..)`.
r
"
\)
"
,
data
,
):
edits
.
append
(
Edit
(
span
=
match
.
span
(),
content
=
'
/*%s*/%s
'
%
(
match
.
group
(
2
),
match
.
group
(
3
)),
content_fail
=
'
__ALWAYS_FAIL__(%s%s)
'
%
(
match
.
group
(
2
),
match
.
group
(
3
)),
))
return
edits
class
use_elem_macro
(
EditGenerator
):
class
use_elem_macro
(
EditGenerator
):
"""
"""
Use the `ELEM` macro for more abbreviated expressions.
Use the `ELEM` macro for more abbreviated expressions.
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment