Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Conversation

@liyuqian
Copy link
Contributor

@liyuqian liyuqian commented Jul 12, 2018

So we'll no longer need #5734 and #5708

travis/format.sh Outdated

for f in $FILES_TO_CHECK; do
set +e
TRAILING_SPACES="$(grep -P " +$" $f)"
Copy link
Contributor

Choose a reason for hiding this comment

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

I'd look for trailing tab characters too.

Copy link
Member

@cbracken cbracken Jul 12, 2018

Choose a reason for hiding this comment

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

Just use \s to match all whitespace.

Copy link
Member

@cbracken cbracken Jul 12, 2018

Choose a reason for hiding this comment

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

Also, use single quotes in the grep invocation in the subshell, and add double quotes around the "$f".

Copy link
Contributor

Choose a reason for hiding this comment

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

And I'd use "-E" instead of "-P", since that doesn't exist on macOS grep: you can use the blank character class too (which is space and tab).

grep -E '[[:blank:]]+$' .

Copy link
Member

Choose a reason for hiding this comment

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

You can avoid both -E and -P with \s unless [[:blank:]] matches a superset of \s.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done. Thanks for the suggestion!

travis/format.sh Outdated

if [[ $FAILED_CHECKS -ne 0 ]]; then
echo ""
echo "ERROR: Some files have trailing spaces. To fix, try something like \`find . -name "*.dart" -print0 | xargs -0 perl -pi -e 's/ +$//'\`."
Copy link
Member

Choose a reason for hiding this comment

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

Patch up as described in person, should be significantly shorter too :)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

travis/format.sh Outdated
for f in $FILES_TO_CHECK; do
set +e
TRAILING_SPACES="$(grep -P " +$" $f)"
TRAILING_SPACES="$(grep '\s\+$' $f)"
Copy link
Contributor

@gspencergoog gspencergoog Jul 13, 2018

Choose a reason for hiding this comment

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

Note that \s also matches return, vertical tab, form feed and, technically, newline. I'd just use [[:blank:]], since that just matches actual space and tab characters, and the others, while we probably want to remove them if they're in the code, it's more likely that they're intentionally there as part of a """ string.

Copy link
Contributor

@gspencergoog gspencergoog Jul 13, 2018

Choose a reason for hiding this comment

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

Oh, also \s (which is a synonym for [[:space:]]) is locale dependent and will match any whitespace characters in the locale, and those (besides space and tab) are even more likely to be intentional, IMO.

Copy link
Contributor

Choose a reason for hiding this comment

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

But if we're sure we want to eliminate ALL whitespace at EOL, then I'm fine with \s, since there are workarounds if you really want whitespace at EOL in a """ string anyhow (which now that I think about it more is probably a bad practice in any case).

Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah, ignore me. Listen to Chris. :-)

@gspencergoog
Copy link
Contributor

FYI, I made a PR for a similar check for the flutter repo: flutter/flutter#19329

@liyuqian
Copy link
Contributor Author

@cbracken : please review the changed the git diff line as we discussed offline.

travis/format.sh Outdated
FILETYPES="*.c *.cc *.cpp *.h *.m *.mm *.dart"
FILES_TO_CHECK="$(git diff $DIFF_OPTS -- master $FILETYPES)"

for f in $FILES_TO_CHECK; do
Copy link
Contributor

Choose a reason for hiding this comment

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

I'd actually suggest you do this with xargs: it results in fewer invocations of grep (so it's marginally faster), it's more compact, and it avoids problems where the command line size limit is reached.

TRAILING_SPACES=$(git diff $DIFF_OPTS master -- $FILETYPES | xargs grep --line-number --with-filename '\s\+$')

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

travis/format.sh Outdated

for f in $FILES_TO_CHECK; do
set +e
TRAILING_SPACES="$(grep --line-number '\s\+$' $f)"
Copy link
Contributor

Choose a reason for hiding this comment

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

You'll also want to add --with-filename so that the grep line includes the filename.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

liyuqian added 7 commits July 13, 2018 13:04
Previously, the git diff always returns empty because everything after
`--` is considered <path>. (So master is parsed as <path> instead of
<branch>.)
Otherwise, the script will exit with error if grep finds no match.
@liyuqian
Copy link
Contributor Author

@gspencergoog : xargs do have different exit code between linux and mac, and error code 123 only exists on linux. Anyway, set +e would solve all these problems and we've already used that in this script during earlier diff.

@gspencergoog
Copy link
Contributor

Works for me. LGTM (again).

@liyuqian liyuqian merged commit a28c3e7 into flutter:master Jul 13, 2018
jonahwilliams pushed a commit that referenced this pull request Jul 13, 2018
@chinmaygarde
Copy link
Contributor

This is giving me unexpected results on https://travis-ci.org/flutter/engine/builds/408311343?utm_source=github_status&utm_medium=notification. I have run clang-format over the file to make sure. Also, why are we reinventing clang-format? Both #5734 and #5708 would have been caught if we had ensured that clang-format was run over the diff. There is also a python script that performs clang-format over just the diff instead of over the entire source tree.

@liyuqian
Copy link
Contributor Author

liyuqian commented Jul 26, 2018 via email

@chinmaygarde
Copy link
Contributor

chinmaygarde commented Jul 26, 2018 via email

@liyuqian
Copy link
Contributor Author

liyuqian commented Jul 26, 2018 via email

@chinmaygarde
Copy link
Contributor

chinmaygarde commented Jul 26, 2018 via email

@liyuqian
Copy link
Contributor Author

Thanks @chinmaygarde for the feedback! I agree that using a single tool such as clang-format is a better way to go. I guess that we don't clang-format dart now because most of our dart files don't comply with clang-format. So if we're using clang-format for dart, we have to disable every other check except trailing spaces (and potentially new lines if we choose to do so).

@gspencergoog
Copy link
Contributor

@liyuqian, clang-format doesn't format Dart files, it formats C/C++ (clang => C-Language). We don't run dartfmt because our style guide doesn't conform with the output of dartfmt.

@liyuqian
Copy link
Contributor Author

@gspencergoog it does format Dart file for me: ../buildtools/linux-x64/clang/bin/clang-format lib/ui/painting.dart. Maybe our repo has special clang-format config?

@liyuqian liyuqian deleted the whitespace2 branch September 12, 2018 22:51
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.

5 participants