Rust equivalents of formatters and import sorters?

Im coming from python where similarly to other languages there is a lot of tools for formatting your code (like flake8, pylint or black) and also formatting your imports (like isort). What are the equivalents of those in Rust? Are they built-in or are also external packages that you install with your package manager?

For code formatting, there is rustfmt, and the linter is clippy.

2 Likes

Does it also fort the imports?
Also is it possible to use it in a CI pipeline so that for example if someone pushes code that is not formatted the pipeline fails?

nvm i just read its --help and it can be easily done with --check flag. Thats great! Thanks!

I'm not a rustfmt user myself because I think it's overly opinionated, but from what I can tell, there has been an issue in 2017 for sorting inputs, which appears to be implemented, so yes, I think it can sort inputs. I don't think it does it by default, though.See @Alice's comment below.

1 Like

We don't have any configuration set up for the rustfmt in Tokio, but it does still sort our imports.

2 Likes

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.