From 376a5acc24426896a62fcd3406fccf061b54ae9f Mon Sep 17 00:00:00 2001 From: Maximilian Brune Date: Tue, 8 Apr 2025 14:59:30 +0200 Subject: [PATCH] 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 Change-Id: I9c75fc0bf20a2625ddae43b0472a6586ae78f213 Reviewed-on: https://review.coreboot.org/c/coreboot/+/87211 Tested-by: build bot (Jenkins) Reviewed-by: Maxim Polyakov --- util/lint/lint-stable-031-gofmt | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100755 util/lint/lint-stable-031-gofmt diff --git a/util/lint/lint-stable-031-gofmt b/util/lint/lint-stable-031-gofmt new file mode 100755 index 0000000000..f22d39ae34 --- /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