diff options
author | Gaëtan Gilbert <gaetan.gilbert@skyskimmer.net> | 2017-10-24 14:41:36 +0200 |
---|---|---|
committer | Gaëtan Gilbert <gaetan.gilbert@skyskimmer.net> | 2017-10-25 13:42:37 +0200 |
commit | d3de8fe500c736aa92aa87c9cd8b83fa4f44b7d8 (patch) | |
tree | d85956c39c66544d284da0d17ce70ab972c933c9 /dev | |
parent | 4c954a3479e002d3a350c3094ae73e6ca5865202 (diff) |
Linter: check that files end with newlines.
We use git check-attr to look at the same files as git diff --check.
Diffstat (limited to 'dev')
-rwxr-xr-x | dev/lint-repository.sh | 28 | ||||
-rwxr-xr-x | dev/tools/check-eof-newline.sh | 9 | ||||
-rwxr-xr-x | dev/tools/should-check-whitespace.sh | 5 |
3 files changed, 42 insertions, 0 deletions
diff --git a/dev/lint-repository.sh b/dev/lint-repository.sh new file mode 100755 index 000000000..ecf7880e2 --- /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 000000000..1c578c05c --- /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 000000000..8159506b4 --- /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$' |