-
-
Notifications
You must be signed in to change notification settings - Fork 771
Remove tab characters & protect against accidentally introducing them #2414
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
Conversation
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.
Good change, just too bad we still have to do this in 2021!
@@ -377,9 +377,9 @@ impl Driver for L3gd20Spi<'_> { | |||
) -> ReturnCode { | |||
match subscribe_num { | |||
0 /* set the one shot callback */ => { |
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.
Just FYI this is a known rustfmt issue: rust-lang/rustfmt#4119
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.
Looks good once Brad's comment is addressed.
Some tab characters will not be replaced by spaces through rustfmt. To avoid these making it into the repository, add an additional check for tab characters. If available, the fast "git grep" will be used, otherwise it will fall back to the system grep. This has been tested with GNU grep.
It appears that rustfmt does not always remove tab characters, in particular as part of macro invocations. This removes (accidentally) inserted tab characters for a consistent code style.
dd922cf
to
0c96b02
Compare
bors r+ |
Pull Request Overview
This pull request removes tab characters from Tock's Rust codebase, most of which have been accidentally introduced by me. Whoops, sorry!
While I don't want to "police" anyone's code style, Tock's codebase uses almost exclusively spaces.
rustfmt
seems to replace tabs by spaces pretty consistently, but it appears to have a hard time in macro invocations and some other places. Given that there is no defined standard width for representing tabs in Tock's Rust files, and we're interleaving tabs with spaces, this makes for a very inconsistent indentation depending on the editor's configuration.Furthermore, this adds a check for tab characters in the codebase to the
run_cargo_fmt.sh
script. It usesgit grep
if available, and falls back to the system'sgrep
otherwise. It has been tested with GNUgrep
and might require small modifications for BSDgrep
. The check's overhead isn't noticeable (compared to thecargo fmt
invocations), even on some low-end systems of mine.Output prior to removing the tab characters from the codebase:
Testing Strategy
This pull request was tested by running the script against the codebase with tab characters, and against the properly formatted one. It requires testing on a machine with BSD grep (such as macOS).
TODO or Help Wanted
I'd appreciate someone with access to a machine having BSD
grep
to test the fallback to the system's installedgrep
.Documentation Updated
/docs
, or no updates are required.Formatting
make prepush
.