Commit 150b302c authored by Emilia Haligowska's avatar Emilia Haligowska Committed by Tomasz Zawadzki
Browse files

scripts: switch from go fmt to gofmt



Neither "go fmt" nor "gofmt" return a status code when the format check
fails. We can only rely on their stdout. "go fmt" invokes "gofmt -w -l"
on every file in the target package and pulls in dependencies. These
dependencies are not verified, but they pollute stdout and increase
format check time.

Therefore, we switch to "gofmt", which only checks files within the
target package.

It turns out that not all files from the target package were checked.
Compare "go fmt -n ." to "go fmt -n ./...". Switching to "gofmt ."
addresses this issue, and we've added fixes to client.go accordingly.

Finally, instead of fixing the formatting, we print out the diff by
switching from "-w" to "-d".

Change-Id: Ifb1c339bdd1703c7d9e1b0cfa0b0ad0df7cff683
Signed-off-by: default avatarEmilia Haligowska <emilia.haligowska@intel.com>
Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/22832


Tested-by: default avatarSPDK CI Jenkins <sys_sgci@intel.com>
Reviewed-by: default avatarTomasz Zawadzki <tomasz.zawadzki@intel.com>
Reviewed-by: default avatarKonrad Sztyber <konrad.sztyber@intel.com>
Community-CI: Mellanox Build Bot
parent 79f76d9f
Loading
Loading
Loading
Loading
+11 −3
Original line number Diff line number Diff line
@@ -499,11 +499,19 @@ function check_golang_style() {

	if hash golangci-lint 2> /dev/null; then
		echo -n "Checking Golang style..."
		out=$(find "$rootdir/go" -name go.mod -execdir go fmt \; -execdir golangci-lint run \; 2>&1)
		if [[ -n "$out" ]]; then
		gofmtOut=$(gofmt -d . 2>&1)
		golintOut=$(find "$rootdir/go" -name go.mod -execdir golangci-lint run \; 2>&1)
		if [[ -n "$gofmtOut" ]] && [[ $gofmtOut == *"diff"* ]]; then
			cat <<- WARN
				Golang formatting errors detected:
				echo "$out"
				echo "$gofmtOut"
			WARN

			return 1
		elif [[ -n "$golintOut" ]]; then
			cat <<- WARN
				Golangci lint failed:
				echo "$golintOut"
			WARN

			return 1
+2 −2

File changed.

Contains only whitespace changes.

+4 −4

File changed.

Contains only whitespace changes.