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

Commit c85afe0

Browse files
committed
Add a simple tool that applies fixes from JSON
Useful when you can get rustc to emit JSON but don't want to/can't use `cargo fix` directly. Currently only supports a single source file but it's easy to extend.
1 parent df678eb commit c85afe0

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

examples/fix-json.rs

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
extern crate failure;
2+
extern crate rustfix;
3+
4+
use std::{env, fs, process, collections::HashSet};
5+
use failure::Error;
6+
7+
fn main() -> Result<(), Error> {
8+
let args: Vec<String> = env::args().collect();
9+
let (suggestions_file, source_file) = match args.as_slice() {
10+
[_, suggestions_file, source_file] => (suggestions_file, source_file),
11+
_ => {
12+
println!("USAGE: fix-json <suggestions-file> <source-file>");
13+
process::exit(1);
14+
}
15+
};
16+
17+
let suggestions = fs::read_to_string(&suggestions_file)?;
18+
let suggestions = rustfix::get_suggestions_from_json(&suggestions, &HashSet::new())?;
19+
20+
let source = fs::read_to_string(&source_file)?;
21+
22+
let fixes = rustfix::apply_suggestions(&source, &suggestions)?;
23+
24+
println!("{}", fixes);
25+
26+
Ok(())
27+
}

0 commit comments

Comments
 (0)