Skip to content

tobinjt/rust-pre-commit-checks

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

23 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

rust-pre-commit-checks

Rust checks for http://pre-commit.com/

Usage

Make sure pre-commit is installed.

Create a blank configuration file at the root of your repo, if needed:

touch .pre-commit-config.yaml

Add a new repo entry in your configuration file:

repos:
  - repo: https://github.com/tobinjt/rust-pre-commit-checks
    rev: v1.0.0
    hooks:
      # See below for hook documentation, in particular the binaries you need
      # to install for each hook.
      - id: cargo-check
      - id: cargo-clippy
      - id: cargo-fmt
      - id: cargo-llvm-cov
      - id: cargo-test
      - id: check-tag-version

Install the pre-commit script:

pre-commit install --install-hooks

If you're using check-tag-version you'll also need to run:

pre-commit install --hook-type pre-push

Dependencies

You need to install the tools used for each hook and ensure they're in $PATH for the checks to work. The required tool and brief installation instructions, if any, is documented below beside each hook.

Workspaces

I haven't used cargo workspaces so these hooks don't support them because I have no way to test the config. PRs adding workspaces support are welcome.

Hooks

cargo-check

Runs cargo check. cargo check should be installed by default with your Rust installation.

cargo-clippy

Runs cargo clippy. The default args passed are --deny warnings to fail on warnings.

Install with:

rustup component add clippy

cargo-fmt

Runs cargo fmt. cargo fmt should be installed by default with your Rust installation.

cargo-llvm-cov

Runs cargo llvm-cov test. The default args passed are --quiet to reduce output; consider using --fail-uncovered-lines=X and --fail-uncovered-functions=X to require high test coverage.

Install with (see https://github.com/taiki-e/cargo-llvm-cov?tab=readme-ov-file#from-source). :

cargo +stable install cargo-llvm-cov --locked

Configure with:

repos:
  - repo: https://github.com/tobinjt/rust-pre-commit-checks
    rev: v1.0.0
    hooks:
      - id: cargo-llvm-cov
        args:
          [
            "--fail-uncovered-lines=5",
            "--fail-uncovered-functions=1",
            "--quiet",
            "--show-missing-lines",
          ]

cargo-test

Runs cargo test. cargo test should be installed by default with your Rust installation.

check-tag-version

This runs on push, not on commit. If a Git tag is being pushed, and it doesn't match the version in Cargo.toml, this check will fail. The intent is to prevent mismatches between the two, because you generally want them to be in sync.

You might want to consider using https://github.com/crate-ci/cargo-release to streamline the release process, but johntobin doesn't have any experience with that tooling.

License

Apache 2.0; see LICENSE for details.

About

Rust checks for http://pre-commit.com/

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Contributors

Languages