Code style guide #6
Loading…
Reference in New Issue
No description provided.
Delete Branch "%!s(<nil>)"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Should we have some general style rules? Just looking at the repo and hit save for some reason, then realized my auto-format was not formatting the same way as the bit of code we have so far.
We can do this with rustfmt, which has integrations in most popular editors as well can be run from cmd line.
Note: I have set nothing fancy, so if no one has strong feelings we can just use the default which I think is just the official conventions.
REF Rust Style-Guide
👍
Agree that we should just use
rustfmt --edition 2021
as our defaultWould love to have a pre-commit hook or a format on save config for Visual Studio Code that works, if anyone wants to knock that together.
I can do both later today, but unfortunately the day job is calling. So if anyone wants to do it before then, please do.
For Visual Studio Code the rust-analyzer extension has a knob for
rustfmt
on save and on paste. This conversation lays out some problems with performing formatting in a git hook and some suggestions that might be helpful. I'll poke at it deeper if I get a moment after dinner.Yep, and installing the Rust meta extension includes this. So we just need to make sure we are using the same 'version' of formatting, and then have some instructions for users who aren't familiar with how to set format on save for a language.
On the topic of editors and rust-analyzer, there are also integrations for he following editors and they have nice instructions already we can link to:
Each editor also has one or more plugins that make this possible so users can use whichever suits them. Documentation
Mostly that person is trying to do some magic, if we have a pre commit hook it will check if the code is formatted and then abort the commit when it isn't, telling the user to do so. Answer clarifying
The question I have is where should this information be? Contribution guide? A style-guide file?
Or maybe not, regarding the commit hook. I will test that out tonight and see what happens.
So
cargo fmt --check
works as expected and returns non-zero when code is not formatted correctly. It also work recursively through project directories.cargo fmt
is usingrustfmt
and we can specify theedition
in the Cargo.toml config file. If I am reading this issue correctly, then I believe that rust analyzer just runs rustfmt which also picks up the edition from the Cargo.toml. 😬The last trick is how to share our pre commit hook. I hoped git templates would work but I'm not sure it works like I hoped.
EDIT: Maybe we can just offer the pre commit hook as some documentation, this way people can format with whichever method works for them but the option to catch it pre commit can remain with them. Then once we have CI we can enforce it there as well?
I like the idea of sharing any hooks we recommend for devs to use in an appropriate folder.
Ya I agree, I was thinking that but wasn't sure the directory structure to go with. So the pull request is is changed to WIP so we can fine tune everything 😎