Giter VIP home page Giter VIP logo

pre-commit-rust's People

Contributors

calinou avatar danielchabrowski avatar frangio avatar mathieu-lemay avatar narsil avatar teymour-aldridge avatar waisbrot avatar zsol avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

pre-commit-rust's Issues

disable "deny warning"

should this hook provide a way to disable the 'deny warnings' flag?

many codebases (including my own) use compiler flags to set the warning level for clippy lints. the 'deny warnings' flag escalates them further, beyond the original intention of the author.

for a concrete example, i tend to use

#![deny(clippy::all)]
#![warn(clippy::pedantic)]

this hook effectively elevates this to

#![deny(clippy::all)]
#![deny(clippy::pedantic)]

this is a nightmare for reproducible builds, for example.

Use language: rust for hooks?

I noticed that the current hooks use language: system, but it would be nice if the hooks used language: rust instead (e.g. this is needed for pre-commit.ci)

Cannot pass arguments to rustfmt

cargo fmt would use cargo.toml for the info, rustfmt has also the option --edition but

-   repo: https://github.com/doublify/pre-commit-rust
    rev: master
    hooks:
    -   id: fmt
        args:
          - --edition=2018

Says: "Error: file --edition=2018 does not exist"

Workaround: create .rustfmt.toml and put edition="2018" there.

Need a way to specify toolchain channel for each hook

I'm tinkering with a project, right now, which compiles fine with stable rust, but its rustfmt configuration uses a whole bunch of options that are only available with nightly rustfmt. I don't want to switch my default toolchain to nightly just for the sake of this project. It would be nice if it were possible to specify, in .pre-commit-config.yaml for this project, that the fmt hook should run cargo +nightly fmt instead of cargo fmt.

This doesn't appear to be possible with the args array because that's inserted too late on the command line, e.g.

  hooks:
    - id: fmt
      args: ["+nightly"]

gives an error message about there not being any file named +nightly.

Skipped hook

Hi,
I am trying to use this repo with pre-commit but when I use it to check my code format, it apply modification and I want to not commit them directly.

My repo with staged changes before format looks like this with git status:

$ git status     
On branch <branch-name>
Your branch is ahead of 'origin/<branch-name>' by 1 commit.
  (use "git push" to publish your local commits)

Changes to be committed:
  (use "git restore --staged <file>..." to unstage)
	modified:   tests/test_commands.rs

and commiting leads to this:

$ git commit -m "test"
Formatting source files
Formatting done, changed files: tests/test_commands.rs
fmt..................................................(no files to check)Skipped
[<branch-name> <commit-hash>] test

And the file is modified by the formatter which is not what I expect.

I would have it to fail to commit and having a status like this:

$ git status     
On branch 209-add-cargo-fmt-to-git-hooks-pre-commit
Your branch is ahead of 'origin/<branch-name>' by 1 commit.
  (use "git push" to publish your local commits)

Changes to be committed:
  (use "git restore --staged <file>..." to unstage)
	modified:   tests/test_commands.rs

Untracked files:
  (use "git add <file>..." to include in what will be committed)
	tests/test_commands.rs

My config file looks like this:

repos:
-   repo: https://github.com/doublify/pre-commit-rust
    rev: v1.0
    hooks:
    -   id: fmt
        name: fmt
        description: Format files with cargo fmt.
        entry: cargo fmt --
        language: system
        types: [rust]
        args: ["--verbose", "--check"]

Using check in argument prevent the modification of the file which makes it event more frustrating and is not what I want to do.

I want it to make unstaged changes to the file that I can add and then commit.

Where does this behavior comes from?

Also run hooks when only Cargo.toml and/or Cargo.lock has changed

Both the cargo-check and clippy hooks should also be run if only Cargo.toml and/or Cargo.lock has been changed.

The following shows the problem:

$ cd /tmp
$ cargo new test-pre-commit
$ cd test-pre-commit
$ cat > .pre-commit-config.yaml
repos:
  - repo: https://github.com/doublify/pre-commit-rust
    rev: v1.0
    hooks:
    -   id: fmt
    -   id: cargo-check
^D
$ pre-commit install
$ git add .
$ git commit -m 'init'
fmt......................................................................Passed
cargo check..............................................................Passed
...
$ cargo add libc
$ cat > src/main.rs
fn main() {
    let r = unsafe { libc::rand() };
    dbg!(r);
}
^D
$ git add .
$ git commit -m '2nd'
fmt......................................................................Passed
cargo check..............................................................Passed
...
$ cargo rm libc
$ git add .
$ git commit -m '3rd'
fmt..................................................(no files to check)Skipped
cargo check..........................................(no files to check)Skipped

In the 3rd commit we have removed libc so that the code no longer compiles. However the cargo-check step is skipped, so this is not caught :(

Running pre-commit run --all-files manually results in:

fmt......................................................................Passed
cargo check..............................................................Failed
- hook id: cargo-check
- exit code: 101

    Checking test-pre-commit v0.1.0 (/tmp/test-pre-commit)
error[E0433]: failed to resolve: use of undeclared crate or module `libc`
 --> src/main.rs:2:22
  |
2 |     let r = unsafe { libc::rand() };
  |                      ^^^^ use of undeclared crate or module `libc`

For more information about this error, try `rustc --explain E0433`.
error: could not compile `test-pre-commit` (bin "test-pre-commit") due to 1 previous error

feat request: hook for running rust tests

What:

  • add cargo test hook, that runs test suite of Rust package.

Why:

  • support TDD workflows, provide easy hook for teams to add test runs to their pre-commit checks.
  • reduce need for packages to use a local hook implementation/workaround

Context:

A standard practice for my projects is to have tests run for each commit and push. My impression of this repo is the go-to for standard Rust hooks including basic cargo functionality. However, I see cargo test is not yet implemented -> feature request! ๐Ÿ˜Š

Setting rev: master is no longer supported

Following the readme in this repo, I get the following error:

The 'rev' field of repo 'https://github.com/doublify/pre-commit-rust' appears to be a mutable reference (moving tag / branch). Mutable references are never updated after first install and are not supported. See https://pre-commit.com/#using-the-latest-version-for-a-repository for more details. Hint: pre-commit autoupdate often fixes this.

Doing the recommended step fixes this:

pre-commit autoupdate

Which sets the hook to rev: v1.0 so I guess the readme needs to be updated to include this?

Providing location to Cargo.toml

I have repository that has both Python and Rust code inside.

In the root of the repository I have .pre-commit-config.yaml with:

  -   repo: https://github.com/doublify/pre-commit-rust
      rev: master
      hooks:
        -   id: fmt
            args: ['--manifest-path', 'rust_code/Cargo.toml']

In the rust_code/ folder I have rust code together with Cargo.toml.

However, it looks like the hook expects Cargo.toml to be in the root of the repository and is ignoring arguments.

Error during execution of `cargo metadata`: error: could not find `Cargo.toml` in `D:\projects\project-repo` or any parent directory

What options do I have?

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.