diff options
author | George Burgess IV <gbiv@google.com> | 2019-01-16 11:35:22 -0800 |
---|---|---|
committer | chrome-bot <chrome-bot@chromium.org> | 2019-01-17 12:18:22 -0800 |
commit | 56620aa44e75db5710896fedcf53b4ea51606612 (patch) | |
tree | 1d0031537b42401e8d1db78575945d2332b8dc00 /toolchain_utils_githooks | |
parent | 85214faa489ff59c3ffefd6cbf084acb0fb34900 (diff) | |
download | toolchain-utils-56620aa44e75db5710896fedcf53b4ea51606612.tar.gz |
git-hooks: swap to `[[`; fix style nits
Per the comment in I101c4c8b142f0c8f78819779adcfd0b3b0e1d614, `[[` is
preferable to `test` where possible. Swap to that for consistency.
(`[[` isn't an actual command, so we have to stick to `test` in
status_to_tf)
BUG=chromium:918755
TEST=check-style on a handful of Python files
Change-Id: Ic2256fadc570a5d3818918e49de45d641a21574a
Reviewed-on: https://chromium-review.googlesource.com/1415683
Commit-Ready: George Burgess <gbiv@chromium.org>
Tested-by: George Burgess <gbiv@chromium.org>
Reviewed-by: Mike Frysinger <vapier@chromium.org>
Diffstat (limited to 'toolchain_utils_githooks')
-rwxr-xr-x | toolchain_utils_githooks/check-format | 12 | ||||
-rwxr-xr-x | toolchain_utils_githooks/check-style | 6 |
2 files changed, 9 insertions, 9 deletions
diff --git a/toolchain_utils_githooks/check-format b/toolchain_utils_githooks/check-format index 3868c338..fc256671 100755 --- a/toolchain_utils_githooks/check-format +++ b/toolchain_utils_githooks/check-format @@ -10,7 +10,7 @@ # FIXME: It would be nice if YAPF supported tweaking quotes: # https://github.com/google/yapf/issues/399 -if test $# -eq 0; then +if [[ $# -eq 0 ]]; then echo "No files were given to check the format of." >&2 echo "Usage: $0 file1 file2 ..." >&2 exit 1 @@ -39,7 +39,7 @@ check_python_file_header() { local needs_hashbang=$(status_to_tf test -x "${py_file}") local has_hashbang=$(status_to_tf grep -q '^#!' <(head -n1 "${py_file}")) - if test "${needs_hashbang}" = "${has_hashbang}"; then + if [[ "${needs_hashbang}" == "${has_hashbang}" ]]; then return 0 fi @@ -58,7 +58,7 @@ python_files=() for f in "$@"; do [[ "${f}" == *.py ]] || continue - if ! test -e "${f}"; then + if [[ ! -e "${f}" ]]; then if "${complain_about_missing}"; then echo "error: no such file: ${f}" >&2 everything_passed=false @@ -74,7 +74,7 @@ for f in "$@"; do done bad_files=() -if test "${#python_files[@]}" -ne 0; then +if [[ "${#python_files[@]}" -ne 0 ]]; then # yapf will give us a full unified (git-like) diff. We parse out the file # names, e.g., # @@ -93,10 +93,10 @@ if test "${#python_files[@]}" -ne 0; then ) fi -if test "${#bad_files[@]}" -ne 0; then +if [[ "${#bad_files[@]}" -ne 0 ]]; then echo "One or more files appear to be incorrectly formatted." echo "Please run \`${yapf} -i ${bad_files[@]}\` to rectify this." everything_passed=false fi -$everything_passed +"${everything_passed}" diff --git a/toolchain_utils_githooks/check-style b/toolchain_utils_githooks/check-style index dbc38a71..7178ad49 100755 --- a/toolchain_utils_githooks/check-style +++ b/toolchain_utils_githooks/check-style @@ -6,7 +6,7 @@ # Convenient wrapper to run format and lint checks in parallel without # interleaving output/etc. -if test $# -eq 0; then +if [[ $# -eq 0 ]]; then echo "No files were given to check the format of." >&2 echo "Usage: $0 file1 file2 ..." >&2 exit 1 @@ -37,8 +37,8 @@ pid="$!" wait "${pid}" || success=false lint_output="$(cat "${tempfile}")" -if ! test -z "${lint_output}"; then +if [[ -n "${lint_output}" ]]; then echo "${lint_output}" fi -$success +"${success}" |