-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
[WIP] Add format command to tools crate #163
Conversation
crates/tools/src/main.rs
Outdated
|
||
fn run_rustfmt() -> Result<()> { | ||
// Use beta toolchain for 2018 edition. | ||
run("rustup install beta", ".")?; |
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.
Let's pin this to a specific beta, rustup install beta-2018-10-30
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.
How about we have a const value like:
const TOOLCHAIN: &str = "beta-2018-10-30";
and use it where we need?
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.
👍
crates/tools/src/main.rs
Outdated
@@ -163,3 +160,11 @@ fn run(cmdline: &'static str, dir: &str) -> Result<()> { | |||
} | |||
Ok(()) | |||
} | |||
|
|||
fn run_rustfmt() -> Result<()> { |
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 would be cool to have an fn run_rustfmt_precommit
, which formats all files changed in git. See this for the proper git command invocation and for how to make rustfmt format a single file: https://github.com/antiochp/grin/blob/121cce7e515f9eca8d8708a262a7cc262ee9b7e9/.hooks/pre-commit#L27
Oh, and one more stratch goal is to have a test which checks formatting. |
Pin to a specific toolchain version Format checking functionality Add a test to check the code formatting. Remove macro_use attribute
@matklad We now use a specific toolchain version and there is a test to check the code formatting. Can you check it please? I haven't yet added precommit hook though. |
Let's handle that in a separate PR then! Bascially, I think we need to have
which installs the hook (copies relevant files to and
which does the trick. |
I'll merge this PR manually and run a one-time formatting. |
BTW, this seems like a common problem, so publishing this as a reusable |
Ok! I'll create a |
I'd rather merge this as is! |
I think it make sense to prototype the git-hook as a PR against this repo, and then extract everyting as a crate: we might find some things to improve after using this for a bit. For example, I've noticed that rustup is not exactly fast, and added some code to check if we already have rustfmt isntalled |
Ok, I'll start hacking with git pre-commit hook and have a PR here first! After we gain experience, we can bundle them into a crate as you have said. |
I am quite unsure about the implementation of #155 , so I want to get reviews.
Thanks!
Thanks to @alanhdu @CAD97 for discussing the
rustup
commands!