Skip to content

Commit

Permalink
refactor: make clippy happy
Browse files Browse the repository at this point in the history
  • Loading branch information
max397574 committed Jan 31, 2023
1 parent daa8f4a commit 5e1558d
Showing 1 changed file with 7 additions and 17 deletions.
24 changes: 7 additions & 17 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ fn main() {

let path = Path::new(&args.file).to_owned();
if path.is_file() {
// let file = File::open(path).expect("Unable to open the file");
format_file(&path, parser, args);
} else if path.is_dir() {
let languages = read_dir(path).unwrap();
Expand Down Expand Up @@ -84,8 +83,6 @@ fn main() {

let language = unsafe { tree_sitter_query() };
parser.set_language(language).unwrap();
// let file = File::open(file_path.path().as_path())
// .expect("Unable to open the file");
format_file(file_path.path().as_path(), parser, args);
}
}
Expand All @@ -94,7 +91,7 @@ fn main() {
if file_path.is_file() {
let file_path = file_path.as_path();
if file_path.parent().unwrap().parent().unwrap() == Path::new("queries") {
println!("{:?}", file_path);
println!("{file_path:?}");
let args = Args::parse();

let mut parser = Parser::new();
Expand All @@ -104,7 +101,6 @@ fn main() {

let language = unsafe { tree_sitter_query() };
parser.set_language(language).unwrap();
// let file = File::open(file_path).expect("Unable to open the file");
format_file(file_path, parser, args);
}
}
Expand All @@ -119,7 +115,7 @@ fn format_file(path: &Path, mut parser: Parser, args: Args) {
file.read_to_string(&mut contents)
.expect("Unable to read the file");
let source_code = &contents;
let original_len = get_len(&source_code);
let original_len = get_len(source_code);
let tree = parser.parse(source_code, None).unwrap();
let mut comment_before = false;
let mut output = String::new();
Expand Down Expand Up @@ -213,17 +209,11 @@ fn format_file(path: &Path, mut parser: Parser, args: Args) {
Not applying formatting.
Open an issue."
);
} else {
if args.preview {
println!("{output}");
} else if !args.preview {
let mut new_file = File::create(path).expect("Unable to open the file");
writeln!(&mut new_file, "{}", output).unwrap();
// match file.write(output.as_bytes()) {
// Ok(..) => {}
// Err(e) => println!("{:#?}", e),
// }
}
} else if args.preview {
println!("{output}");
} else if !args.preview {
let mut new_file = File::create(path).expect("Unable to open the file");
writeln!(&mut new_file, "{output}").unwrap();
}
}

Expand Down

0 comments on commit 5e1558d

Please sign in to comment.