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

Stabilize the ignore configuration #3243

Closed
sdroege opened this issue Dec 10, 2018 · 28 comments · Fixed by #4139
Closed

Stabilize the ignore configuration #3243

sdroege opened this issue Dec 10, 2018 · 28 comments · Fixed by #4139
Labels
stabilisation-request A request to stabilise an option or argument
Milestone

Comments

@sdroege
Copy link

sdroege commented Dec 10, 2018

This one does not affect how the code is formatted but allows specific files or directories to be excluded from formatting.

What is needed for stabilizing this for one of the next releases?

@nrc
Copy link
Member

nrc commented Jan 7, 2019

The question I guess is do we think that we really want this config option (which I think the answer is 'yes') and if it has the right options, or at least, are they forward compatible with the right options.

@sdroege
Copy link
Author

sdroege commented Jan 10, 2019

What's the right way to move forward with this then?

IMHO it would be nicer to rename the configuration to ignore_files or similar to make it more explicit that this is for ignoring whole files and directories (and not modules for example).

The only way how I can currently imagine how this could be extended is to make it possible to provide module names, or generally paths to items in the code. But then this would basically duplicate the #[rustfmt::skip] attribute, so maybe that's not a good idea anyway.

@nrc
Copy link
Member

nrc commented Jan 16, 2019

So, one bigger thought is whether we want to control non-formatting things using rustfmt.toml, or whether we should have a separate configuration file. I think changing the name to ignore_files is a good idea (and could be a small, separate PR). I'm not even sure what syntax we accept, but we might think about if its the right one (is it comma-separated, is it whitespace sensitive, does it have the correct behaviour with respect to all OSs when it comes to unicode edge cases, punctuation, etc., should we accept globs?).

What is your use case for this?

@nrc nrc added the stabilisation-request A request to stabilise an option or argument label Jan 16, 2019
@sdroege
Copy link
Author

sdroege commented Jan 16, 2019

What is your use case for this?

I have a crate that contains quite some autogenerated code, and I want to run rustfmt only over all the other code. The autogenerated code is in the repo because a) generation is non-trivial and b) having the code in the repo allows tracking changes better.

@sdroege
Copy link
Author

sdroege commented Jan 16, 2019

#3279 would be another solution for me

@otavio
Copy link
Contributor

otavio commented Jan 16, 2019

If this is inside a lib or a module, it would be better to control inside the source code itself and not on the rustfmt.toml as #3279 suggests. This makes what controls the code style more obvious as we need to import it anyway (using mod).

@nrc
Copy link
Member

nrc commented Jan 17, 2019

Yeah, I think having the code generator also generate #[rustfmt::skip] would be best

@jbit
Copy link

jbit commented Feb 17, 2019

Having an ignore option stabilised and in rustfmt.toml (or another config file) would be really useful when a project pulls in external projects as submodules.
Right now cargo fmt will reformat code in external submodules with the same rustfmt.toml as the main project. This is rarely a good thing, and with a CI system that runs --check, this can cause failing builds.

@richard-uk1
Copy link

Two things, both related to ignoring everything.

  1. currently ignore = ["."] doesn't work
  2. there is no ignore_all directive

Basically I got stung while working on Rocket (which doesn't use rustfmt) because my vim automatically runs cargo fmt on save. This caused me a lot of pain. However generally I want to run cargo fmt so I'd rather keep it built in.

A way to solve this problem is for packages that can't/don't want to use rustfmt to add a rustfmt.toml to their project with ignore = ["."] or ignore_all = true (if it exists).

@topecongiro
Copy link
Contributor

@derekdreery ignore = ["/"] should work. We recently changed the pattern of ignore to mimic .gitignore.

@richard-uk1
Copy link

Can confirm that works - could it be made more discoverable?

@scampi
Copy link
Contributor

scampi commented May 28, 2019

@derekdreery The configuration file https://github.com/rust-lang/rustfmt/blob/e0664662b49c1ed3e99391c51132ddf01cd87c79/Configurations.md#ignore has been updated few days ago with an example about this.

@richard-uk1
Copy link

Awesome, exactly what I wanted :)

@CreepySkeleton
Copy link
Contributor

Any progress on it?

@thomaseizinger
Copy link
Contributor

@derekdreery ignore = ["/"] should work. We recently changed the pattern of ignore to mimic .gitignore.

If the intention is to mimic .gitignore, should there maybe be a separate file as @nrc suggested? Like .rustfmtignore?

