Skip to content

Conversation

@eklitzke
Copy link
Contributor

@eklitzke eklitzke commented Aug 8, 2017

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

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.
@fanquake fanquake added the Tests label Aug 8, 2017
Copy link
Member

@maflcko maflcko left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

fi

showdiff() {
if ! git diff "${TRAVIS_COMMIT_RANGE}" --; then
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

-U0

Copy link
Contributor Author

@eklitzke eklitzke Aug 8, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

}

# Do a first pass, and if no trailing whitespace was found then exit early.
if ! showdiff | egrep -q '^\+.*\s+$'; then
Copy link
Contributor

@practicalswift practicalswift Aug 8, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Serious nit, haha.

fi
echo "$line"
fi
done < <(showdiff | egrep '^(diff --git |\+.*\s+$)')
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

@practicalswift
Copy link
Contributor

Concept ACK

@eklitzke
Copy link
Contributor Author

eklitzke commented Aug 8, 2017

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

@eklitzke
Copy link
Contributor Author

eklitzke commented Aug 8, 2017

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.

@eklitzke eklitzke closed this Aug 9, 2017
@eklitzke eklitzke reopened this Aug 9, 2017
@fanquake
Copy link
Member

fanquake commented Aug 9, 2017

@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.

@eklitzke
Copy link
Contributor Author

eklitzke commented Aug 9, 2017

@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.

@maflcko
Copy link
Member

maflcko commented Aug 10, 2017

Please squash your commits according to https://github.com/bitcoin/bitcoin/blob/master/CONTRIBUTING.md#squashing-commits

@practicalswift
Copy link
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.

@maflcko
Copy link
Member

maflcko commented Aug 30, 2017

@eklitzke Are you still working on this?

Copy link
Contributor

@ryanofsky ryanofsky left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

utACK d8a7add 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.


# We can't run this check unless we know the commit range for the PR.
if [ -z "${TRAVIS_COMMIT_RANGE}" ]; then
exit 0
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

@maflcko
Copy link
Member

maflcko commented Sep 10, 2017

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

This is up for grab by other contributors.

@maflcko maflcko closed this Sep 10, 2017
maflcko pushed a commit that referenced this pull request Sep 14, 2017
1f379b1 Add tab char lint check and exclude imported dependencies (MeshCollider)
dd36561 Add a lint check for trailing whitespace. (Evan Klitzke)

Pull request description:

  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

Tree-SHA512: d2dfbedc8469026f39b0c63d9a71d8b8e2ed3815d69fecaabad10304d977d6345728c4c865ec7600ed539b1f7cabaa826b50312f4d2eef0a1583d4ff9024c36d
PastaPastaPasta pushed a commit to PastaPastaPasta/dash that referenced this pull request Jan 10, 2020
…*dash* no travis

*DASH* doesn't implement this check into travis

1f379b1 Add tab char lint check and exclude imported dependencies (MeshCollider)
dd36561 Add a lint check for trailing whitespace. (Evan Klitzke)

Pull request description:

  This is a new attempt at bitcoin#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

Tree-SHA512: d2dfbedc8469026f39b0c63d9a71d8b8e2ed3815d69fecaabad10304d977d6345728c4c865ec7600ed539b1f7cabaa826b50312f4d2eef0a1583d4ff9024c36d
@bitcoin bitcoin locked as resolved and limited conversation to collaborators Sep 8, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants