Skip to content

Commit 98c2288

Browse files
committed
Add cxxdt-cxx-lint
1 parent 57af5a7 commit 98c2288

File tree

4 files changed

+140
-1
lines changed

4 files changed

+140
-1
lines changed

clang/README.md

Whitespace-only changes.

clang/bin/cxxdt-cxx-lint

Lines changed: 136 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,136 @@
1+
#!/bin/bash
2+
#
3+
# CXX linter provided by cxx-dev-tools
4+
#
5+
# ARG_POSITIONAL_INF([cxx-files],[CXX files to lint (default: read CXX files from PWD/.cxxdt-cxx-lint)],[])
6+
# ARG_HELP([CXX linter provided by cxx-dev-tools])
7+
# ARGBASH_GO()
8+
# needed because of Argbash --> m4_ignore([
9+
### START OF CODE GENERATED BY Argbash v2.8.1 one line above ###
10+
# Argbash is a bash code generator used to get arguments parsing right.
11+
# Argbash is FREE SOFTWARE, see https://argbash.io for more info
12+
# Generated online by https://argbash.io/generate
13+
14+
15+
die()
16+
{
17+
local _ret=$2
18+
test -n "$_ret" || _ret=1
19+
test "$_PRINT_HELP" = yes && print_help >&2
20+
echo "$1" >&2
21+
exit ${_ret}
22+
}
23+
24+
25+
begins_with_short_option()
26+
{
27+
local first_option all_short_options='h'
28+
first_option="${1:0:1}"
29+
test "$all_short_options" = "${all_short_options/$first_option/}" && return 1 || return 0
30+
}
31+
32+
# THE DEFAULTS INITIALIZATION - POSITIONALS
33+
_positionals=()
34+
_arg_cxx_files=()
35+
# THE DEFAULTS INITIALIZATION - OPTIONALS
36+
37+
38+
print_help()
39+
{
40+
printf '%s\n' "CXX linter provided by cxx-dev-tools"
41+
printf 'Usage: %s [-h|--help] [<cxx-files-1>] ... [<cxx-files-n>] ...\n' "$0"
42+
printf '\t%s\n' "<cxx-files>: CXX files to lint (default: read CXX files from PWD/.cxxdt-cxx-lint)"
43+
printf '\t%s\n' "-h, --help: Prints help"
44+
}
45+
46+
47+
parse_commandline()
48+
{
49+
_positionals_count=0
50+
while test $# -gt 0
51+
do
52+
_key="$1"
53+
case "$_key" in
54+
-h|--help)
55+
print_help
56+
exit 0
57+
;;
58+
-h*)
59+
print_help
60+
exit 0
61+
;;
62+
*)
63+
_last_positional="$1"
64+
_positionals+=("$_last_positional")
65+
_positionals_count=$((_positionals_count + 1))
66+
;;
67+
esac
68+
shift
69+
done
70+
}
71+
72+
73+
assign_positional_args()
74+
{
75+
local _positional_name _shift_for=$1
76+
_positional_names=""
77+
_our_args=$((${#_positionals[@]} - 0))
78+
for ((ii = 0; ii < _our_args; ii++))
79+
do
80+
_positional_names="$_positional_names _arg_cxx_files[$((ii + 0))]"
81+
done
82+
83+
shift "$_shift_for"
84+
for _positional_name in ${_positional_names}
85+
do
86+
test $# -gt 0 || break
87+
eval "$_positional_name=\${1}" || die "Error during argument parsing, possibly an Argbash bug." 1
88+
shift
89+
done
90+
}
91+
92+
parse_commandline "$@"
93+
assign_positional_args 1 "${_positionals[@]}"
94+
95+
# OTHER STUFF GENERATED BY Argbash
96+
97+
### END OF CODE GENERATED BY Argbash (sortof) ### ])
98+
# [ <-- needed because of Argbash
99+
100+
cxxdt_cxx_lint_config_file=$PWD/.cxxdt-cxx-lint
101+
cxxdt_cxx_lint_files=("${_arg_cxx_files[@]}")
102+
clang_format_config=()
103+
104+
read_cxx_files_from_file()
105+
{
106+
while IFS= read -r line || [[ "$line" ]]; do
107+
cxxdt_cxx_lint_files+=("$line")
108+
done < $cxxdt_cxx_lint_config_file
109+
}
110+
111+
read_clang_format_config()
112+
{
113+
while IFS= read -r line || [[ "$line" ]]; do
114+
clang_format_config+=("$line")
115+
done < $CXX_DEV_TOOLS_PATH/clang/config/.clang-format
116+
}
117+
118+
if [ "${#cxxdt_cxx_lint_files[@]}" -eq 0 ]; then
119+
if [ ! -f "$cxxdt_cxx_lint_config_file" ]; then
120+
echo "ERROR: Specify CXX files in the command line or in $cxxdt_cxx_lint_config_file"
121+
exit 1
122+
fi
123+
124+
read_cxx_files_from_file
125+
fi
126+
127+
read_clang_format_config
128+
129+
# Convert the config array to JSON string
130+
printf -v clang_format_config_str '%s,' "${clang_format_config[@]}"
131+
clang_format_config_str="{ ${clang_format_config_str%,} }"
132+
133+
# Compare actual files to what clang-format outputs to stdout
134+
diff -u <(cat ${cxxdt_cxx_lint_files}) <(clang-format --style="${clang_format_config_str}" ${cxxdt_cxx_lint_files})
135+
136+
# ] <-- needed because of Argbash

clang/config/.clang-format

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
BasedOnStyle: Google
2+
IndentWidth: 4
3+
AccessModifierOffset: -2

export.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ function cxx_dev_tools_export_main() {
4040
fi
4141

4242
CXX_DEV_TOOLS_ADD_PATHS_EXTRAS="${CXX_DEV_TOOLS_PATH}/cmake/bin"
43-
CXX_DEV_TOOLS_ADD_PATHS_EXTRAS="${CXX_DEV_TOOLS_ADD_PATHS_EXTRAS}:${CXX_DEV_TOOLS_PATH}/clang/format"
43+
CXX_DEV_TOOLS_ADD_PATHS_EXTRAS="${CXX_DEV_TOOLS_ADD_PATHS_EXTRAS}:${CXX_DEV_TOOLS_PATH}/clang/bin"
4444
export PATH="${CXX_DEV_TOOLS_ADD_PATHS_EXTRAS}:${PATH}"
4545

4646
unset CXX_DEV_TOOLS_ADD_PATHS_EXTRAS

0 commit comments

Comments
 (0)