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
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
blender
blender-dev-tools
Commits
8c724253
Commit
8c724253
authored
11 years ago
by
Campbell Barton
Browse files
Options
Downloads
Patches
Plain Diff
Add checks for indentation within a multiline if/while/switch statements body
also check for whitespace around '?' and ':'
parent
53fb01d1
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
check_source/check_style_c.py
+72
-7
72 additions, 7 deletions
check_source/check_style_c.py
with
72 additions
and
7 deletions
check_source/check_style_c.py
+
72
−
7
View file @
8c724253
...
@@ -343,14 +343,79 @@ def blender_check_kw_if(index_kw_start, index_kw, index_kw_end):
...
@@ -343,14 +343,79 @@ def blender_check_kw_if(index_kw_start, index_kw, index_kw_end):
else
:
else
:
# no '{' on a multi-line if
# no '{' on a multi-line if
if
tokens
[
index_kw
].
line
!=
tokens
[
index_kw_end
].
line
:
if
tokens
[
index_kw
].
line
!=
tokens
[
index_kw_end
].
line
:
warning
(
"
multi-line if should use a brace
'
%s (
\\
n
\\
n) statement;
'"
%
tokens
[
index_kw
].
text
,
index_kw
,
index_kw_end
)
# double check this is not...
# if (a &&
# check for: if (a &&
# b); <--
# b) { ...
#
# brace should be on a newline.
# While possible but not common for 'if' statements, its used in this example:
#
# do {
# foo;
# } while(a &&
# b);
#
if
not
(
tokens
[
index_next
].
type
==
Token
.
Punctuation
and
tokens
[
index_next
].
text
==
"
;
"
):
warning
(
"
multi-line if should use a brace
'
%s (
\\
n
\\
n) statement;
'"
%
tokens
[
index_kw
].
text
,
index_kw
,
index_kw_end
)
# multi-line statement
if
(
tokens
[
index_kw
].
line
!=
tokens
[
index_kw_end
].
line
):
if
(
tokens
[
index_kw
].
line
!=
tokens
[
index_kw_end
].
line
):
# check for: if (a &&
# b) { ...
# brace should be on a newline.
#
if
tokens
[
index_kw_end
].
line
==
tokens
[
index_next
].
line
:
if
tokens
[
index_kw_end
].
line
==
tokens
[
index_next
].
line
:
warning
(
"
multi-line should use a on a new line
'
%s (
\\
n
\\
n) {
'"
%
tokens
[
index_kw
].
text
,
index_kw
,
index_kw_end
)
if
not
(
tokens
[
index_next
].
type
==
Token
.
Punctuation
and
tokens
[
index_next
].
text
==
"
;
"
):
warning
(
"
multi-line should use a on a new line
'
%s (
\\
n
\\
n) {
'"
%
tokens
[
index_kw
].
text
,
index_kw
,
index_kw_end
)
# Note: this could be split into its own function
# since its not spesific to if-statements,
# can also work for function calls.
#
# check indentation on a multi-line statement:
# if (a &&
# b)
# {
#
# should be:
# if (a &&
# b)
# {
# Skip the first token
# Extract ' if (' then convert to
# ' ' and check lines for correct indent.
index_kw_bracket
=
tk_advance_ws_newline
(
index_kw
,
1
)
ws_indent
=
extract_to_linestart
(
index_kw_bracket
+
1
)
ws_indent
=
""
.
join
([(
"
\t
"
if
c
==
"
\t
"
else
"
"
)
for
c
in
ws_indent
])
l_last
=
tokens
[
index_kw
].
line
for
i
in
range
(
index_kw
+
1
,
index_kw_end
+
1
):
if
tokens
[
i
].
line
!=
l_last
:
l_last
=
tokens
[
i
].
line
# ignore blank lines
if
tokens
[
i
].
text
==
"
\n
"
:
pass
elif
tokens
[
i
].
text
.
startswith
(
"
#
"
):
pass
else
:
# check indentation is good
# use startswith because there are function calls within 'if' checks sometimes.
ws_indent_test
=
extract_to_linestart
(
i
+
1
)
# print("intend testA: %r %s" % (ws_indent_test, tokens[i].text))
#if ws_indent_test != ws_indent:
if
ws_indent_test
.
startswith
(
ws_indent
):
pass
elif
tokens
[
i
].
text
.
startswith
(
ws_indent
):
# needed for some comments
pass
else
:
warning
(
"
TEST123 if body brace mult-line indent mismatch
"
,
i
,
i
)
del
index_kw_bracket
del
ws_indent
del
l_last
# check for: if () { ... };
# check for: if () { ... };
#
#
...
@@ -601,7 +666,7 @@ def blender_check_operator(index_start, index_end, op_text, is_cpp):
...
@@ -601,7 +666,7 @@ def blender_check_operator(index_start, index_end, op_text, is_cpp):
# warning("no space after operator '%s'" % op_text, index_start, index_end)
# warning("no space after operator '%s'" % op_text, index_start, index_end)
pass
pass
elif
op_text
in
{
"
/
"
,
"
%
"
,
"
^
"
,
"
|
"
,
"
=
"
,
"
<
"
,
"
>
"
}:
elif
op_text
in
{
"
/
"
,
"
%
"
,
"
^
"
,
"
|
"
,
"
=
"
,
"
<
"
,
"
>
"
,
"
?
"
,
"
:
"
}:
if
not
_is_ws_pad
(
index_start
,
index_end
):
if
not
_is_ws_pad
(
index_start
,
index_end
):
if
not
(
is_cpp
and
(
"
<
"
in
op_text
or
"
>
"
in
op_text
)):
if
not
(
is_cpp
and
(
"
<
"
in
op_text
or
"
>
"
in
op_text
)):
warning
(
"
no space around operator
'
%s
'"
%
op_text
,
index_start
,
index_end
)
warning
(
"
no space around operator
'
%s
'"
%
op_text
,
index_start
,
index_end
)
...
...
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