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

Commit 7b0e921

Browse files
authored
Merge pull request #101 from killercup/json-tool
Add a simple tool that applies fixes from JSON
2 parents df678eb + c85afe0 commit 7b0e921

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)