Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
Skyward Boardcore
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
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
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
Nicolò Caruso
Skyward Boardcore
Commits
2eb84d9e
Commit
2eb84d9e
authored
2 years ago
by
Alberto Nidasio
Browse files
Options
Downloads
Patches
Plain Diff
[SBS][Linter] Updated cppcheck and copyright output
parent
47b91f10
No related branches found
No related tags found
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
sbs
+70
-70
70 additions, 70 deletions
sbs
scripts/linter.py
+46
-48
46 additions, 48 deletions
scripts/linter.py
with
116 additions
and
118 deletions
sbs
+
70
−
70
View file @
2eb84d9e
...
@@ -277,9 +277,9 @@ lint_cppcheck() {
...
@@ -277,9 +277,9 @@ lint_cppcheck() {
declare
-a
opts
=()
declare
-a
opts
=()
[
-n
"
$jobs
"
]
&&
opts+
=(
"-j
$jobs
"
)
[
-n
"
$jobs
"
]
&&
opts+
=(
"-j
$jobs
"
)
cppcheck
--language
=
c++
--std
=
c++1
1
--enable
=
all
--inline-suppr
\
cppcheck
--language
=
c++
--std
=
c++1
4
--enable
=
all
--inline-suppr
\
--suppress
=
unmatchedSuppression
--suppress
=
unusedFunction
\
--suppress
=
unmatchedSuppression
--suppress
=
unusedFunction
\
--suppress
=
missingInclude
--error-exitcode
=
1
"
${
opts
[@]
}
"
\
--suppress
=
missingInclude
--error-exitcode
=
1
-q
"
${
opts
[@]
}
"
\
"
$source_dir
/src"
"
$source_dir
/src"
}
}
...
...
This diff is collapsed.
Click to expand it.
scripts/linter.py
+
46
−
48
View file @
2eb84d9e
...
@@ -92,10 +92,6 @@ def print_banner():
...
@@ -92,10 +92,6 @@ def print_banner():
print
(
'
+------------------------------+
'
)
print
(
'
+------------------------------+
'
)
def
linter_print
(
*
strings
):
print
(
'
[linter]
'
,
*
strings
)
class
Colors
():
class
Colors
():
BLACK
=
'
\033
[30m
'
BLACK
=
'
\033
[30m
'
RED
=
'
\033
[31m
'
RED
=
'
\033
[31m
'
...
@@ -111,7 +107,7 @@ class Colors():
...
@@ -111,7 +107,7 @@ class Colors():
# Checks for the right copyright notice in all .h and .cpp files
# Checks for the right copyright notice in all .h and .cpp files
def
check_copyright
(
directory
):
def
check_copyright
(
directory
):
linter_
print
(
Colors
.
GREEN
+
'
Copyright check
'
+
Colors
.
RESET
)
print
(
Colors
.
GREEN
+
'
Copyright check
'
+
Colors
.
RESET
)
# Statistics
# Statistics
totalCheckdFilesCounter
=
0
totalCheckdFilesCounter
=
0
...
@@ -134,7 +130,7 @@ def check_copyright(directory):
...
@@ -134,7 +130,7 @@ def check_copyright(directory):
filesWithErrorsCounter
+=
1
filesWithErrorsCounter
+=
1
# The file's copyright notice does not match the template!
# The file's copyright notice does not match the template!
linter_
print
(
Colors
.
YELLOW
+
'
Wrong copyright notice in file {0}
'
.
format
(
print
(
Colors
.
YELLOW
+
'
Wrong copyright notice in file {0}
'
.
format
(
currentFilepath
)
+
Colors
.
RESET
)
currentFilepath
)
+
Colors
.
RESET
)
else
:
else
:
fileAuthors
=
[
a
.
strip
()
fileAuthors
=
[
a
.
strip
()
...
@@ -142,10 +138,10 @@ def check_copyright(directory):
...
@@ -142,10 +138,10 @@ def check_copyright(directory):
# Check the number of authors against 'Author' or `Authors`
# Check the number of authors against 'Author' or `Authors`
if
len
(
fileAuthors
)
==
1
and
match
.
group
(
1
)[
-
1
]
==
'
s
'
:
if
len
(
fileAuthors
)
==
1
and
match
.
group
(
1
)[
-
1
]
==
'
s
'
:
linter_
print
(
'
\'
Authors
\'
should to be changed to
\'
Author
\'
in {0}
'
.
format
(
print
(
'
\'
Authors
\'
should to be changed to
\'
Author
\'
in {0}
'
.
format
(
currentFilepath
))
currentFilepath
))
if
len
(
fileAuthors
)
>
1
and
match
.
group
(
1
)[
-
1
]
!=
'
s
'
:
if
len
(
fileAuthors
)
>
1
and
match
.
group
(
1
)[
-
1
]
!=
'
s
'
:
linter_
print
(
'
\'
Author
\'
should to be changed to
\'
Authors
\'
in {0}
'
.
format
(
print
(
'
\'
Author
\'
should to be changed to
\'
Authors
\'
in {0}
'
.
format
(
currentFilepath
))
currentFilepath
))
# Save statistics on authors
# Save statistics on authors
...
@@ -157,19 +153,20 @@ def check_copyright(directory):
...
@@ -157,19 +153,20 @@ def check_copyright(directory):
averageAuthorsPerFile
+=
len
(
fileAuthors
)
averageAuthorsPerFile
+=
len
(
fileAuthors
)
averageAuthorsPerFile
/=
totalCheckdFilesCounter
averageAuthorsPerFile
/=
totalCheckdFilesCounter
linter_
print
(
'
Checked {} files
'
.
format
(
totalCheckdFilesCounter
))
print
(
'
Checked {} files
'
.
format
(
totalCheckdFilesCounter
))
if
filesWithErrorsCounter
==
0
:
if
filesWithErrorsCounter
==
0
:
linter_
print
(
'
All the files have the correct copyright notice
'
)
print
(
'
All the files have the correct copyright notice
'
)
else
:
else
:
linter_
print
(
Colors
.
RED
+
'
{:.1f}% ({}/{}) of all analyzed files do not match with the copyright template!
'
.
format
(
print
(
Colors
.
RED
+
'
{:.1f}% ({}/{}) of all analyzed files do not match with the copyright template!
'
.
format
(
100
*
filesWithErrorsCounter
/
totalCheckdFilesCounter
,
filesWithErrorsCounter
,
totalCheckdFilesCounter
)
+
Colors
.
RESET
)
100
*
filesWithErrorsCounter
/
totalCheckdFilesCounter
,
filesWithErrorsCounter
,
totalCheckdFilesCounter
)
+
Colors
.
RESET
)
if
(
not
args
.
quiet
):
if
(
not
args
.
quiet
):
linter_
print
(
'
{:.2} authors per file
'
.
format
(
print
(
'
{:.2} authors per file
'
.
format
(
averageAuthorsPerFile
))
averageAuthorsPerFile
))
linter_print
(
'
Number of mentions per author:
'
)
for
author
in
authors
:
print
(
'
Number of mentions per author:
'
)
linter_print
(
'
{:3} - {}
'
.
format
(
authors
[
author
],
author
))
for
author
in
sorted
(
authors
.
items
(),
key
=
lambda
item
:
item
[
1
],
reverse
=
True
):
print
(
'
{:3} - {}
'
.
format
(
author
[
1
],
author
[
0
]))
# Exit if error if at least one file isn't correct
# Exit if error if at least one file isn't correct
if
(
filesWithErrorsCounter
>
0
):
if
(
filesWithErrorsCounter
>
0
):
...
@@ -178,7 +175,7 @@ def check_copyright(directory):
...
@@ -178,7 +175,7 @@ def check_copyright(directory):
# Checks if all .h and .cpp files respects the clang format specified in .clang-format file
# Checks if all .h and .cpp files respects the clang format specified in .clang-format file
def
check_format
(
directory
):
def
check_format
(
directory
):
linter_
print
(
Colors
.
GREEN
+
'
Formatting check
'
+
Colors
.
RESET
)
print
(
Colors
.
GREEN
+
'
Formatting check
'
+
Colors
.
RESET
)
# Statistics
# Statistics
totalCheckdFilesCounter
=
0
totalCheckdFilesCounter
=
0
...
@@ -201,14 +198,14 @@ def check_format(directory):
...
@@ -201,14 +198,14 @@ def check_format(directory):
filesWithErrorsCounter
+=
1
filesWithErrorsCounter
+=
1
if
(
not
args
.
quiet
):
if
(
not
args
.
quiet
):
linter_
print
(
Colors
.
YELLOW
+
'
Wrong code format for file {1}
'
.
format
(
print
(
Colors
.
YELLOW
+
'
Wrong code format for file {1}
'
.
format
(
returnCode
,
currentFilepath
)
+
Colors
.
RESET
)
returnCode
,
currentFilepath
)
+
Colors
.
RESET
)
linter_
print
(
'
Checked {} files
'
.
format
(
totalCheckdFilesCounter
))
print
(
'
Checked {} files
'
.
format
(
totalCheckdFilesCounter
))
if
filesWithErrorsCounter
==
0
:
if
filesWithErrorsCounter
==
0
:
linter_
print
(
'
All the files match the Skyward formatting style
'
)
print
(
'
All the files match the Skyward formatting style
'
)
else
:
else
:
linter_
print
(
Colors
.
RED
+
'
{:4.1f}% ({}/{}) of all analyzed files do not match Skyward formatting style!
'
.
format
(
print
(
Colors
.
RED
+
'
{:4.1f}% ({}/{}) of all analyzed files do not match Skyward formatting style!
'
.
format
(
100
*
filesWithErrorsCounter
/
totalCheckdFilesCounter
,
filesWithErrorsCounter
,
totalCheckdFilesCounter
),
Colors
.
RESET
)
100
*
filesWithErrorsCounter
/
totalCheckdFilesCounter
,
filesWithErrorsCounter
,
totalCheckdFilesCounter
),
Colors
.
RESET
)
# Exit if error if at least one file isn't correct
# Exit if error if at least one file isn't correct
...
@@ -217,7 +214,7 @@ def check_format(directory):
...
@@ -217,7 +214,7 @@ def check_format(directory):
def
find_in_code
(
directory
,
searchTerm
,
extensionFilters
=
(
'
.cpp
'
,
'
.h
'
),
pathFilter
=
None
):
def
find_in_code
(
directory
,
searchTerm
,
extensionFilters
=
(
'
.cpp
'
,
'
.h
'
),
pathFilter
=
None
):
linter_
print
(
print
(
Colors
.
GREEN
+
'
Checking for
\'
{}
\'
in code files
'
.
format
(
searchTerm
)
+
Colors
.
RESET
)
Colors
.
GREEN
+
'
Checking for
\'
{}
\'
in code files
'
.
format
(
searchTerm
)
+
Colors
.
RESET
)
# Statistics
# Statistics
...
@@ -244,15 +241,15 @@ def find_in_code(directory, searchTerm, extensionFilters=('.cpp', '.h'), pathFil
...
@@ -244,15 +241,15 @@ def find_in_code(directory, searchTerm, extensionFilters=('.cpp', '.h'), pathFil
# The current file has the error
# The current file has the error
if
(
not
args
.
quiet
):
if
(
not
args
.
quiet
):
linter_
print
(
Colors
.
YELLOW
+
'
Found
\'
{}
\'
in file {}
'
.
format
(
searchTerm
,
print
(
Colors
.
YELLOW
+
'
Found
\'
{}
\'
in file {}
'
.
format
(
searchTerm
,
currentFilepath
)
+
Colors
.
RESET
)
currentFilepath
)
+
Colors
.
RESET
)
linter_
print
(
'
Checked {} files
'
.
format
(
totalCheckdFilesCounter
))
print
(
'
Checked {} files
'
.
format
(
totalCheckdFilesCounter
))
if
filesWithErrorsCounter
==
0
:
if
filesWithErrorsCounter
==
0
:
linter_
print
(
print
(
'
All the files does not contain
\'
{}
\'
'
.
format
(
searchTerm
))
'
All the files does not contain
\'
{}
\'
'
.
format
(
searchTerm
))
else
:
else
:
linter_
print
(
Colors
.
RED
+
'
{:.1f}% ({}/{}) of all analyzed files contain
\'
{}
\'
!
'
.
format
(
print
(
Colors
.
RED
+
'
{:.1f}% ({}/{}) of all analyzed files contain
\'
{}
\'
!
'
.
format
(
100
*
filesWithErrorsCounter
/
totalCheckdFilesCounter
,
filesWithErrorsCounter
,
totalCheckdFilesCounter
,
searchTerm
)
+
Colors
.
RESET
)
100
*
filesWithErrorsCounter
/
totalCheckdFilesCounter
,
filesWithErrorsCounter
,
totalCheckdFilesCounter
,
searchTerm
)
+
Colors
.
RESET
)
return
filesWithErrorsCounter
return
filesWithErrorsCounter
...
@@ -260,7 +257,8 @@ def find_in_code(directory, searchTerm, extensionFilters=('.cpp', '.h'), pathFil
...
@@ -260,7 +257,8 @@ def find_in_code(directory, searchTerm, extensionFilters=('.cpp', '.h'), pathFil
def
check_find
(
directory
):
def
check_find
(
directory
):
sum
=
find_in_code
(
directory
,
r
'
^using namespace
'
,
'
.h
'
)
sum
=
find_in_code
(
directory
,
r
'
^using namespace
'
,
'
.h
'
)
sum
+=
find_in_code
(
directory
,
r
'
[^a-zA-Z0-9]printf\(
'
,
pathFilter
=
'
shared
'
)
sum
+=
find_in_code
(
directory
,
r
'
[^a-zA-Z0-9]printf\(
'
,
pathFilter
=
'
shared
'
)
sum
+=
find_in_code
(
directory
,
r
'
( |^)assert\(
'
)
sum
+=
find_in_code
(
directory
,
r
'
( |^)assert\(
'
)
sum
+=
find_in_code
(
directory
,
'
^ *throw
'
,
pathFilter
=
'
catch
'
)
sum
+=
find_in_code
(
directory
,
'
^ *throw
'
,
pathFilter
=
'
catch
'
)
...
@@ -269,7 +267,7 @@ def check_find(directory):
...
@@ -269,7 +267,7 @@ def check_find(directory):
def
check_cppcheck
(
directory
):
def
check_cppcheck
(
directory
):
linter_
print
(
Colors
.
GREEN
+
'
cppcheck
'
+
Colors
.
RESET
)
print
(
Colors
.
GREEN
+
'
cppcheck
'
+
Colors
.
RESET
)
# Run cppcheck on the directory
# Run cppcheck on the directory
try
:
try
:
result
=
check_output
([
'
cppcheck
'
,
'
-q
'
,
'
--language=c++
'
,
'
--template=gcc
'
,
'
--std=c++11
'
,
'
--enable=all
'
,
'
--inline-suppr
'
,
result
=
check_output
([
'
cppcheck
'
,
'
-q
'
,
'
--language=c++
'
,
'
--template=gcc
'
,
'
--std=c++11
'
,
'
--enable=all
'
,
'
--inline-suppr
'
,
...
@@ -281,20 +279,20 @@ def check_cppcheck(directory):
...
@@ -281,20 +279,20 @@ def check_cppcheck(directory):
errors
=
Counter
(
errors
)
errors
=
Counter
(
errors
)
if
(
not
args
.
quiet
):
if
(
not
args
.
quiet
):
linter_
print
(
'
cppcheck found the following errors:
'
)
print
(
'
cppcheck found the following errors:
'
)
for
error
in
errors
:
for
error
in
errors
:
linter_
print
(
'
{:3} - {}
'
.
format
(
errors
[
error
],
error
))
print
(
'
{:3} - {}
'
.
format
(
errors
[
error
],
error
))
totalErrors
=
sum
(
errors
.
values
())
totalErrors
=
sum
(
errors
.
values
())
if
(
totalErrors
>
0
):
if
(
totalErrors
>
0
):
linter_
print
(
print
(
Colors
.
RED
+
'
cppcheck found {} errors in total
'
.
format
(
totalErrors
)
+
Colors
.
RESET
)
Colors
.
RED
+
'
cppcheck found {} errors in total
'
.
format
(
totalErrors
)
+
Colors
.
RESET
)
exit
(
-
1
)
exit
(
-
1
)
else
:
else
:
linter_
print
(
'
cppcheck did not find any errors
'
)
print
(
'
cppcheck did not find any errors
'
)
except
CalledProcessError
as
e
:
except
CalledProcessError
as
e
:
linter_
print
(
e
.
output
.
decode
(
'
utf-8
'
))
print
(
e
.
output
.
decode
(
'
utf-8
'
))
exit
(
-
1
)
exit
(
-
1
)
# -------------------------------------------------------------
# -------------------------------------------------------------
...
@@ -306,7 +304,7 @@ parser = config_cmd_parser()
...
@@ -306,7 +304,7 @@ parser = config_cmd_parser()
args
=
parser
.
parse_args
()
args
=
parser
.
parse_args
()
if
(
not
args
.
directory
):
if
(
not
args
.
directory
):
linter_
print
(
'
No directory specified
'
)
print
(
'
No directory specified
'
)
print
(
''
)
print
(
''
)
parser
.
print_help
()
parser
.
print_help
()
exit
(
-
1
)
exit
(
-
1
)
...
...
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