This patch:
* Checks the `version` variable assignment directly to avoid relying on
`$?`, therefore removing the `shellcheck disable` comment.
* Makes `formatter` an array to satisfy SC2086, therefore removing the
`shellcheck disable` comment.
* Quotes `$(nproc)` to satisfy SC2068.
Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com>
Change-Id: Ib7c5fe530faad12704ee8b91ae55a6bfcb1aee5c
Reviewed-on: https://review.lttng.org/c/babeltrace/+/11142
Reviewed-by: Simon Marchi <simon.marchi@efficios.com>
Reviewed-by: Michael Jeanson <mjeanson@efficios.com>
# Runs the formatter, making sure it's the expected version.
format_cpp() {
# Runs the formatter, making sure it's the expected version.
format_cpp() {
- version=$($formatter --version)
-
- # shellcheck disable=SC2181
- if (($? != 0)); then
- echo "Cannot execute \`$formatter --version\`." >&2
+ if ! version=$("${formatter[@]}" --version); then
+ echo "Cannot execute \`${formatter[*]} --version\`." >&2
# Using xargs to fail as soon as the formatter fails (`-exec`
# won't stop if its subprocess fails).
# Using xargs to fail as soon as the formatter fails (`-exec`
# won't stop if its subprocess fails).
- #
- # shellcheck disable=SC2086
find "$root_dir" \( -name '*.cpp' -o -name '*.hpp' \) \
! -wholename '*/cpp-common/optional.hpp' \
! -wholename '*/cpp-common/string_view.hpp' \
! -wholename '*/cpp-common/nlohmann/json.hpp' \
find "$root_dir" \( -name '*.cpp' -o -name '*.hpp' \) \
! -wholename '*/cpp-common/optional.hpp' \
! -wholename '*/cpp-common/string_view.hpp' \
! -wholename '*/cpp-common/nlohmann/json.hpp' \
- -print0 | xargs -P$(nproc) -n1 -0 $formatter
+ -print0 | xargs -P"$(nproc)" -n1 -0 "${formatter[@]}"
}
if [[ -n "$FORMATTER" ]]; then
# Try using environment-provided formatter
}
if [[ -n "$FORMATTER" ]]; then
# Try using environment-provided formatter
+ read -ra formatter <<< "$FORMATTER"
elif command -v clang-format-$expected_formatter_major_version &> /dev/null; then
# Try using the expected version of clang-format
elif command -v clang-format-$expected_formatter_major_version &> /dev/null; then
# Try using the expected version of clang-format
- formatter="clang-format-$expected_formatter_major_version -i"
+ formatter=("clang-format-$expected_formatter_major_version" -i)
else
# Try using `clang-format` as is
else
# Try using `clang-format` as is
- formatter='clang-format -i'
+ formatter=(clang-format -i)
+format_cpp "${formatter[@]}"