Skip to content

Commit

Permalink
Fix pedantic clippy
Browse files Browse the repository at this point in the history
  • Loading branch information
chriscerie committed Nov 11, 2023
1 parent 0055e2c commit 038e062
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 5 deletions.
9 changes: 6 additions & 3 deletions selene-lib/src/lints.rs
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ impl Diagnostic {
if suggestion_str.is_empty() {
"consider removing this".to_string()
} else {
format!("try: `{}`", suggestion_str)
format!("try: `{suggestion_str}`")
},
);
}
Expand Down Expand Up @@ -196,28 +196,31 @@ impl Diagnostic {
}
}

#[must_use]
pub fn start_position(&self) -> u32 {
self.primary_label.range.0
}

#[must_use]
pub fn has_machine_applicable_fix(&self) -> bool {
self.suggestion.is_some() && self.applicability == Applicability::MachineApplicable
}

#[must_use]
pub fn has_maybe_incorrect_fix(&self) -> bool {
self.suggestion.is_some() && self.applicability == Applicability::MaybeIncorrect
}

/// After applying suggestions, calls `get_new_diagnostics` and reruns to ensure fixes didn't produce new errors
pub fn get_applied_suggestions_code<F>(
code: &str,
diagnostics: Vec<&Diagnostic>,
diagnostics: &[&Diagnostic],
get_new_diagnostics: F,
) -> String
where
F: Fn(&str) -> Vec<Diagnostic>,
{
let mut chosen_diagnostics = Self::get_independent_suggestions(&diagnostics);
let mut chosen_diagnostics = Self::get_independent_suggestions(diagnostics);
let mut owned_diagnostics_ref;
let mut owned_diagnostics;

Expand Down
2 changes: 1 addition & 1 deletion selene-lib/src/lints/test_util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ pub fn test_lint_config_with_output<

suggestion = Diagnostic::get_applied_suggestions_code(
suggestion.as_str(),
fixed_diagnostics,
&fixed_diagnostics,
|new_code| {
let fixed_ast = full_moon::parse(new_code).unwrap_or_else(|_| {
panic!(
Expand Down
2 changes: 1 addition & 1 deletion selene/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,7 @@ fn read<R: Read>(

suggestion = Diagnostic::get_applied_suggestions_code(
suggestion.as_str(),
diagnostics
&diagnostics
.iter()
.filter(|diagnostic| diagnostic.diagnostic.has_machine_applicable_fix())
.map(|diagnostic| &diagnostic.diagnostic)
Expand Down

0 comments on commit 038e062

Please sign in to comment.