From 4eb0f3bb8aecdb954dc3cd268f9ae07ea0e10053 Mon Sep 17 00:00:00 2001 From: "Joshua M. Boniface" Date: Sat, 6 Nov 2021 03:10:17 -0400 Subject: [PATCH] Unify formatting and linting Ensures optimal formatting in addition to linting during manual deploys and during pre-commit actions. --- .hooks/pre-commit | 6 ++---- build-and-deploy.sh | 6 +++--- format | 1 + lint | 1 + prepare | 6 ++++++ 5 files changed, 13 insertions(+), 7 deletions(-) create mode 100755 prepare diff --git a/.hooks/pre-commit b/.hooks/pre-commit index 1b29eb25..bc88cea8 100755 --- a/.hooks/pre-commit +++ b/.hooks/pre-commit @@ -4,11 +4,9 @@ pushd $( git rev-parse --show-toplevel ) &>/dev/null ex=0 -# Linting -echo "Linting..." -./lint +./prepare if [[ $? -ne 0 ]]; then - echo "Aborting commit due to linting errors." + echo "Aborting commit due to formatting or linting errors." ex=1 fi diff --git a/build-and-deploy.sh b/build-and-deploy.sh index 5899ffc9..82524886 100755 --- a/build-and-deploy.sh +++ b/build-and-deploy.sh @@ -27,9 +27,9 @@ fi HOSTS=( ${@} ) echo "> Deploying to host(s): ${HOSTS[@]}" -# Lint to prevent deploying bad code -echo -n "Linting code for errors... " -./lint || exit +# Prepare code +echo "Preparing code (format and lint)..." +./prepare || exit # Build the packages echo -n "Building packages... " diff --git a/format b/format index bd79789e..a5304949 100755 --- a/format +++ b/format @@ -5,6 +5,7 @@ if ! which black &>/dev/null; then exit 1 fi +echo "Formatting..." black --safe --exclude api-daemon/migrations . ret=$? if [[ $ret -eq 0 ]]; then diff --git a/lint b/lint index 929c085c..4369364a 100755 --- a/lint +++ b/lint @@ -5,6 +5,7 @@ if ! which flake8 &>/dev/null; then exit 1 fi +echo "Linting..." flake8 ret=$? if [[ $ret -eq 0 ]]; then diff --git a/prepare b/prepare new file mode 100755 index 00000000..20f628d2 --- /dev/null +++ b/prepare @@ -0,0 +1,6 @@ +#!/usr/bin/env bash + +#set -o errexit + +./format +./lint