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

Add a simple tool that applies fixes from JSON #101

Merged
merged 1 commit into from
May 13, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions examples/fix-json.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
extern crate failure;
extern crate rustfix;

use std::{env, fs, process, collections::HashSet};
use failure::Error;

fn main() -> Result<(), Error> {
let args: Vec<String> = env::args().collect();
let (suggestions_file, source_file) = match args.as_slice() {
[_, suggestions_file, source_file] => (suggestions_file, source_file),
_ => {
println!("USAGE: fix-json <suggestions-file> <source-file>");
process::exit(1);
}
};

let suggestions = fs::read_to_string(&suggestions_file)?;
let suggestions = rustfix::get_suggestions_from_json(&suggestions, &HashSet::new())?;

let source = fs::read_to_string(&source_file)?;

let fixes = rustfix::apply_suggestions(&source, &suggestions)?;

println!("{}", fixes);

Ok(())
}