Opens an external site in a new window
Mental Health Awareness Month
“Community”
RODNEY LAB
  • Home
  • Plus +
  • Newsletter
  • Links
  • Profile
RODNEY LAB
  • Home
  • Plus +
  • Newsletter
  • Links

Rust CI Tooling: Clippy, commitlint, pre‑commit and More # Rust CI Tooling: Clippy, commitlint, pre-commit and More #

blurry low resolution placeholder image Rust CI Tooling
  1. Home Rodney Lab Home
  2. Blog Posts Rodney Lab Blog Posts
  3. Rust Rust Blog Posts
<PREVIOUS POST
NEXT POST >
LATEST POST >>

Rust CI Tooling: Clippy, commitlint, pre‑commit and More #

Published: 4 years ago
4 minute read
Gunning Fog Index: 6.8
Content by Rodney
blurry low resolution placeholder image Author Image: Rodney from Rodney Lab
SHARE:

🔨 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 #

Please enable JavaScript to watch the video 📼

Rust CI Tooling

🗳 Poll #

Are you a conventional commits fan?
Voting reveals latest results.

🖥 Rust CI Tooling: Code #

CLI Commands #

Installation #

  • Clippy as well as rustfmt install
  •     
    rustup component add clippy rustfmt
  • Install commitizen together with pre-commit with Homebrew
  •     
    brew install commitizen pre-commit
  • Install commitizen together with pre-commit with Python pip
  •     
    pip install Commitizen pre-commit

Tool commands #

  • Check Rust code for errors (comes with RustUp no need to install manually)
    
cargo check
  • Format Rust code
    
cargo fmt
  • Lint Rust code
    
cargo clippy
  • commitlint
  •     
    cz init # initialise new project
    cz c # commit
    cz c --retry # retry failed commit with same parameters
    cz bump # bump SemVer version
    cz changelog # generate CHANGELOG.md
  • pre-commit
  •     
    pre-commit install # install pre-commit in new project
    pre-commit run --all-files # one-off check all files

pre‑commit Config #

.pre-commit-config.yaml
yaml
    
1 repos:
2 - hooks:
3 - id: commitizen
4 stages:
5 - commit-msg
6 repo: https://github.com/commitizen-tools/commitizen
7 rev: v2.24.0
8 - hooks:
9 - id: fmt
10 - id: cargo-check
11 - id: clippy
12 repo: https://github.com/doublify/pre-commit-rust
13 rev: v1.0
14 - repo: https://github.com/alessandrojcm/commitlint-pre-commit-hook
15 rev: v8.0.0
16 hooks:
17 - id: commitlint
18 stages: [commit-msg]
19 additional_dependencies: ["@commitlint/config-conventional"]

Custom commitlint Config Example #

commitlint.config.cjs
javascript
    
1 module.exports = {
2 extends: ["@commitlint/config-conventional"],
3 rules: {
4 "scope-empty": [2, "never"],
5 },
6 };

🔗 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.

blurry low resolution placeholder image ask Rodney X (formerly Twitter) avatar

Rodney

@askRodney

Just dropped a new 🎬 video taking you through some Continuous Integration tooling for Serverless Rust and other Rust projects.

Hope you find it useful!

#askRodneyhttps://t.co/rcFBv0PNlh

— Rodney (@askRodney) April 25, 2022

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.

Thanks for reading this post. I hope you found it valuable. Please get in touch with your feedback and suggestions for posts you would like to see. Read more about me …

blurry low resolution placeholder image Rodney from Rodney Lab
TAGS:
RUSTSERVERLESS

Likes:

Likes

  • Jordan Shurmer profile avatar
Likes provided by Mastodon & X via Webmentions.
<PREVIOUS POST
NEXT POST >
LATEST POST >>

Leave a comment …

Your information will be handled in line with our Privacy Policy .

Ask for more

1 Nov 2022 — Astro Server-Side Rendering: Edge Search Site
3 Oct 2022 — Svelte eCommerce Site: SvelteKit Snipcart Storefront
1 Sept 2022 — Get Started with SvelteKit Headless WordPress

Copyright © 2020 – 2025 Rodney Johnson. All Rights Reserved. Please read important copyright and intellectual property information.

  • Home
  • Profile
  • Plus +
  • Newsletter
  • Contact
  • Links
  • Terms of Use
  • Privacy Policy
We use cookies  to enhance visitors’ experience. Please click the “Options” button to make your choice.  Learn more here.