"cargo new" should add pre-commit hooks for autoformatter and linter #13758
Open
Description
opened on Apr 15, 2024
Problem
- Usage of autoformatter and linter is a really good practice and, for not depend on IDE, good to have them in pre-commit hooks (of course it can also be some rust implementation (if any)) for block commiting changes which has issues.
- Rust/cargo has rustfmt and clippy.
cargo new
even does initialization of new git repo, has all tools, but doesn't configure pre-commit hooks, but why to not add them as it clearly good practice?
Proposed Solution
cargo new
should depends on pre-commit or something similar and add config (.pre-commit-config.yaml
for pre-commit).
Notes
For rustfmt I found example here:
repos:
- repo: local
hooks:
- id: rustfmt
name: rustfmt
description: Check if all files follow the rustfmt style
entry: cargo fmt --all -- --check --color always
language: system
pass_filenames: false
another example, plus example for clippy can be found here:
- repo: local
hooks:
- id: rust-linting
name: Rust linting
description: Run cargo fmt on files included in the commit. rustfmt should be installed before-hand.
entry: cargo fmt --all --
pass_filenames: true
types: [file, rust]
language: system
- id: rust-clippy
name: Rust clippy
description: Run cargo clippy on files included in the commit. clippy should be installed before-hand.
entry: cargo clippy --all-targets --all-features -- -Dclippy::all
pass_filenames: false
types: [file, rust]
language: system
Activity