Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Suggestion: run clippy for specific package in workspace #2518

Closed
bjgill opened this issue Mar 9, 2018 · 6 comments
Closed

Suggestion: run clippy for specific package in workspace #2518

bjgill opened this issue Mar 9, 2018 · 6 comments
Assignees

Comments

@bjgill
Copy link
Contributor

bjgill commented Mar 9, 2018

We now have the --all option, and this is very helpful when testing a workspace.

However, when developing, it would be convenient to be able to run clippy over only a specified package in the workspace. i.e. similar to the cargo test option -p SPEC, --package SPEC ... Package to run tests for.

Unless anyone objects, I'll have a look at implementing this - it should be a fairly simple extension of the current handling for --all.

@bjgill
Copy link
Contributor Author

bjgill commented Mar 19, 2018

I've started prototyping. It looks as if cargo is busy transitioning over to use clap - see rust-lang/cargo#4177. Do we want to do the same?

I think we would end up with a help message like that below (c.f. the current one at https://github.com/rust-lang-nursery/rust-clippy/blob/master/src/main.rs#L14).

Thoughts? It'll be a minor functional change (you can no longer specify --all anywhere - it must be at the start), and the help message will look different (though I could probably retain the old look if that is desirable). We'll gain, however, since main.rs will no longer need to parse the contents of std::env::args(), instead relying on clap.

Clippy 0.0.188
Checks a package to catch common mistakes and improve your Rust code.

USAGE:
    cargo-clippy [OPTIONS] [--] [CMD]...

OPTIONS:
        --all                  Run over all packages in the current workspace
    -h, --help                 Prints help information
    -p, --package <SPEC>...    Package(s) to check
    -V, --version              Prints version information

ARGS:
    <CMD>...    Commands to pass through to cargo rustc

Other options are the same as `cargo rustc`.

To allow or deny a lint from the command line you can use `cargo clippy --`
with:

    -W --warn OPT       Set lint warnings
    -A --allow OPT      Set lint allowed
    -D --deny OPT       Set lint denied
    -F --forbid OPT     Set lint forbidden

The feature `cargo-clippy` is automatically defined for convenience. You can use
it to allow or deny lints from the code, eg.:

    #[cfg_attr(feature = "cargo-clippy", allow(needless_lifetimes))]

@oli-obk
Copy link
Contributor

oli-obk commented Mar 19, 2018

yes please! no more args parsing!

bjgill added a commit to bjgill/rust-clippy that referenced this issue Mar 20, 2018
It saves us from having to parse std::env::args manually, though at the
cost of mandating that --all/--manifest-path come before any other
arguments. Will make adding additional clippy-specific args easier - see rust-lang#2518
bjgill added a commit to bjgill/rust-clippy that referenced this issue Mar 28, 2018
Now that we're using cargo check, we can stop needing to find out the
manifest path ourselves. Instead, we can delegate to cargo check, which
is perfectly capable of working out for itself what needs to be built.

This fixes rust-lang#1707 and rust-lang#2518.

Note that this PR will change the output. We will no longer output `bin:
foo` before each crate. This a bit unfortunate. However, given that
we're now going to be building in parallel (which is *much* faster), I
think this is acceptable - we'll be no worse than cargo itself.
@mimoo
Copy link

mimoo commented Oct 14, 2020

not sure why this was closed, it looks like you still can't run clippy on a specific package in your workspace

@ebroto
Copy link
Member

ebroto commented Oct 14, 2020

@mimoo could you share an example of what does not work for you? cargo clippy -p <package> should work with both simple and virtual workspaces.

If you refer to the ability of running Clippy only on the package, excluding its dependencies (#3025), that will be fixed in a couple of days after rust-lang/cargo#8758 is merged.

@mimoo
Copy link

mimoo commented Oct 15, 2020

Ah, indeed I was getting hits on its dependencies (which are other packages in my workspace) and didn't understand why

@mleonhard
Copy link

If one package depends on another package the workspace, clippy will still check the extra package. To avoid that, pass the --no-deps flag (recently added). With this flag, you can even run clippy in the crate directory and it will check only that crate:

$ cd workspace1/crate1/
$ cargo clippy --all-features -- -D clippy::pedantic --no-deps

If you run clippy as part of a script that runs other cargo commands, clippy may just exit right away without reporting any errors. The workaround is to clean the package just before running clippy:

$ cd workspace1/crate1/
$ cargo clean --package "$(basename "$PWD")"
$ cargo clippy --all-features -- -D clippy::pedantic --no-deps

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants