This is a new attempt at #11005
Addressed nits, excluded imported dependencies, squashed the original commits, and added a test for tab characters in the *.cpp *.h *.md *.py *.sh files too as per @practicalswift suggestion
This is a new attempt at #11005
Addressed nits, excluded imported dependencies, squashed the original commits, and added a test for tab characters in the *.cpp *.h *.md *.py *.sh files too as per @practicalswift suggestion
utACK 258094ae4bdb17a1f2063b9f85955f41945e4611
Fixed a mis-copied comment in the tab character check which was referring to whitespace again
52 | + RET=1 53 | +fi 54 | + 55 | +# Check if tab characters were found in the diff. 56 | +if showcodediff | grep -P -q '^\+.*\t'; then 57 | + echo "This diff appears to have added new lines with tab characters not spaces."
This doesn't sound like correct English to me (but I'm not a native speaker myself). Use "instead of spaces" perhaps?
Yeah, I don't think it's technically wrong but it doesn't sound quite right, yours sounds better. Fixed.
45 | @@ -46,6 +46,7 @@ install: 46 | before_script: 47 | - if [ "$CHECK_DOC" = 1 -a "$TRAVIS_EVENT_TYPE" = "pull_request" ]; then contrib/devtools/commit-script-check.sh $TRAVIS_COMMIT_RANGE; fi 48 | - if [ "$CHECK_DOC" = 1 ]; then contrib/devtools/check-doc.py; fi 49 | + - if [ "$CHECK_DOC" = 1 ]; then contrib/devtools/lint-all.sh; fi
This needs to be guarded by TRAVIS_COMMIT_RANGE if you fail on -z $TRAVIS_COMMIT_RANGE, no?
I'm not even sure if I should have changed it to fail, should it just exit quietly if there's no commit range?
Actually this should be fine, as TRAVIS_COMMIT_RANGE should never be empty according to the travis doc. (It is only empty for branches with a single commit, which we don't have)
I can't manage to run the script. Am I calling it wrong?
TRAVIS_COMMIT_RANGE=50fae68d416b4b8ec4ca192923dfd5ae9ea42773...b3d6fc654770e3b4d2f82e8d77e531df9e522982 ./contrib/devtools/lint-all.sh
fatal: There is nothing to exclude from by :(exclude) patterns.
Perhaps you forgot to add either ':/' or '.' ?
I got the commit range from https://travis-ci.org/bitcoin/bitcoin/jobs/272143045
I get the same if I run
TRAVIS_COMMIT_RANGE=50fae68d416b4b8ec4ca192923dfd5ae9ea42773...b3d6fc654770e3b4d2f82e8d77e531df9e522982 git diff -U0 "${TRAVIS_COMMIT_RANGE}" -- ":(exclude)src/leveldb/" ":(exclude)src/secp256k1/" ":(exclude)src/univalue/"
This works:
TRAVIS_COMMIT_RANGE=50fae68d416b4b8ec4ca192923dfd5ae9ea42773...b3d6fc654770e3b4d2f82e8d77e531df9e522982 git diff -U0 "${TRAVIS_COMMIT_RANGE}"
@mess110 my guess is that you have a different version of git which doesn't assume all files to be included if only excludes are given, but I've updated the commit to (hopefully) fix it for you
Thanks, that was it indeed.
ACK https://github.com/bitcoin/bitcoin/pull/11300/commits/b8c0cfae6d6f39fe38dcfec229f3824a5af44b29
utACK b8c0cfae6d6f39fe38dcfec229f3824a5af44b29
utACK b8c0cfae6d6f39fe38dcfec229f3824a5af44b29
6 | +# 7 | +# Check for new lines in diff that introduce trailing whitespace. 8 | + 9 | +# We can't run this check unless we know the commit range for the PR. 10 | +if [ -z "${TRAVIS_COMMIT_RANGE}" ]; then 11 | + echo "Cannot run lint-whitespace.sh without commit range"
Perhaps add help text here explaining how to run locally:
echo "To run locally, use:"
echo "TRAVIS_COMMIT_RANGE='<commit range>' .lint-whitespace.sh"
echo "eg:"
echo "TRAVIS_COMMIT_RANGE='47ba2c3...ee50c9e' .lint-whitespace.sh"
Tested ACK. I've tested locally that both checks work, and that the src/leveldb/ exclusion also works.
It'd be helpful to also print out the @@ line showing the line number where the whitespace was introduced. Something like:
diff --git a/contrib/devtools/lint-whitespace.sh b/contrib/devtools/lint-whitespace.sh
index 5bea86a..8a065fe 100755
--- a/contrib/devtools/lint-whitespace.sh
+++ b/contrib/devtools/lint-whitespace.sh
@@ -40,0 +41,2 @@ if showdiff | grep -E -q '^\+.*\s+$'; then
+ elif [[ "$line" =~ ^@@ ]]; then
+ LINENUMBER="$line"
@@ -46,0 +49 @@ if showdiff | grep -E -q '^\+.*\s+$'; then
+ echo "$LINENUMBER"
@@ -51 +54 @@ if showdiff | grep -E -q '^\+.*\s+$'; then
- done < <(showdiff | grep -E '^(diff --git |\+.*\s+$)')
+ done < <(showdiff | grep -E '^(diff --git |@@|\+.*\s+$)')
@@ -64,0 +68,2 @@ if showcodediff | grep -P -q '^\+.*\t'; then
+ elif [[ "$line" =~ ^@@ ]]; then
+ LINENUMBER="$line"
@@ -70,0 +76 @@ if showcodediff | grep -P -q '^\+.*\t'; then
+ echo "$LINENUMBER"
@@ -75 +81 @@ if showcodediff | grep -P -q '^\+.*\t'; then
- done < <(showcodediff | grep -P '^(diff --git |\+.*\t)')
+ done < <(showcodediff | grep -P '^(diff --git |@@|\+.*\t)')
should do it. This only prints out the line number for the first match in each file, but I think that's ok.
This adds a new CHECK_DOC check that looks for newly introduced trailing
whitespace. Existing trailing whitespace (of which there is plenty!)
will not trigger an error.
This is written in a generic way so that new lint-*.sh scripts can be
added to contrib/devtools/, as I'd like to contribute additional lint
checks in the future.
Rebased on master to fix merge conflict and addressed @jnewbery's comments, thanks!
re-utACK 1f379b1