🔨 Rust CI Tooling #
In this Rust CI tooling post, we see how you can use tools to keep your Rust repo polished using conventional commits together with Rust lint tools. Conventional commits are fantastic if you want automatically to generate SemVer versioning for your project. It can also assist in creating changelogs. In the video, we see how you can use the commitlint CLI tool to help you get started with conventional commits. More Rust centric, we also see how automatically to run Rust formatting and linting scripts on each commit. This can be great for keeping your code consistent when working in a team. Equally, if you like your code just so, these tools will have your back. Finally, we see how you can even enforce a custom commit message style, useful for example if you are working on a monorepo.
If that’s what you wanted to know, then hit play on the video! After that, don’t forget to check links below. You will also find the commands mentioned and handy code snippets further down. Drop a comment below or reach out for a chat on Element as well as Twitter @mention if you have suggestions for improvements or questions.
📹 Rust CI Tooling: Video #
🗳 Poll #
🖥 Rust CI Tooling: Code #
CLI Commands #
Installation #
- Clippy as well as rustfmt install
- Install commitizen together with pre-commit with Homebrew
- Install commitizen together with pre-commit with Python pip
Tool commands #
- Check Rust code for errors (comes with RustUp no need to install manually)
- Format Rust code
- Lint Rust code
- commitlint
- pre-commit
pre‑commit Config #
Custom commitlint Config Example #
🔗 Rust CI Tooling: Links #
- Article on getting started with Rust Cloudflare workers,
- cargo check docs ,
- rusfmt docs ,
- Clippy docs ,
- pre-commit Rust hook docs ,
- pre-commit commitlint hook docs ,
- conventional commit docs ,
- Twitter handle: @askRodney .
🏁 Rust CI Tooling: Summary #
What Rust formatting and linting tools are there? #
- The Rust team ships cargo-check with Rustup. This checks your Rust code for errors without fully building it. In fact, it should be quicker than building the code, when you just want a quick check you have not messed something up. As well as cargo-check there is rustfmt as well as Clippy. While rustfmt just enforces the Rust standard for code formatting, Clippy goes a step further. It can help you write better Rust. It goes beyond cargo-check which just checks for errors. Clippy will offer tips. For example, it might suggest a map is a clearer way of writing a particular block. As well as make suggestions it provides links, so you can open web pages to get a better idea of why it thinks the suggestion might improve code.
Can you integrate cargo-check, rustfmt and Clippy into your Rust CI process? #
- Yes, it is not too much hassle to add cargo-check and rustfmt together with Clippy into your continuous integration process. Using git hooks you can check your code is clean for all three tools on each commit. In fact, we have seen the pre-commit tool can be super helpful here. Adding pre-commit with a hook for the tools will help keep your repo polished whether working in a team or on your own pet project.
How can you enforce customized conventional commits in your project? #
- commitlint is a very helpful tool for enforcing a commit comment style. Conventional commits offer a standard for git commit messages which add consistency over projects. As well as being useful to humans, they help with automated continuous integration tasks like generating change logs and SemVer versioning. You can set conventional commits as a base standard then, augment the rules to suite your project. For example, if you have a monorepo and want to make sure a scope is included in each commit, you can add a rule for this. You can even go further and specify a list of allowed scopes. This might catch typos, keeping your commits message just how you intended them to be!
🙏🏽 Feedback #
Have you found the post useful? Would you prefer to see posts on another topic instead? Get in touch with ideas for new posts. Also, if you like my writing style, get in touch if I can write some posts for your company site on a consultancy basis. Read on to find ways to get in touch, further below. If you want to support posts similar to this one and can spare a few dollars, euros or pounds, please consider supporting me through Buy me a Coffee.
Just dropped a new 🎬 video taking you through some Continuous Integration tooling for Serverless Rust and other Rust projects.
— Rodney (@askRodney) April 25, 2022
Hope you find it useful!
#askRodneyhttps://t.co/rcFBv0PNlh
Finally, feel free to share the post on your social media accounts for all your followers who will find it useful. As well as leaving a comment below, you can get in touch via @askRodney on Twitter and also askRodney on Telegram . Also, see further ways to get in touch with Rodney Lab. I post regularly on Astro as well as SvelteKit. Also, subscribe to the newsletter to keep up-to-date with our latest projects.