@@ -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
0 commit comments