Skip to content
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

Adding formatting spec #8

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions text/code-standards/formatting.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Formatting

All Rust projects should follow the same formatting standard. This standard is
to be documented in a `rustfmt.toml` file in the top level of each project.
See below for an example of the default values for the file.

```toml
Copy link
Member

Choose a reason for hiding this comment

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

Another nice one for organizing imports is group_imports

Suggested change
```toml
```toml
group_imports = "StdExternalCrate"

fn_args_layout = "Tall"
hard_tabs = false
match_arm_leading_pipes = "Never"
max_width = 100
merge_derives = true
remove_nested_parens = true
reorder_imports = true
reorder_modules = true
tab_spaces = 4
Copy link
Member

Choose a reason for hiding this comment

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

This auto formats imports into a nice format for diffing (requires nightly fmt though):

Suggested change
tab_spaces = 4
imports_layout = "Vertical"
imports_granularity = "Crate"
tab_spaces = 4
use foo::{
    a,
    b
}

use_field_init_shorthand = false
Copy link
Member

Choose a reason for hiding this comment

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

This is a handy feature that helps prevent clippy warnings when enabled

Suggested change
use_field_init_shorthand = false
use_field_init_shorthand = true

use_small_heuristics = "Default"
use_try_shorthand = false
Copy link
Member

Choose a reason for hiding this comment

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

This one also makes sense to enable, no reason to keep the try! macro around

Suggested change
use_try_shorthand = false
use_try_shorthand = true

```