Skip to content
This repository was archived by the owner on Nov 24, 2023. It is now read-only.

Commit 0411465

Browse files
authored
Merge pull request #97 from killercup/feature/filter-by-machine-applicability
Filter by machine applicability
2 parents f6e423f + 5e71ec2 commit 0411465

File tree

15 files changed

+99
-31
lines changed

15 files changed

+99
-31
lines changed

cargo-fix/src/cli.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,8 +112,7 @@ pub fn run() -> Result<(), Error> {
112112
//
113113
// TODO: we probably want to do something fancy here like collect results
114114
// from the client processes and print out a summary of what happened.
115-
let status = cmd
116-
.status()
115+
let status = cmd.status()
117116
.with_context(|e| format!("failed to execute `{}`: {}", cargo.to_string_lossy(), e))?;
118117
exit_with(status);
119118
}

cargo-fix/src/main.rs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,9 @@ use std::str;
2121

2222
use failure::{Error, ResultExt};
2323
use rustfix::diagnostics::Diagnostic;
24-
use termcolor::{ColorSpec, WriteColor, Color};
24+
use termcolor::{Color, ColorSpec, WriteColor};
2525

26-
use diagnostics::{Message, output_stream};
26+
use diagnostics::{output_stream, Message};
2727

2828
mod cli;
2929
mod diagnostics;
@@ -174,6 +174,10 @@ fn rustfix_crate(rustc: &Path, filename: &str) -> Result<FixedCrate, Error> {
174174
return Ok(Default::default());
175175
}
176176

177+
let fix_mode = env::var_os("__CARGO_FIX_YOLO")
178+
.map(|_| rustfix::Filter::Everything)
179+
.unwrap_or(rustfix::Filter::MachineApplicableOnly);
180+
177181
// Sift through the output of the compiler to look for JSON messages
178182
// indicating fixes that we can apply.
179183
let stderr = str::from_utf8(&output.stderr).context("failed to parse rustc stderr as utf-8")?;
@@ -185,7 +189,7 @@ fn rustfix_crate(rustc: &Path, filename: &str) -> Result<FixedCrate, Error> {
185189
.filter_map(|line| serde_json::from_str::<Diagnostic>(line).ok())
186190

187191
// From each diagnostic try to extract suggestions from rustc
188-
.filter_map(|diag| rustfix::collect_suggestions(&diag, &only));
192+
.filter_map(|diag| rustfix::collect_suggestions(&diag, &only, fix_mode));
189193

190194
// Collect suggestions by file so we can apply them one at a time later.
191195
let mut file_map = HashMap::new();

cargo-fix/tests/all/broken_build.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,10 @@ fn fix_broken_if_requested() {
3636
)
3737
.build();
3838

39-
p.expect_cmd("cargo-fix fix --broken-code").status(0).run();
39+
p.expect_cmd("cargo-fix fix --broken-code")
40+
.fix_everything()
41+
.status(0)
42+
.run();
4043
}
4144

