You are not logged in.

#1 2020-03-16 20:35:45

OK38
Member
Registered: 2014-08-07
Posts: 15

Rust fmt default config file

Hello,

I started learning the Rust programming language and installed on my Arch config. But I don't really like some default formatting like 4 spaces rather tab indent or error message on non_snake_case. I found out that I can allow indent using hard_tabs=true on project folder and #![allow(non_snake_case)] but I would like to don't have to add this line on each project if possible. I would set them by default on all project. Do you know where can I find the configuration file ? There is nothing on /etc/rustup or /etc/cargo or on ~/.config/ folders.

Thank you.

Offline

#2 2020-03-21 16:25:16

Trent
Member
From: Baltimore, MD (US)
Registered: 2009-04-16
Posts: 990

Re: Rust fmt default config file

rustfmt looks for a file named rustfmt.toml or .rustfmt.toml in any parent directory. So if you have a directory that stores all your projects, you don't need to put a config file in every project; you can just put it in the parent directory.

allow(non_snake_case) is not a rustfmt directive; it is the compiler itself that checks naming conventions. So I think you have to override it on a per-project basis. But if you can, I would encourage you to just adopt the suggested naming style; even if it's not your favorite, there's value in following language convention when it comes to naming things, especially if you intend to ever publish this code in some way. Nobody likes that guy who writes Python in C#-style.

Personally the only thing I have overridden in any of my projects is hard_tabs = true.

Last edited by Trent (2020-03-21 16:25:40)

Offline

#3 2020-03-23 22:16:53

OK38
Member
Registered: 2014-08-07
Posts: 15

Re: Rust fmt default config file

If I put rustfmt.toml with hard_subs=true on parent folder and then create a new project with cargo, the file main.rs have spaces instead of tabs by default. I suppose, this is not an issue and I just have to replace on each new project on first use. Right ?

Thanks.

Offline

#4 2020-03-24 00:19:03

Trent
Member
From: Baltimore, MD (US)
Registered: 2009-04-16
Posts: 990

Re: Rust fmt default config file

True, cargo init does not run rustfmt for you, but it will be fixed the next time you run cargo fmt.

Offline

#5 2020-03-24 15:03:16

OK38
Member
Registered: 2014-08-07
Posts: 15

Re: Rust fmt default config file

Okay, thank you.

Offline

Board footer

Powered by FluxBB