Skip to content

Commit

Permalink
Add fmt/lint for trailing spaces
Browse files Browse the repository at this point in the history
  • Loading branch information
cartermckinnon committed Oct 18, 2023
1 parent 14fb76d commit 4e0d150
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 0 deletions.
2 changes: 2 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ endif
.PHONY: fmt
fmt: ## Format the source files
$(SHFMT_COMMAND) $(SHFMT_FLAGS) --write $(MAKEFILE_DIR)
hack/fmt-trailing-spaces.sh

SHELLCHECK_COMMAND := $(shell which shellcheck)
ifeq (, $(SHELLCHECK_COMMAND))
Expand All @@ -96,6 +97,7 @@ transform-al2-to-al2023:
lint: lint-docs ## Check the source files for syntax and format issues
$(SHFMT_COMMAND) $(SHFMT_FLAGS) --diff $(MAKEFILE_DIR)
$(SHELLCHECK_COMMAND) --format gcc --severity error $(SHELL_FILES)
hack/lint-trailing-spaces.sh

.PHONY: test
test: ## run the test-harness
Expand Down
25 changes: 25 additions & 0 deletions hack/fmt-trailing-spaces.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#!/usr/bin/env bash

set -o errexit
set -o nounset
set -o pipefail

cd $(dirname $0)/..

OS=$(uname)
for FILE in $(find . -type f -not -path "*/.git/*"); do
if git check-ignore --quiet "$FILE"; then
continue
fi
echo >&2 "$FILE"
if [ "$OS" = "Darwin" ]; then
# macOS sed doesn't support '-i'
sed 's/[[:space:]]*$//g' "$FILE" > "$FILE.tmp"
# macOS chmod doesn't support '--reference'
chmod "$(stat -f "%Mp%Lp" $FILE)" "$FILE.tmp"
mv "$FILE.tmp" "$FILE"
else
# assume we have a sane sed
sed -i 's/[[:space:]]*$//g' "$FILE"
fi
done
4 changes: 4 additions & 0 deletions hack/lint-trailing-spaces.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/usr/bin/env bash

cd $(dirname $0)/..
git diff-tree --check $(git hash-object -t tree /dev/null) HEAD

0 comments on commit 4e0d150

Please sign in to comment.