From d3de8fe500c736aa92aa87c9cd8b83fa4f44b7d8 Mon Sep 17 00:00:00 2001 From: Gaƫtan Gilbert Date: Tue, 24 Oct 2017 14:41:36 +0200 Subject: Linter: check that files end with newlines. We use git check-attr to look at the same files as git diff --check. --- dev/lint-repository.sh | 28 ++++++++++++++++++++++++++++ dev/tools/check-eof-newline.sh | 9 +++++++++ dev/tools/should-check-whitespace.sh | 5 +++++ 3 files changed, 42 insertions(+) create mode 100755 dev/lint-repository.sh create mode 100755 dev/tools/check-eof-newline.sh create mode 100755 dev/tools/should-check-whitespace.sh (limited to 'dev') diff --git a/dev/lint-repository.sh b/dev/lint-repository.sh new file mode 100755 index 0000000000..ecf7880e20 --- /dev/null +++ b/dev/lint-repository.sh @@ -0,0 +1,28 @@ +#!/usr/bin/env bash + +# A script to check prettyness over the repository. + +# lint-commits.sh seeks to prevent the worsening of already present +# problems, such as tab indentation in ml files. lint-repository.sh +# seeks to prevent the (re-)introduction of solved problems, such as +# newlines at the end of .v files. + +CODE=0 + +if [ "(" "-n" "${TRAVIS_PULL_REQUEST}" ")" "-a" "(" "${TRAVIS_PULL_REQUEST}" "!=" "false" ")" ]; +then + # Some problems are too widespread to fix in one commit, but we + # can still check that they don't worsen. + CUR_HEAD=${TRAVIS_COMMIT_RANGE%%...*} + PR_HEAD=${TRAVIS_COMMIT_RANGE##*...} + MERGE_BASE=$(git merge-base $CUR_HEAD $PR_HEAD) + dev/lint-commits.sh $MERGE_BASE $PR_HEAD || CODE=1 +fi + +# Check that the files with 'whitespace' gitattribute end in a newline. +# xargs exit status is 123 if any file failed the test +find . "(" -path ./.git -prune ")" -type f \ +-o "(" -exec dev/tools/should-check-whitespace.sh '{}' ';' ")" \ +-print0 | xargs -0 -L 1 dev/tools/check-eof-newline.sh || CODE=1 + +exit $CODE diff --git a/dev/tools/check-eof-newline.sh b/dev/tools/check-eof-newline.sh new file mode 100755 index 0000000000..1c578c05ce --- /dev/null +++ b/dev/tools/check-eof-newline.sh @@ -0,0 +1,9 @@ +#!/usr/bin/env bash + +if [ -z "$(tail -c 1 "$1")" ] +then + exit 0 +else + echo "No newline at end of file $1!" + exit 1 +fi diff --git a/dev/tools/should-check-whitespace.sh b/dev/tools/should-check-whitespace.sh new file mode 100755 index 0000000000..8159506b41 --- /dev/null +++ b/dev/tools/should-check-whitespace.sh @@ -0,0 +1,5 @@ +#!/usr/bin/env bash + +# determine if a file has whitespace checking enabled in .gitattributes + +git check-attr whitespace -- "$1" | grep -q -v 'unspecified$' -- cgit v1.2.3