Maximilian Brune has uploaded this change for review. ( https://review.coreboot.org/c/coreboot/+/87211?usp=email )
Change subject: util/lint: Add lint file for gofmt ......................................................................
util/lint: Add lint file for gofmt
Add a linter file to check the formatting of our go files. For now only intelp2m utiliy is checked.
Signed-off-by: Maximilian Brune maximilian.brune@9elements.com Change-Id: I9c75fc0bf20a2625ddae43b0472a6586ae78f213 --- A util/lint/lint-stable-031-gofmt 1 file changed, 33 insertions(+), 0 deletions(-)
git pull ssh://review.coreboot.org:29418/coreboot refs/changes/11/87211/1
diff --git a/util/lint/lint-stable-031-gofmt b/util/lint/lint-stable-031-gofmt new file mode 100755 index 0000000..f22d39a --- /dev/null +++ b/util/lint/lint-stable-031-gofmt @@ -0,0 +1,33 @@ +#!/usr/bin/env sh +# +# SPDX-License-Identifier: GPL-2.0-only + +# DESCR: Run gofmt on util/intelp2m + +LINTDIR="$( + cd -- "$(dirname "$0")" > /dev/null 2>&1 || return + pwd -P +)" + +# shellcheck source=helper_functions.sh +. "${LINTDIR}/helper_functions.sh" + +# Until we require this by default, we need a list of opted-in directories +# If the script isn't looking at a git repository, just exit +if [ "${IN_GIT_TREE}" -eq 0 ]; then + exit 0 +fi + +files_to_check=$(${GIT} log HEAD~..HEAD --format= --name-only util/intelp2m | grep ".go$") + +# nothing to do +if [ -z "$files_to_check" ]; then + exit 0 +fi + +diff_files=$(gofmt -l $files_to_check) +if [ "$diff_files" != "" ]; then + echo "Coding style mismatch. Run "gofmt -w $files_to_check" before pushing changes" + exit 1 +fi +exit 0