Skip to content

Commit 37ec89f

Browse files
committed
Lintcheck: Fix lintcheck --fix
1 parent 345c94c commit 37ec89f

File tree

4 files changed

+36
-9
lines changed

4 files changed

+36
-9
lines changed

lintcheck/src/config.rs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,13 @@ pub(crate) struct LintcheckConfig {
3030
/// Only process a single crate on the list
3131
#[clap(long, value_name = "CRATE")]
3232
pub only: Option<String>,
33-
/// Runs cargo clippy --fix and checks if all suggestions apply
34-
#[clap(long, conflicts_with("max_jobs"))]
33+
/// Runs cargo clippy --fix and checks if all suggestions apply.
34+
#[clap(
35+
long,
36+
conflicts_with("max_jobs"),
37+
conflicts_with("warn_all"),
38+
conflicts_with("recursive")
39+
)]
3540
pub fix: bool,
3641
/// Apply a filter to only collect specified lints, this also overrides `allow` attributes
3742
#[clap(long = "filter", value_name = "clippy_lint_name", use_value_delimiter = true)]

lintcheck/src/input.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ impl CrateWithSource {
180180
/// copies a local folder
181181
#[expect(clippy::too_many_lines)]
182182
fn download_and_extract(&self) -> Crate {
183-
#[allow(clippy::result_large_err)]
183+
#[expect(clippy::result_large_err)]
184184
fn get(path: &str) -> Result<ureq::Response, ureq::Error> {
185185
const MAX_RETRIES: u8 = 4;
186186
let mut retries = 0;

lintcheck/src/main.rs

Lines changed: 27 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -116,11 +116,36 @@ impl Crate {
116116
clippy_args.extend(lint_levels_args.iter().map(String::as_str));
117117

118118
let mut cmd = Command::new("cargo");
119-
cmd.arg(if config.fix { "fix" } else { "check" })
120-
.arg("--quiet")
119+
120+
if config.fix {
121+
cmd.arg("fix");
122+
cmd.arg("--allow-no-vcs");
123+
// Fix should never be run in combination with `--recursive`. This
124+
// should never happen as the CLI flags conflict, but you know life.
125+
assert!(
126+
server.is_none(),
127+
"--fix was combined with `--recursive`. Server: {server:#?}"
128+
);
129+
} else {
130+
cmd.arg("check");
131+
cmd.arg("--message-format=json");
132+
}
133+
134+
// It turns out that `cargo fix` by default runs all tests, benchmarks,
135+
// and examples. This is different from `cargo check` which only runs the
136+
// main packages. The `--tests` works for both `cargo fix` and `cargo check`
137+
// to indicate that only the main packages and tests should be processed.
138+
// This unifies the behavior between the different lintcheck modes.
139+
//
140+
// It also makes sense to include tests either way, since some Clippy lints
141+
// have custom behavior in test code.
142+
cmd.arg("--tests");
143+
144+
cmd.arg("--quiet")
121145
.current_dir(&self.path)
122146
.env("CLIPPY_ARGS", clippy_args.join("__CLIPPY_HACKERY__"));
123147

148+
// This is only used for `--recursive`
124149
if let Some(server) = server {
125150
// `cargo clippy` is a wrapper around `cargo check` that mainly sets `RUSTC_WORKSPACE_WRAPPER` to
126151
// `clippy-driver`. We do the same thing here with a couple changes:
@@ -145,10 +170,6 @@ impl Crate {
145170
return Vec::new();
146171
};
147172

148-
if !config.fix {
149-
cmd.arg("--message-format=json");
150-
}
151-
152173
let shared_target_dir = shared_target_dir(&format!("_{thread_index:?}"));
153174
let all_output = cmd
154175
// use the looping index to create individual target dirs

lintcheck/src/recursive.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ fn process_stream(
7979
}
8080
}
8181

82+
#[derive(Debug)]
8283
pub(crate) struct LintcheckServer {
8384
pub local_addr: SocketAddr,
8485
receiver: Receiver<ClippyWarning>,

0 commit comments

Comments
 (0)