Having .XYignore files is a pretty common pattern and if the syntax is the same, it will be obvious to people how to use it.

The downside is that there is yet another file in the repository.

Many tools in the JS ecosystem for example allow you to put your configuration under a special key in the package.json file instead of having yet another file in the root of your repository. If the ignore configuration would move to a .rustfmtignore file, the remaining configuration could optionally be moved to a [rustmft] section of Cargo.toml.

This idea could obviously be implemented regardless of whether .rustfmtignore is introduced or not.

@hayd
Copy link

hayd commented Oct 31, 2019

configuration could optionally be moved to a [rustmft] section of Cargo.toml.

Is there an existing issue for this?

@topecongiro
Copy link
Contributor

@hayd Not that I am aware of.

@misha
Copy link

misha commented May 24, 2021

This option was supposedly stabilized, but someone posted in #4139 that it is reporting as unstable. I added my own output there, too.

@dnsco
Copy link

dnsco commented Mar 25, 2022

Warning: can't set `ignore = IgnoreList { path_set: {"generate"}, rustfmt_toml_path: "" }`, unstable features are only available in nightly channel.
% rustfmt --version
rustfmt 1.4.38-stable (9d1b2106 2022-02-23)```

@ytmimi
Copy link
Contributor

ytmimi commented Mar 25, 2022

@dnsco I think this comment does a good job of explaining things: #4139 (comment), and the tracking issue is for stabilization can be found at #3395.

To see if a given option is stable or not you can check Configurations.md, and more specifically here are the docs on ignore

@dnsco
Copy link

dnsco commented Mar 27, 2022

@ytmimi thank you.

@gnprice
Copy link

gnprice commented Dec 4, 2022

This issue should be reopened, if I've understood the discussion correctly (and in particular #4139 (comment) .) The option is still unstable; the PR that closed it was closing it for an exploratory potential 2.0 which didn't become a release.

There's also the issue #3395, which sounds very similar. I'm not sure if these two issues should be seen as duplicates, or if there's an intentional workflow distinction that results in two separate related issues. If they are to be taken as duplicates, though, this thread is both the older of the two and the one where substantive discussion has happened; so it seems like #3395 should be closed in that case and this one reopened.

@rdaum
Copy link

rdaum commented Feb 20, 2024

Can I ask why this issue is closed? The "ignore" feature still doesn't work:

Warning: can't set `ignore = IgnoreList { path_set: {"submodules"}, rustfmt_toml_path: "" }`, unstable features are only available in nightly channel.

with

active toolchain
----------------

stable-x86_64-unknown-linux-gnu (default)
rustc 1.76.0 (07dca489a 2024-02-04)
...
rustfmt 1.7.0-stable (07dca48 2024-02-04)

I don't control the formatting of my vendored third party submodules. But cannot make CI pass because I cannot tell rustfmt to stop scolding me for things I do not have control over. This seems undesirable and broken.

@ytmimi
Copy link
Contributor

ytmimi commented Feb 20, 2024

@rdaum the option is currently unstable and you'll need to use a nightly version of rustfmt if you want to use the ignore option.

@rdaum
Copy link

rdaum commented Feb 20, 2024

@ytmimi the question is why this ticket is closed implying stabilization finished, while #3395 is still open.

@ytmimi
Copy link
Contributor

ytmimi commented Feb 20, 2024

I agree that it's a bit confusing. This was closed a long time ago when changes were merged into an experimental 2.0 branch that never got released. As I mentioned in #3243 (comment), I think the comment made by Caleb #4139 (comment) does a good job of explaining the situation.

#3395 is the tracking issue for stabilization and I'd recommend relying on it as an indicator for when the option will be stabilized.

@kelvincesar
Copy link

I was having problem with the diesel schema.rs generation format. Using the rustfmt.toml to ignore the file didn't work, returning "unstable features are only available in nightly channel."

Resolved using:

#[rustfmt::skip]
pub mod schema;

@ytmimi
Copy link
Contributor

ytmimi commented Jul 5, 2024

Glad that you found a workaround. Yeah, ignore is still and unstable configuration option so you'd need to use a nightly version of rustfmt in order to take advantage of it. That's what the error message is letting you know. You can double check what version of rustfmt you're using by running rustfmt --version.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
stabilisation-request A request to stabilise an option or argument
Projects
None yet
Development

Successfully merging a pull request may close this issue.