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

Add option to format all files #4977

Closed
dylni opened this issue Sep 4, 2021 · 3 comments
Closed

Add option to format all files #4977

dylni opened this issue Sep 4, 2021 · 3 comments

Comments

@dylni
Copy link
Contributor

dylni commented Sep 4, 2021

It would be helpful for rustfmt to have an option to format all .rs files in a crate or all files in a directory.

Some issues exist due to rustfmt being unable to know exactly which files are included, due to #[path] attributes (1) or macros (1, 2, 3). However, usually, all that is needed is for every Rust file to be formatted. If rustfmt had an option to format all files, those issues would be avoided.

This could be combined with the ignore option to exclude some files.

@calebcartwright
Copy link
Member

Thanks for reaching out but going to close as this has been covered in various prior issues and is duplicative of existing behavior.

cargo fmt exists to format all the files in a crate in a way that's aware of crucial information, like edition, which impacts parsing. rustfmt formats whatever input is provided to it, either specified files or from stdin, and in the case of files the user has the option to also format files imported by inputs, or not.

We're not going to change that. If for some reason folks want/need to run rustfmt instead of cargo fmt then they'll need to provide the input files to rustfmt, and there's plenty of existing tools and capabilities for discovering files with a certain extension residing in a directory tree, that can then be piped to rustfmt. We're not going to duplicate those capabilities.

@dylni
Copy link
Contributor Author

dylni commented Sep 4, 2021

@calebcartwright Thank you for the information. That is unfortunate, but it makes sense.

Sorry for not finding existing issues about this. They did not show up in a search.

@calebcartwright
Copy link
Member

No worries, and thanks again for sharing!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants