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 Reviewed-on: https://review.coreboot.org/c/coreboot/+/87211 Tested-by: build bot (Jenkins) <no-reply@coreboot.org> Reviewed-by: Maxim Polyakov <max.senia.poliak@gmail.com>
This commit is contained in:
parent
4456c125f6
commit
376a5acc24
1 changed files with 33 additions and 0 deletions
33
util/lint/lint-stable-031-gofmt
Executable file
33
util/lint/lint-stable-031-gofmt
Executable file
|
|
@ -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
|
||||
Loading…
Add table
Add a link
Reference in a new issue