Skip to content

Commit

Permalink
save
Browse files Browse the repository at this point in the history
  • Loading branch information
praveenperera committed Feb 2, 2025
1 parent fccb046 commit 25a0d85
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 20 deletions.
16 changes: 9 additions & 7 deletions rustywind-cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,8 @@ fn main() -> Result<()> {
color_eyre::install()?;

let cli = Cli::parse();
let options = Options::new_from_cli(cli)?;
let rustywind = &options.rustywind;
let mut options = Options::new_from_cli(cli)?;
let rustywind = &mut options.rustywind;

match &options.write_mode {
WriteMode::ToStdOut => (),
Expand Down Expand Up @@ -132,10 +132,11 @@ fn main() -> Result<()> {
eprint!("[WARN] No classes were found in STDIN");
}
} else {
options
.search_paths
let search_paths = &options.search_paths.clone();

search_paths
.iter()
.for_each(|file_path| run_on_file_paths(file_path, &options));
.for_each(|file_path| run_on_file_paths(file_path, &mut options));

if EXIT_ERROR.load(Ordering::Relaxed) {
std::process::exit(1);
Expand All @@ -145,15 +146,16 @@ fn main() -> Result<()> {
Ok(())
}

fn run_on_file_paths(file_path: &Path, options: &Options) {
fn run_on_file_paths(file_path: &Path, options: &mut Options) {
// if the file is in the ignored_files list return early
if should_ignore_current_file(&options.ignored_files, file_path) {
log::debug!("file path {file_path:#?} found in ignored_files, will not sort");
return;
}

let rustywind = &options.rustywind;
options.rustywind.check_and_reset_bump();

let rustywind = &options.rustywind;
match rustywind.read_file_contents(file_path) {
Ok(contents) => {
if rustywind.has_classes(&contents) {
Expand Down
24 changes: 11 additions & 13 deletions rustywind-core/src/app.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std::{borrow::Cow, fs::File, io::BufRead as _, path::Path};
use std::{borrow::Cow, fs::File, io::Read as _, path::Path};

Check failure on line 1 in rustywind-core/src/app.rs

View workflow job for this annotation

GitHub Actions / clippy

unused imports: `fs::File` and `io::Read as _`

error: unused imports: `fs::File` and `io::Read as _` --> rustywind-core/src/app.rs:1:24 | 1 | use std::{borrow::Cow, fs::File, io::Read as _, path::Path}; | ^^^^^^^^ ^^^^^^^^^^^^^ | = note: `-D unused-imports` implied by `-D warnings` = help: to override `-D warnings` add `#[allow(unused_imports)]`

Check failure on line 1 in rustywind-core/src/app.rs

View workflow job for this annotation

GitHub Actions / macos (stable, x86_64-apple-darwin)

unused imports: `fs::File` and `io::Read as _`

use crate::{
class_wrapping::ClassWrapping,
Expand Down Expand Up @@ -53,17 +53,15 @@ impl RustyWind {
}
}

/// Read the file contents into a `String`.
pub fn read_file_contents(&self, file_path: &Path) -> eyre::Result<String> {
let file = File::open(file_path)?;
let mut contents = String::new_in(&self.bump);

for line in std::io::BufReader::new(file).lines() {
contents.push_str(&line?);
contents.push('\n');
}
/// Resets if needed the bumpalo allocator
pub fn check_and_reset_bump(&mut self) {
self.bump.reset();
}

Ok(contents)
/// Read the file contents into a `String`.
pub fn read_file_contents(&self, file_path: &Path) -> eyre::Result<std::string::String> {
let file_contents = std::fs::read_to_string(file_path)?;
Ok(file_contents)
}

/// Checks if the file contents have any classes.
Expand Down Expand Up @@ -167,10 +165,10 @@ impl RustyWind {
.collect_in(&self.bump);

// sorted varaints
let mut sorted_variant_classes = Vec::new_in(&bump);
let mut sorted_variant_classes = Vec::new_in(bump);
for key in VARIANTS.iter() {
let (mut sorted_classes, new_custom_classes) = self.sort_variant_classes(
variants.remove(key).unwrap_or_else(|| Vec::new_in(&bump)),
variants.remove(key).unwrap_or_else(|| Vec::new_in(bump)),
custom_classes,
key.len() + 1,
);
Expand Down

0 comments on commit 25a0d85

Please sign in to comment.