From 1b8a965105ad56a8145381d3622ee2a5a4b35eb4 Mon Sep 17 00:00:00 2001 From: Ian Howell Date: Tue, 7 Jan 2020 12:03:26 -0600 Subject: [PATCH] Add a simple whitespace linter The goimports tool does not check for trailing whitespaces in multiline strings. This commit adds a simple linter to address this deficiency. This change will also have the benefit of providing light linting of any non-go files. Change-Id: I253dd7c4895f476fa3a6f0c4fccf7c9cada16366 --- Makefile | 1 + tools/whitespace_linter | 11 +++++++++++ 2 files changed, 12 insertions(+) create mode 100755 tools/whitespace_linter diff --git a/Makefile b/Makefile index 44c90cdf8..ea2c9167f 100644 --- a/Makefile +++ b/Makefile @@ -80,6 +80,7 @@ fmt: lint lint: tidy lint: $(LINTER) @echo "Performing linting step..." + @./tools/whitespace_linter @./$(LINTER) run --config $(LINTER_CONFIG) @echo "Linting completed successfully" diff --git a/tools/whitespace_linter b/tools/whitespace_linter new file mode 100755 index 000000000..280cef5da --- /dev/null +++ b/tools/whitespace_linter @@ -0,0 +1,11 @@ +#!/usr/bin/env bash + +# git 1.9.0+ allows for exclusions in pathspecs via ':!foo' syntax. +# However, until git 2.13.0 there must be at least one "inclusive" pathspec, hence the './*' +trailing_whitespace=$(git grep -E -n -- ' +$' -- './*' ':!*.png') + +if [[ -n "$trailing_whitespace" ]]; then + printf "ERROR: Trailing whitespaces:\n" + awk 'BEGIN {FS=":"} {printf " * %s:%s\n", $1, $2}' <<< "$trailing_whitespace" + exit 1 +fi