Skip to content

Commit

Permalink
Fix clippy
Browse files Browse the repository at this point in the history
  • Loading branch information
chriscerie committed Oct 14, 2023
1 parent c49e080 commit 63ad3eb
Showing 1 changed file with 15 additions and 14 deletions.
29 changes: 15 additions & 14 deletions selene/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ fn replace_code_range(code: &str, start: usize, end: usize, replacement: &str) -
return code.to_string();
}

return format!("{}{}{}", &code[..start], replacement, &code[end..]);
format!("{}{}{}", &code[..start], replacement, &code[end..])
}

/// Assumes diagnostics is sorted by starting positions
Expand Down Expand Up @@ -226,9 +226,9 @@ fn apply_diagnostics_fixes(code: &str, diagnostics: &Vec<&Diagnostic>) -> String
let (start, end) = diagnostic.primary_label.range;
let new_code = replace_code_range(
code.as_str(),
(start as isize + bytes_offset as isize) as usize,
(end as isize + bytes_offset as isize) as usize,
&fixed.as_str(),
(start as isize + bytes_offset) as usize,
(end as isize + bytes_offset) as usize,
fixed.as_str(),
);

bytes_offset += fixed.len() as isize - (end - start) as isize;
Expand Down Expand Up @@ -591,15 +591,16 @@ fn start(mut options: opts::Options) {
None => {}
}

if options.fix && !options.allow_dirty {
if has_unstaged_changes() || (!options.allow_staged && has_staged_changes()) {
error(
"the working directory of this package has uncommitted changes, and `selene --fix` can potentially \
perform destructive changes; if you'd like to suppress this error pass `--allow-dirty`, `--allow-staged`, \
or commit the changes"
);
std::process::exit(1);
}
if options.fix
&& !options.allow_dirty
&& (has_unstaged_changes() || (!options.allow_staged && has_staged_changes()))
{
error(
"the working directory of this package has uncommitted changes, and `selene --fix` can potentially \
perform destructive changes; if you'd like to suppress this error pass `--allow-dirty`, `--allow-staged`, \
or commit the changes"
);
std::process::exit(1);
}

let (config, config_directory): (CheckerConfig<toml::value::Value>, Option<PathBuf>) =
Expand Down Expand Up @@ -900,7 +901,7 @@ fn has_staged_changes() -> bool {

let stdout = String::from_utf8(output.stdout).expect("Failed to convert git output to string");

stdout.lines().any(|line| line.chars().nth(0) != Some(' '))
stdout.lines().any(|line| !line.starts_with(' '))
}

#[cfg(feature = "roblox")]
Expand Down

0 comments on commit 63ad3eb

Please sign in to comment.