New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Working whitespace check #838
Conversation
Seems good to me. |
@nishnik |
exit -1; | ||
fi | ||
# TODO: Add similar grep checks for space after comma,, space after `if`, space between `)` and `{` also | ||
git diff HEAD^1 --check #test for whitespaces |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is the idea here?
remove the top commit and take a diff
as it looks to me.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It doesn't remove the top commit. Just returns the diff
at it, i.e. the changes introduced in previous commit.
And diff --check
is to check for trailing whitespaces.
--check
Warn if changes introduce whitespace errors.
What are considered whitespace errors is controlled by core.whitespace configuration.
By default, trailing whitespaces (including lines that solely consist of whitespaces) and a space character that is immediately followed by a tab character inside the initial indent of the line are considered whitespace errors.
Exits with non-zero status if problems are found.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is incorrect.
@nishnik This misses out on some cases. Say you have a set of 10 commits, this checks only the top two. If the whitespace was introduced in the initial commits then they are missed out. |
Oh! My bad! |
I googled a lot about this issue.
As a good practice it is advised to use Git hooks.
The default
pre-commit
hook is sufficient for whitespace check.We can write a bash or python script to activate
pre-commit
hook (It just needsmv .git/hooks/pre-commit.sample .git/hooks/pre-commit
). Need suggestions on that!And adding this:
git diff HEAD^1 --check
in travis will serve our purpose. As it will exit the travis build if it finds trailing whitespace in recently modified code.Instance where travis build fails due to trailing whitespace.
Instance when it runs fine when there aren't any whitespace. One job fails because piranha has been updated. Unrelated to this PR.