# Using rustfmt systemically

**URL:** <https://discourse.pijul.org/t/using-rustfmt-systemically/211>\
**Category:** Development\
**Created:** [May 12, 2018, 4:15pm UTC](https://discourse.pijul.org/t/using-rustfmt-systemically/211 "2018-05-12T16:15:34Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![lthms](https://yyz1.discourse-cdn.com/flex031/user_avatar/discourse.pijul.org/lthms/32/124_2.png) [@lthms](https://discourse.pijul.org/u/lthms)\
**Post date:** [May 12, 2018, 4:15pm UTC](https://discourse.pijul.org/t/using-rustfmt-systemically/211/1 "2018-05-12T16:15:34Z")

</div>

I’ve seen @pmeunier and @flobec creating “rustfmt patches” from times to times. I wonder if we shouldn’t make one last one, then using it systemically before recording any patches.

This way, we will have a more consistent coding style across the pijul source code.

Fortunately, we have hooks to remember to run the script for us:

Create an executable `.pijul/hooks/pre-record` with the following content:

```bash
#!/usr/bin/bash

cargo fmt

```

---

<div class="post-metadata">

**Author:** ![yory](https://avatars.discourse-cdn.com/v4/letter/y/da6949/32.png) [@yory](https://discourse.pijul.org/u/yory)\
**Post date:** [May 12, 2018, 4:36pm UTC](https://discourse.pijul.org/t/using-rustfmt-systemically/211/2 "2018-05-12T16:36:40Z")

</div>

definitely. Done in my own repo.

Question: is it possible to have global template hooks like in git, so that whenever I create a pijul repo that hook is automatically copied inside? (obviously in that case it would need to be more generic, as not all projects are in rust)

---

<div class="post-metadata">

**Author:** ![lthms](https://yyz1.discourse-cdn.com/flex031/user_avatar/discourse.pijul.org/lthms/32/124_2.png) [@lthms](https://discourse.pijul.org/u/lthms)\
**Post date:** [May 12, 2018, 4:51pm UTC](https://discourse.pijul.org/t/using-rustfmt-systemically/211/3 "2018-05-12T16:51:50Z")

</div>

I had a look at the `rustfmt` [configuration options](https://github.com/rust-lang-nursery/rustfmt/blob/master/Configurations.md). I personally prefer the `visual` options, but I’ve seen the default is `block` and that it follows one rust official RFC… So if you guys would like to stick to the official guidelines, I am fine with that.

Once we agree, we can add a `rustfmt.toml` file to the root of the repo, **and** update the `README` file accordingly.

---

<div class="post-metadata">

**Author:** ![yory](https://avatars.discourse-cdn.com/v4/letter/y/da6949/32.png) [@yory](https://discourse.pijul.org/u/yory)\
**Post date:** [May 12, 2018, 5:22pm UTC](https://discourse.pijul.org/t/using-rustfmt-systemically/211/4 "2018-05-12T17:22:15Z")

</div>

If you scroll down, you’ll see that each option has a different default, for example “control\_brace\_style” is “AlwaysSameLine”, “error\_on\_line\_overflow” is “false”, etc.

---

<div class="post-metadata">

**Author:** ![lthms](https://yyz1.discourse-cdn.com/flex031/user_avatar/discourse.pijul.org/lthms/32/124_2.png) [@lthms](https://discourse.pijul.org/u/lthms)\
**Post date:** [May 12, 2018, 8:04pm UTC](https://discourse.pijul.org/t/using-rustfmt-systemically/211/5 "2018-05-12T20:04:03Z")

</div>

Yeah, I was not clear enough. I meant, for the first few configuration options, I prefer visual over block. For instance

```auto
fn function(arg1: x,
                  arg2: y)

```

over

```auto
fn function(
    arg1: x,
    arg2: y
)

```

but again, this is more a matter of personal taste.

---

<div class="post-metadata">

**Author:** ![pmeunier](https://yyz1.discourse-cdn.com/flex031/user_avatar/discourse.pijul.org/pmeunier/32/4_2.png) [@pmeunier](https://discourse.pijul.org/u/pmeunier)\
**Post date:** [May 12, 2018, 8:29pm UTC](https://discourse.pijul.org/t/using-rustfmt-systemically/211/6 "2018-05-12T20:29:15Z")

</div>

I strongly prefer the default (C-style) one.

---

<div class="post-metadata">

**Author:** ![lthms](https://yyz1.discourse-cdn.com/flex031/user_avatar/discourse.pijul.org/lthms/32/124_2.png) [@lthms](https://discourse.pijul.org/u/lthms)\
**Post date:** [May 12, 2018, 8:31pm UTC](https://discourse.pijul.org/t/using-rustfmt-systemically/211/7 "2018-05-12T20:31:52Z")

</div>

Then, default it is!

Is it okay if I push the “rustfmt patch”, then? Do we agree on using it before recording?

---

<div class="post-metadata">

**Author:** ![pmeunier](https://yyz1.discourse-cdn.com/flex031/user_avatar/discourse.pijul.org/pmeunier/32/4_2.png) [@pmeunier](https://discourse.pijul.org/u/pmeunier)\
**Post date:** [May 12, 2018, 8:46pm UTC](https://discourse.pijul.org/t/using-rustfmt-systemically/211/8 "2018-05-12T20:46:01Z")

</div>

I really like your idea of using this systematically, so yes! Go ahead!

---

<div class="post-metadata">

**Author:** ![yory](https://avatars.discourse-cdn.com/v4/letter/y/da6949/32.png) [@yory](https://discourse.pijul.org/u/yory)\
**Post date:** [May 12, 2018, 9:07pm UTC](https://discourse.pijul.org/t/using-rustfmt-systemically/211/9 "2018-05-12T21:07:22Z")

</div>

I fear this sentence might come across a bit too forceful in tone:

> If your patch does not comply with the coding style enforced by `rustfmt`, your patch might be refused as-is.

Maybe it’s better:

> Please make sure to comply with the rustfmt coding style before submitting your patches!

---

<div class="post-metadata">

**Author:** ![lthms](https://yyz1.discourse-cdn.com/flex031/user_avatar/discourse.pijul.org/lthms/32/124_2.png) [@lthms](https://discourse.pijul.org/u/lthms)\
**Post date:** [May 12, 2018, 9:43pm UTC](https://discourse.pijul.org/t/using-rustfmt-systemically/211/10 "2018-05-12T21:43:00Z")

</div>

You are probably right. I will edit as you suggest tomorrow, or you could always propose the change and I would apply it quickly.

---

<div class="post-metadata">

**Author:** ![lthms](https://yyz1.discourse-cdn.com/flex031/user_avatar/discourse.pijul.org/lthms/32/124_2.png) [@lthms](https://discourse.pijul.org/u/lthms)\
**Post date:** [May 13, 2018, 10:06pm UTC](https://discourse.pijul.org/t/using-rustfmt-systemically/211/11 "2018-05-13T22:06:30Z")

</div>

For the record, I just pushed another patch to apply globally `rustfmt`.

**Edit:** And I have unrecorded it, at it appears it fires a strange conflict within `pijul/src/commands/remote.rs`.

Will have to dig… another day.

---

<div class="post-metadata">

**Author:** ![pmeunier](https://yyz1.discourse-cdn.com/flex031/user_avatar/discourse.pijul.org/pmeunier/32/4_2.png) [@pmeunier](https://discourse.pijul.org/u/pmeunier)\
**Post date:** [May 14, 2018, 6:56am UTC](https://discourse.pijul.org/t/using-rustfmt-systemically/211/12 "2018-05-14T06:56:06Z")

</div>

I’d be interested in debugging this. What did your patch do exactly?

---

<div class="post-metadata">

**Author:** ![lthms](https://yyz1.discourse-cdn.com/flex031/user_avatar/discourse.pijul.org/lthms/32/124_2.png) [@lthms](https://discourse.pijul.org/u/lthms)\
**Post date:** [May 14, 2018, 7:09am UTC](https://discourse.pijul.org/t/using-rustfmt-systemically/211/13 "2018-05-14T07:09:40Z")

</div>

cargo fmt  
pijul record -a

The repo looks fine, but clone it and you should see a conflict in remote.rs

–lthms

1. Mai 2018 09:06 de [pijul@discoursemail.com](mailto:pijul@discoursemail.com):

---

<div class="post-metadata">

**Author:** ![pmeunier](https://yyz1.discourse-cdn.com/flex031/user_avatar/discourse.pijul.org/pmeunier/32/4_2.png) [@pmeunier](https://discourse.pijul.org/u/pmeunier)\
**Post date:** [May 14, 2018, 7:26am UTC](https://discourse.pijul.org/t/using-rustfmt-systemically/211/14 "2018-05-14T07:26:01Z")

</div>

I can’t reproduce, even if I fix the `cargo fmt` failure to format `pijul::commands::fs_operations`.

---

<div class="post-metadata">

**Author:** ![lthms](https://yyz1.discourse-cdn.com/flex031/user_avatar/discourse.pijul.org/lthms/32/124_2.png) [@lthms](https://discourse.pijul.org/u/lthms)\
**Post date:** [May 14, 2018, 7:50am UTC](https://discourse.pijul.org/t/using-rustfmt-systemically/211/15 "2018-05-14T07:50:16Z")

</div>

Maybe we are not using the same version of `rustfmt`? Or maybe, my pijul repo was in a strange state, or I used a strange pijul, in order to record this patch. I don’t really know.

I will come back to you if I encounter the issue ever again.

**Edit:** We definitely don’t have the same `rustfmt` version.

---

<div class="post-metadata">

**Author:** ![yory](https://avatars.discourse-cdn.com/v4/letter/y/da6949/32.png) [@yory](https://discourse.pijul.org/u/yory)\
**Post date:** [May 14, 2018, 9:12am UTC](https://discourse.pijul.org/t/using-rustfmt-systemically/211/16 "2018-05-14T09:12:55Z")

</div>

I can’t reproduce either, using rustfmt 0.3.8-nightly

---

<div class="post-metadata">

**Author:** ![yory](https://avatars.discourse-cdn.com/v4/letter/y/da6949/32.png) [@yory](https://discourse.pijul.org/u/yory)\
**Post date:** [May 14, 2018, 2:30pm UTC](https://discourse.pijul.org/t/using-rustfmt-systemically/211/17 "2018-05-14T14:30:36Z")

</div>

Even though now we are all using rustfmt, I still get new formatting on supposedly already formatted code. I think it’s because we are using different versions of rustfmt.

---

<div class="post-metadata">

**Author:** ![lthms](https://yyz1.discourse-cdn.com/flex031/user_avatar/discourse.pijul.org/lthms/32/124_2.png) [@lthms](https://discourse.pijul.org/u/lthms)\
**Post date:** [May 14, 2018, 3:13pm UTC](https://discourse.pijul.org/t/using-rustfmt-systemically/211/18 "2018-05-14T15:13:25Z")

</div>

I will try to oush a rush fly.toml file, see if it does us any good.

Ado, have you installled rustfmt with rustup ? I believe it is the best way for us to stay sync

–lthms

1. Mai 2018 16:40 de [pijul@discoursemail.com](mailto:pijul@discoursemail.com):

---

<div class="post-metadata">

**Author:** ![lthms](https://yyz1.discourse-cdn.com/flex031/user_avatar/discourse.pijul.org/lthms/32/124_2.png) [@lthms](https://discourse.pijul.org/u/lthms)\
**Post date:** [May 14, 2018, 3:45pm UTC](https://discourse.pijul.org/t/using-rustfmt-systemically/211/19 "2018-05-14T15:45:03Z")

</div>

```auto
$ cargo fmt --version
rustfmt 0.6.1-nightly (0f8029f 2018-05-06)

```

Could you try to create a new file `rustfmt.toml` at the root of the repo, with this content:

```auto
max_width = 100
hard_tabs = false
tab_spaces = 4
newline_style = "Unix"
use_small_heuristics = true
indent_style = "Block"
wrap_comments = false
comment_width = 80
normalize_comments = false
format_strings = false
empty_item_single_line = true
struct_lit_single_line = true
fn_single_line = false
where_single_line = false
imports_indent = "Block"
imports_layout = "Mixed"
merge_imports = false
reorder_imports = true
reorder_modules = true
reorder_impl_items = false
type_punctuation_density = "Wide"
space_before_colon = false
space_after_colon = true
spaces_around_ranges = false
spaces_within_parens_and_brackets = false
binop_separator = "Front"
remove_blank_lines_at_start_or_end_of_block = true
combine_control_expr = true
struct_field_align_threshold = 0
match_arm_blocks = true
force_multiline_blocks = false
fn_args_density = "Tall"
brace_style = "SameLineWhere"
control_brace_style = "AlwaysSameLine"
trailing_semicolon = true
trailing_comma = "Vertical"
match_block_trailing_comma = false
blank_lines_upper_bound = 1
blank_lines_lower_bound = 0
merge_derives = true
use_try_shorthand = false
condense_wildcard_suffixes = false
force_explicit_abi = true
use_field_init_shorthand = false
write_mode = "Overwrite"
color = "Auto"
required_version = "0.6.1"
unstable_features = false
disable_all_formatting = false
skip_children = false
hide_parse_errors = false
error_on_line_overflow = false
error_on_unformatted = false
report_todo = "Never"
report_fixme = "Never"
ignore = []
verbose_diff = false

```

And tell me if it works for you? If it does, I will push a patch to add it, along with a rustfmt patch.

---

<div class="post-metadata">

**Author:** ![yory](https://avatars.discourse-cdn.com/v4/letter/y/da6949/32.png) [@yory](https://discourse.pijul.org/u/yory)\
**Post date:** [May 14, 2018, 4:48pm UTC](https://discourse.pijul.org/t/using-rustfmt-systemically/211/20 "2018-05-14T16:48:35Z")

</div>

Were you talking to me?

With rustup I now have rustfmt 0.4.1-stable, everything is up to date. Seems it depends on the default toolchain? Must be resolved anyway.

On a related note, is it possible to have a pre-push hook that checks if pijul builds before sending to the nest? I think it would be even more useful than the rustfmt hook.

[Next page](https://discourse.pijul.org/t/using-rustfmt-systemically/211.md?page=2)
