Skip to content

Commit

Permalink
Auto merge of rust-lang#6884 - matthiaskrgr:lintcheck_crate, r=Manish…
Browse files Browse the repository at this point in the history
…earth

move lintcheck into its own crate

This pr:
* moves lintcheck out of `clippy dev` and into its own crate (`lintcheck`)  (I should have done this earlier :D)
* makes lintcheck terminate if it is not launched from the repo root (to prevent problems with wrong paths when using `cargo run` in the crate root)
* fixes json lint messages leaking the runners `$HOME` when a lint messages comes from a proc macro that originates from a crate inside the `$CARGO_CACHE`
* adds more documentation to lintchecks `README.md` and mentions lintcheck in `docs/basics.md`

changelog: none
  • Loading branch information
bors committed Mar 11, 2021
2 parents 99afc6e + 0af90fd commit 534a13d
Show file tree
Hide file tree
Showing 13 changed files with 475 additions and 234 deletions.
2 changes: 1 addition & 1 deletion .cargo/config
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[alias]
uitest = "test --test compile-test"
dev = "run --target-dir clippy_dev/target --package clippy_dev --bin clippy_dev --manifest-path clippy_dev/Cargo.toml --"
dev-lintcheck = "run --target-dir clippy_dev/target --package clippy_dev --bin clippy_dev --manifest-path clippy_dev/Cargo.toml --features lintcheck -- lintcheck"
lintcheck = "run --target-dir lintcheck/target --package lintcheck --bin lintcheck --manifest-path lintcheck/Cargo.toml -- "

[build]
rustflags = ["-Zunstable-options"]
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ out
/clippy_utils/target
/clippy_workspace_tests/target
/clippy_dev/target
/lintcheck/target
/rustc_tools_util/target

# Generated by dogfood
Expand Down
9 changes: 0 additions & 9 deletions clippy_dev/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,11 @@ edition = "2018"
[dependencies]
bytecount = "0.6"
clap = "2.33"
flate2 = { version = "1.0.19", optional = true }
fs_extra = { version = "1.2.0", optional = true }
itertools = "0.9"
opener = "0.4"
regex = "1"
serde = { version = "1.0", features = ["derive"], optional = true }
serde_json = { version = "1.0", optional = true }
shell-escape = "0.1"
tar = { version = "0.4.30", optional = true }
toml = { version = "0.5", optional = true }
ureq = { version = "2.0.0-rc3", optional = true }
rayon = { version = "1.5.0", optional = true }
walkdir = "2"

[features]
lintcheck = ["flate2", "serde_json", "tar", "toml", "ureq", "serde", "fs_extra", "rayon"]
deny-warnings = []
1 change: 1 addition & 0 deletions clippy_dev/src/fmt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ pub fn run(check: bool, verbose: bool) {
success &= cargo_fmt(context, project_root.as_path())?;
success &= cargo_fmt(context, &project_root.join("clippy_dev"))?;
success &= cargo_fmt(context, &project_root.join("rustc_tools_util"))?;
success &= cargo_fmt(context, &project_root.join("lintcheck"))?;

for entry in WalkDir::new(project_root.join("tests")) {
let entry = entry?;
Expand Down
1 change: 0 additions & 1 deletion clippy_dev/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ use walkdir::WalkDir;

pub mod bless;
pub mod fmt;
pub mod lintcheck;
pub mod new_lint;
pub mod ra_setup;
pub mod serve;
Expand Down
45 changes: 3 additions & 42 deletions clippy_dev/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,13 @@

use clap::{App, Arg, ArgMatches, SubCommand};
use clippy_dev::{bless, fmt, new_lint, ra_setup, serve, stderr_length_check, update_lints};

#[cfg(feature = "lintcheck")]
use clippy_dev::lintcheck;

fn main() {
let matches = get_clap_config();

match matches.subcommand() {
("bless", Some(matches)) => {
bless::bless(matches.is_present("ignore-timestamp"));
},
#[cfg(feature = "lintcheck")]
("lintcheck", Some(matches)) => {
lintcheck::run(&matches);
},
("fmt", Some(matches)) => {
fmt::run(matches.is_present("check"), matches.is_present("verbose"));
},
Expand Down Expand Up @@ -53,34 +45,7 @@ fn main() {
}

fn get_clap_config<'a>() -> ArgMatches<'a> {
#[cfg(feature = "lintcheck")]
let lintcheck_sbcmd = SubCommand::with_name("lintcheck")
.about("run clippy on a set of crates and check output")
.arg(
Arg::with_name("only")
.takes_value(true)
.value_name("CRATE")
.long("only")
.help("only process a single crate of the list"),
)
.arg(
Arg::with_name("crates-toml")
.takes_value(true)
.value_name("CRATES-SOURCES-TOML-PATH")
.long("crates-toml")
.help("set the path for a crates.toml where lintcheck should read the sources from"),
)
.arg(
Arg::with_name("threads")
.takes_value(true)
.value_name("N")
.short("j")
.long("jobs")
.help("number of threads to use, 0 automatic choice"),
)
.arg(Arg::with_name("fix").help("runs cargo clippy --fix and checks if all suggestions apply"));

let app = App::new("Clippy developer tooling")
App::new("Clippy developer tooling")
.subcommand(
SubCommand::with_name("bless")
.about("bless the test output changes")
Expand Down Expand Up @@ -197,10 +162,6 @@ fn get_clap_config<'a>() -> ArgMatches<'a> {
.validator_os(serve::validate_port),
)
.arg(Arg::with_name("lint").help("Which lint's page to load initially (optional)")),
);

#[cfg(feature = "lintcheck")]
let app = app.subcommand(lintcheck_sbcmd);

app.get_matches()
)
.get_matches()
}
13 changes: 12 additions & 1 deletion doc/basics.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,9 @@ the codebase take a look at [Adding Lints] or [Common Tools].
- [Get the Code](#get-the-code)
- [Building and Testing](#building-and-testing)
- [`cargo dev`](#cargo-dev)
- [Common Abbreviations](#common-abbreviations)
- [lintcheck](#lintcheck)
- [PR](#pr)
- [Common Abbreviations](#common-abbreviations)

## Get the Code

Expand Down Expand Up @@ -91,6 +92,16 @@ cargo dev new_lint
cargo dev ra_setup
```

## lintcheck
`cargo lintcheck` will build and run clippy on a fixed set of crates and generate a log of the results.
You can `git diff` the updated log against its previous version and
see what impact your lint made on a small set of crates.
If you add a new lint, please audit the resulting warnings and make sure
there are no false positives and that the suggestions are valid.

Refer to the tools [README] for more details.

[README]: https://github.com/rust-lang/rust-clippy/blob/master/lintcheck/README.md
## PR

We follow a rustc no merge-commit policy.
Expand Down
Loading

0 comments on commit 534a13d

Please sign in to comment.