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
8b6faeba
Commit
8b6faeba
authored
10 years ago
by
Campbell Barton
Browse files
Options
Downloads
Patches
Plain Diff
Add check for single line indentation
parent
308e4c22
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
+35
-1
35 additions, 1 deletion
check_source/check_style_c.py
with
35 additions
and
1 deletion
check_source/check_style_c.py
+
35
−
1
View file @
8b6faeba
...
@@ -214,6 +214,12 @@ def extract_to_linestart(index):
...
@@ -214,6 +214,12 @@ def extract_to_linestart(index):
return
""
.
join
(
ls
)
return
""
.
join
(
ls
)
def
extract_ws_indent
(
index
):
# could optimize this
text
=
extract_to_linestart
(
index
)
return
text
[:
len
(
text
)
-
len
(
text
.
lstrip
(
"
\t
"
))]
def
extract_statement_if
(
index_kw
):
def
extract_statement_if
(
index_kw
):
# assert(tokens[index_kw].text == "if")
# assert(tokens[index_kw].text == "if")
...
@@ -383,6 +389,34 @@ def blender_check_kw_if(index_kw_start, index_kw, index_kw_end):
...
@@ -383,6 +389,34 @@ def blender_check_kw_if(index_kw_start, index_kw, index_kw_end):
warning
(
"
E109
"
,
"
multi-line if should use a brace
'
%s (
\\
n
\\
n) statement;
'"
%
warning
(
"
E109
"
,
"
multi-line if should use a brace
'
%s (
\\
n
\\
n) statement;
'"
%
tokens
[
index_kw
].
text
,
index_kw
,
index_kw_end
)
tokens
[
index_kw
].
text
,
index_kw
,
index_kw_end
)
# check for correct single line use & indentation
if
not
(
tokens
[
index_next
].
type
==
Token
.
Punctuation
and
tokens
[
index_next
].
text
==
"
;
"
):
if
tokens
[
index_next
].
type
==
Token
.
Keyword
and
tokens
[
index_next
].
text
in
{
"
if
"
,
"
while
"
,
"
for
"
}:
ws_kw
=
extract_ws_indent
(
index_kw
)
ws_end
=
extract_ws_indent
(
index_next
)
if
len
(
ws_kw
)
+
1
!=
len
(
ws_end
):
warning
(
"
E200
"
,
"
bad single line indent
'
%s (...) {
'"
%
tokens
[
index_kw
].
text
,
index_kw
,
index_next
)
del
ws_kw
,
ws_end
else
:
index_end
=
tk_advance_to_token
(
index_next
,
1
,
"
;
"
,
Token
.
Punctuation
)
if
tokens
[
index_kw
].
line
!=
tokens
[
index_end
].
line
:
# check for:
# if (a)
# b;
#
# should be:
#
# if (a)
# b;
ws_kw
=
extract_ws_indent
(
index_kw
)
ws_end
=
extract_ws_indent
(
index_end
)
if
len
(
ws_kw
)
+
1
!=
len
(
ws_end
):
warning
(
"
E201
"
,
"
bad single line indent
'
%s (...) {
'"
%
tokens
[
index_kw
].
text
,
index_kw
,
index_end
)
del
ws_kw
,
ws_end
del
index_end
# multi-line statement
# 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 &&
# check for: if (a &&
...
@@ -725,7 +759,7 @@ def blender_check_operator(index_start, index_end, op_text, is_cpp):
...
@@ -725,7 +759,7 @@ def blender_check_operator(index_start, index_end, op_text, is_cpp):
elif
op_text
==
"
&
"
:
elif
op_text
==
"
&
"
:
pass
# TODO, check if this is a pointer reference or not
pass
# TODO, check if this is a pointer reference or not
elif
op_text
==
"
*
"
:
elif
op_text
==
"
*
"
:
# This check could be improved, its a bit fuzzy
# This check could be improved, its a bit fuzzy
if
((
tokens
[
index_start
-
1
].
type
in
Token
.
Number
)
or
if
((
tokens
[
index_start
-
1
].
type
in
Token
.
Number
)
or
(
tokens
[
index_start
+
1
].
type
in
Token
.
Number
)):
(
tokens
[
index_start
+
1
].
type
in
Token
.
Number
)):
warning
(
"
E130
"
,
"
no space around operator
'
%s
'"
%
op_text
,
index_start
,
index_end
)
warning
(
"
E130
"
,
"
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