Skip to content

"cargo new" should add pre-commit hooks for autoformatter and linter #13758

Open
@worldmind

Description

Problem

  1. 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.
  2. Rust/cargo has rustfmt and clippy.
  3. 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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

No one assigned

    Labels

    A-vcsArea: general VCS issuesC-feature-requestCategory: proposal for a feature. Before PR, ping rust-lang/cargo if this is not `Feature accepted`Command-initCommand-newS-needs-designStatus: Needs someone to work further on the design for the feature or fix. NOT YET accepted.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions