Skip to content

Commit

Permalink
Merge pull request #498 from alphagov/enforce_posix_newline
Browse files Browse the repository at this point in the history
Add make target to find textfiles with missing trailing newlines
  • Loading branch information
saliceti committed Sep 27, 2016
2 parents b96e352 + 88df1d3 commit 4bf15f5
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
6 changes: 5 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ check-env-vars:
check-tf-version:
@./terraform/scripts/ensure_terraform_version.sh $(MIN_TERRAFORM_VERSION)

test: spec lint_yaml lint_terraform lint_shellcheck lint_concourse lint_ruby ## Run linting tests
test: spec lint_yaml lint_terraform lint_shellcheck lint_concourse lint_ruby lint_posix_newlines ## Run linting tests

spec:
cd scripts &&\
Expand Down Expand Up @@ -59,6 +59,10 @@ lint_concourse:
lint_ruby:
bundle exec govuk-lint-ruby

.PHONY: lint_posix_newlines
lint_posix_newlines:
git ls-files | grep -v vendor/ | xargs ./scripts/test_posix_newline.sh

GPG = $(shell command -v gpg2 || command -v gpg)

.PHONY: list_merge_keys
Expand Down
22 changes: 22 additions & 0 deletions scripts/test_posix_newline.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#!/bin/sh
RET_CODE=0

test_posix_newline() {
if [ ! -r "$1" ]; then
echo "File $1 not found or not readable" 1>&2
RET_CODE=1
fi
if grep -Iq . "$1" ; then
final_char=$(tail -q -c 1 "$1")
if [ "${final_char}" != "" ]; then
echo "$1 has not POSIX trailing new line" 1>&2
RET_CODE=1
fi
fi
}

set -e
for i in "$@"; do
test_posix_newline "$i"
done
exit $RET_CODE

0 comments on commit 4bf15f5

Please sign in to comment.