4245
#[test]
@@ -111,6 +114,7 @@ fn broken_fixes_backed_out() {
111114

112115
// Attempt to fix code, but our shim will always fail the second compile
113116
p.expect_cmd("cargo-fix fix")
117+
.fix_everything()
114118
.cwd("bar")
115119
.env("RUSTC", p.root.join("foo/target/debug/foo"))
116120
.stderr_contains("not rust code")

cargo-fix/tests/all/broken_lints.rs

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -19,21 +19,18 @@
1919
// .build();
2020

2121
// p.expect_cmd("cargo-fix fix")
22+
// .fix_everything()
2223
// .stderr_contains(r"warning: error applying suggestions to `src/lib.rs`")
2324
// .stderr_contains("The full error message was:")
24-
// .stderr_contains(
25-
// "> Could not replace range 56...60 in file -- maybe parts of it were already replaced?",
26-
// )
27-
// .stderr_contains(
28-
// "\
29-
// This likely indicates a bug in either rustc or rustfix itself,\n\
30-
// and we would appreciate a bug report! You're likely to see \n\
31-
// a number of compiler warnings after this message which rustfix\n\
32-
// attempted to fix but failed. If you could open an issue at\n\
33-
// https://github.com/rust-lang-nursery/rustfix/issues\n\
34-
// quoting the full output of this command we'd be very appreciative!\n\n\
35-
// ",
36-
// )
25+
// .stderr_contains("> Could not replace range 56...60 in file -- maybe parts of it were already replaced?")
26+
// .stderr_contains("\
27+
// This likely indicates a bug in either rustc or rustfix itself,\n\
28+
// and we would appreciate a bug report! You're likely to see \n\
29+
// a number of compiler warnings after this message which rustfix\n\
30+
// attempted to fix but failed. If you could open an issue at\n\
31+
// https://github.com/rust-lang-nursery/rustfix/issues\n\
32+
// quoting the full output of this command we'd be very appreciative!\n\n\
33+
// ")
3734
// .status(0)
3835
// .run();
3936
// }

cargo-fix/tests/all/dependencies.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ fn fix_path_deps() {
5454
[FINISHED] dev [unoptimized + debuginfo]
5555
";
5656
p.expect_cmd("cargo-fix fix")
57+
.fix_everything()
5758
.stdout("")
5859
.stderr(stderr)
5960
.run();

cargo-fix/tests/all/edition_upgrade.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,7 @@ fn upgrade_extern_crate() {
161161
[FINISHED] dev [unoptimized + debuginfo]
162162
";
163163
p.expect_cmd("cargo-fix fix")
164+
.fix_everything()
164165
.stdout("")
165166
.stderr(stderr)
166167
.run();

cargo-fix/tests/all/main.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,11 @@ impl<'a> ExpectCmd<'a> {
151151
self
152152
}
153153

154+
fn fix_everything(&mut self) -> &mut Self {
155+
self.env("__CARGO_FIX_YOLO", "true");
156+
self
157+
}
158+
154159
fn stdout(&mut self, s: &str) -> &mut Self {
155160
self.stdout = Some(s.to_string());
156161
self

cargo-fix/tests/all/smoke.rs

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ fn fixes_extra_mut() {
3434
[FINISHED] dev [unoptimized + debuginfo]
3535
";
3636
p.expect_cmd("cargo-fix fix")
37+
.fix_everything()
3738
.stdout("")
3839
.stderr(stderr)
3940
.run();
@@ -60,6 +61,7 @@ fn fixes_two_missing_ampersands() {
6061
[FINISHED] dev [unoptimized + debuginfo]
6162
";
6263
p.expect_cmd("cargo-fix fix")
64+
.fix_everything()
6365
.stdout("")
6466
.stderr(stderr)
6567
.run();
@@ -85,6 +87,7 @@ fn tricky() {
8587
[FINISHED] dev [unoptimized + debuginfo]
8688
";
8789
p.expect_cmd("cargo-fix fix")
90+
.fix_everything()
8891
.stdout("")
8992
.stderr(stderr)
9093
.run();
@@ -102,7 +105,9 @@ fn preserve_line_endings() {
102105
)
103106
.build();
104107

105-
p.expect_cmd("cargo-fix fix").run();
108+
p.expect_cmd("cargo-fix fix")
109+
.fix_everything()
110+
.run();
106111
assert!(p.read("src/lib.rs").contains("\r\n"));
107112
}
108113

@@ -118,7 +123,9 @@ fn fix_deny_warnings() {
118123
)
119124
.build();
120125

121-
p.expect_cmd("cargo-fix fix").run();
126+
p.expect_cmd("cargo-fix fix")
127+
.fix_everything()
128+
.run();
122129
}
123130

124131
#[test]
@@ -139,7 +146,9 @@ fn fix_deny_warnings_but_not_others() {
139146
)
140147
.build();
141148

142-
p.expect_cmd("cargo-fix fix").run();
149+
p.expect_cmd("cargo-fix fix")
150+
.fix_everything()
151+
.run();
143152
assert!(!p.read("src/lib.rs").contains("let mut x = 3;"));
144153
assert!(p.read("src/lib.rs").contains("fn bar() {}"));
145154
}
@@ -170,6 +179,7 @@ fn fix_two_files() {
170179
.build();
171180

172181
p.expect_cmd("cargo-fix fix")
182+
.fix_everything()
173183
.stderr_contains("[FIXING] src/bar.rs (1 fix)")
174184
.stderr_contains("[FIXING] src/lib.rs (1 fix)")
175185
.run();

cargo-fix/tests/all/subtargets.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ fn fixes_missing_ampersand() {
4040
.build();
4141

4242
p.expect_cmd("cargo fix -- --all-targets")
43+
.fix_everything()
4344
.stdout("")
4445
.stderr_contains("[COMPILING] foo v0.1.0 (CWD)")
4546
.stderr_contains("[FIXING] build.rs (1 fix)")

cargo-fix/tests/all/vcs.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,5 +71,8 @@ fn does_not_warn_about_clean_working_directory() {
7171
.run();
7272
p.expect_cmd("git config user.name RustFix").run();
7373
p.expect_cmd("git commit -m Initial-commit").run();
74-
p.expect_cmd("cargo-fix fix").check_vcs(true).status(0).run();
74+
p.expect_cmd("cargo-fix fix")
75+
.check_vcs(true)
76+
.status(0)
77+
.run();
7578
}

0 commit comments

Comments
 (0)