Giter VIP home page Giter VIP logo

pre-commit-clippy-fix's Introduction

Supplemental pre-commit hook to run cargo clippy --fix, silencing its stderr unless an error prevents Clippy from exiting correctly. Intended to be used together with regular cargo clippy call that would list warnings as usual. Since there seems to be no way to make --fix explain what and why it fixes.

How to use

Add the hook to your .pre-commit-config.yaml after your regular Clippy hook. Order is important as pre-commit runs hooks one by one in the way they were listed in the config file.

repos:
  - repo: https://github.com/doublify/pre-commit-rust
    rev: v1.0
    hooks:
      - id: clippy
  - repo: https://github.com/Artalus/pre-commit-clippy-fix
    rev: v0.1
    hooks:
      - id: clippy-fix
  • If Clippy has nothing to fix, it will exit with code 0 and the hook will succeed.
  • If there were any changes applied, Clippy still will exit with 0, but the hook will fail detecting a change in workdir:
clippy fix...............................................................Failed
- hook id: clippy-fix
- duration: 2.12s
- files were modified by this hook
  • If Clippy actually fails with non-zero exit code, the hook will dump the stderr:
clippy fix...............................................................Failed
- hook id: clippy-fix
- duration: 0.25s
- exit code: 101

cargo clippy --fix --allow-staged exited with 101; STDERR was:

error: invalid table header
expected `.`, `]`
 --> Cargo.toml:1:11
  |
1 | [workspace
  |           ^

As with any other pre-commit hook, you can use args to pass additional arguments to Clippy:

      - id: clippy-fix
        args: [--all-targets, --no-deps, --, -D, warnings]

pre-commit-clippy-fix's People

Contributors

artalus avatar

Watchers

 avatar Kostas Georgiou avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.