Tests: Add a lint check for trailing whitespace #11005

pull eklitzke wants to merge 2 commits into bitcoin:master from eklitzke:whitespace changing 3 files +70 −0
  1. eklitzke commented at 1:38 AM on August 8, 2017: contributor

    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.

    Example of what a lint failure looks like in Travis: https://travis-ci.org/eklitzke/bitcoin/jobs/262052953

  2. Add a lint check for trailing whitespace.
    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.
    5b0295efe5
  3. fanquake added the label Tests on Aug 8, 2017
  4. in contrib/devtools/lint-whitespace.sh:15 in 5b0295efe5 outdated
      10 | +if [ -z "${TRAVIS_COMMIT_RANGE}" ]; then
      11 | +  exit 0
      12 | +fi
      13 | +
      14 | +showdiff() {
      15 | +  if ! git diff "${TRAVIS_COMMIT_RANGE}" --; then
    


    MarcoFalke commented at 9:04 AM on August 8, 2017:

    I assume you need to set the context lines to 0 to prevent false positives?

    -U0


    eklitzke commented at 9:26 PM on August 8, 2017:

    That doesn't hurt, although I think it's correct as is. Context lines are shown with a leading space when they have no changes, so a context line that starts with + will actually have a leading space. I'll make this change anyway for safety/clarity.

  5. MarcoFalke commented at 9:09 AM on August 8, 2017: member

    Concept ACK, as trailing white space causes issues with some editors that remove it automatically on save from the whole file, even from untouched lines.

  6. in contrib/devtools/lint-whitespace.sh:22 in 5b0295efe5 outdated
      17 | +    exit 1
      18 | +  fi
      19 | +}
      20 | +
      21 | +# Do a first pass, and if no trailing whitespace was found then exit early.
      22 | +if ! showdiff | egrep -q '^\+.*\s+$'; then
    


    practicalswift commented at 3:04 PM on August 8, 2017:

    Nit: Use grep -E instead of egrep which is deprecated :-)


    eklitzke commented at 9:28 PM on August 8, 2017:

    Serious nit, haha.

  7. in contrib/devtools/lint-whitespace.sh:46 in 5b0295efe5 outdated
      41 | +      echo "$FILENAME"
      42 | +      SEEN=1
      43 | +    fi
      44 | +    echo "$line"
      45 | +  fi
      46 | +done < <(showdiff | egrep '^(diff --git |\+.*\s+$)')
    


    practicalswift commented at 3:04 PM on August 8, 2017:

    Nit: Use grep -E instead of egrep which is deprecated :-)

  8. practicalswift commented at 3:05 PM on August 8, 2017: contributor

    Concept ACK

  9. fix nits d8a7add0a1
  10. eklitzke commented at 9:29 PM on August 8, 2017: contributor

    @MarcoFalke @practicalswift Thanks for the suggestions, I've made these changes.

  11. eklitzke commented at 9:44 PM on August 8, 2017: contributor

    If this is merged, I'll submit some whitespace-only PRs to clean up various files in the project (probably starting with markdown files, and then moving onto code if that goes well). I feel like it's not worth sending out any whitespace PRs though until this has landed, since otherwise there could be new regressions.

  12. eklitzke closed this on Aug 9, 2017

  13. eklitzke reopened this on Aug 9, 2017

  14. fanquake commented at 2:47 AM on August 9, 2017: member

    @eklitzke Whitespace only PRs aren't likely to be accepted. Basically they disrupt other work and patches, and create rebasing issues, without providing much value. See the first point in the dev notes. "Do not submit patches solely to modify the style of existing code."

    We also have clang-format rules that can be used against new/modified code, which should handle formatting.

  15. eklitzke commented at 2:59 AM on August 9, 2017: contributor

    @fanquake Noted. Although I did have problems with clang-format, since many of the existing files are not formatted properly, so running those files through clang-format caused needless code churn. In any event, this check will prevent the introduction of new trailing whitespace.

  16. kallewoof approved
  17. MarcoFalke commented at 11:43 AM on August 10, 2017: member
  18. practicalswift commented at 1:47 PM on August 10, 2017: contributor

    Can we ignore violations introduced in the directories of our imported dependencies?

    I'm thinking about:

    • src/leveldb/
    • src/secp256k1/
    • src/univalue/

    Also, what about adding a similar check for introductions of new \t:s in files with suffixes *.cpp, *.h, *.md, *.py and *.sh? Again excluding the imported dependencies.

  19. MarcoFalke commented at 10:23 AM on August 30, 2017: member

    @eklitzke Are you still working on this?

  20. in contrib/devtools/lint-whitespace.sh:11 in d8a7add0a1
       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 | +  exit 0
    


    ryanofsky commented at 2:56 PM on August 31, 2017:

    Why exit as if the check was successful instead of showing an error?

  21. ryanofsky commented at 2:56 PM on August 31, 2017: member

    utACK d8a7add0a1f31388eb1235ae11315f00dcf43be3 if the the right files / directories are excluded. It looks like git has a pathspec feature that let you easily exclude paths with :! syntax.

    Other things that could be done in future prs:

    • Incorporate the scripted diff check contrib/devtools/commit-script-check.sh into this linting framework instead of running it separately.
    • Make it possible to disable or pass options to the linter with directives in the commit message.
  22. MarcoFalke commented at 2:30 AM on September 10, 2017: member

    Closing due to inactivity. Please ping me to get this reopened.

    This is up for grab by other contributors.

  23. MarcoFalke closed this on Sep 10, 2017

  24. MarcoFalke referenced this in commit f4ed44ab4a on Sep 14, 2017
  25. PastaPastaPasta referenced this in commit ef10797760 on Sep 24, 2019
  26. PastaPastaPasta referenced this in commit d57d950bc7 on Dec 21, 2019
  27. PastaPastaPasta referenced this in commit cb5408a218 on Jan 2, 2020
  28. PastaPastaPasta referenced this in commit cba81aa8bd on Jan 4, 2020
  29. PastaPastaPasta referenced this in commit a01d3fc7b4 on Jan 4, 2020
  30. PastaPastaPasta referenced this in commit d71fd97b51 on Jan 10, 2020
  31. PastaPastaPasta referenced this in commit d7b26c696a on Jan 10, 2020
  32. PastaPastaPasta referenced this in commit 80f4de55fd on Jan 10, 2020
  33. PastaPastaPasta referenced this in commit d94853e4d1 on Jan 12, 2020
  34. ckti referenced this in commit 83ec5a464f on Mar 28, 2021
  35. DrahtBot locked this on Sep 8, 2021

github-metadata-mirror

This is a metadata mirror of the GitHub repository bitcoin/bitcoin. This site is not affiliated with GitHub. Content is generated from a GitHub metadata backup.
generated: 2026-04-13 18:15 UTC

This site is hosted by @0xB10C
More mirrored repositories can be found on mirror.b10c.me