/
lint.sh
executable file
·80 lines (74 loc) · 2.15 KB
/
lint.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
#!/bin/bash
#
# Run Google's cpplint over the codebase and convert convert the output from
# Google's cpplint.py to the cppcheck XML format for consumption by the Jenkins
# cppcheck plugin.
#
# The given arguments are the src root and the reports directory e.g.:
# ./lint.sh --root . --reports reports/cpplint.xml
while [[ $# -gt 1 ]]
do
key="$1"
case $key in
-r|--root)
root="$2"
shift # past argument
;;
-e|--reports)
reports="$2"
shift # past argument
;;
-d|--dir)
dir="$2"
shift # past argument
;;
*)
# unknown option
;;
esac
shift # past argument or value
done
linter="$(cd "$(dirname "${BASH_SOURCE[0]}" )" && pwd)"
# Change to source directory.
cd "$root"
# Get all files for the style check and exclude external files and run
# cpplint and convert the output.
find "$dir" \
! -path "*/src/mlpack/core/arma_extend/*" \
! -path "*/src/mlpack/core/boost_backport/*" \
! -path "*src/mlpack/bindings/matlab/*" \
! -path "*src/mlpack/core/core.hpp" \
! -path "*src/mlpack/core/util/arma_config_check.hpp" \
! -path "*src/mlpack/methods/ann/visitor/*" \
! -path "*src/mlpack/prereqs.hpp" \
! -path "*src/mlpack/core.hpp" \
! -path "*src/mlpack/tests/catch.hpp" \
! -path "*src/mlpack/bindings/cli/third_party/CLI/CLI11.hpp" \
! -path "*src/mlpack/bindings/R/mlpack/src/boost/*" \
! -path "*src/mlpack/core/cereal/pair_associative_container.hpp" \
! -path "*tests/catch.hpp" \
-print0 -iname '*.[hc]pp' -type f | \
xargs -0 python "$linter"/cpplint.py --extensions=hpp,cpp --filter=\
-whitespace/braces,\
-whitespace/newline,\
-build/header_guard,\
-build/include_order,\
-build/storage_class,\
-build/namespaces,\
-build/include_what_you_use,\
-legal/copyright,\
-readability/casting,\
-readability/alt_tokens,\
-readability/todo,\
-readability/multiline_string,\
-runtime/explicit,\
-runtime/int,\
-runtime/string,\
-runtime/references 2>&1 | \
grep -v 'Missing spaces around <' | \
grep -v 'Consider using rand_r' | \
grep -v 'Consider using CHECK_EQ instead of CHECK(a == b)' | \
grep -v 'Consider using CHECK_LE instead of CHECK(a <= b)' | \
python3 "$linter"/cpplint_cppcheckxml.py 2> "$reports"
# Restore directory.
cd "$cwd"