fix(rust): address new lints

This commit is contained in:
Will Lillis 2025-10-12 03:59:34 -04:00
parent 19b4b7f0e3
commit 8ced5059b4
No known key found for this signature in database
13 changed files with 40 additions and 35 deletions

View file

@ -40,7 +40,7 @@ pub async fn check_directories(
directories
};
let workspace = workspace
.unwrap_or(env::current_dir().expect("Failed to get current directory"))
.unwrap_or_else(|| env::current_dir().expect("Failed to get current directory"))
.canonicalize()
.expect("Workspace path should be valid");
let workspace = Arc::new(workspace);

View file

@ -20,7 +20,7 @@ use crate::{
};
#[derive(Debug, Copy, Clone)]
pub(crate) struct LintOptions {
pub struct LintOptions {
pub fix: bool,
pub ignore_missing_language: bool,
}
@ -101,7 +101,8 @@ pub(super) async fn lint_file(
else {
continue;
};
let Some(mut changes) = edit.changes.and_then(|mut changes| changes.remove(&uri)) else {
let Some(mut changes) = edit.changes.and_then(|mut changes| changes.remove(&uri))
else {
continue;
};
edits.append(&mut changes);
@ -181,7 +182,7 @@ pub async fn lint_directories(
directories
};
let workspace = workspace
.unwrap_or(env::current_dir().expect("Failed to get current directory"))
.unwrap_or_else(|| env::current_dir().expect("Failed to get current directory"))
.canonicalize()
.expect("Workspace path should be valid");
let workspace = Arc::new(workspace);

View file

@ -1,4 +1,4 @@
pub(super) mod check;
pub(super) mod format;
pub(super) mod lint;
pub(super) mod profile;
pub mod check;
pub mod format;
pub mod lint;
pub mod profile;

View file

@ -35,7 +35,7 @@ impl From<CodeActions> for serde_json::Value {
impl From<CodeActions> for u8 {
fn from(e: CodeActions) -> Self {
e as u8
e as Self
}
}
@ -44,11 +44,11 @@ impl TryFrom<u8> for CodeActions {
fn try_from(value: u8) -> std::result::Result<Self, Self::Error> {
match value {
0 => Ok(CodeActions::RemoveBackslash),
1 => Ok(CodeActions::PrefixUnderscore),
2 => Ok(CodeActions::Remove),
3 => Ok(CodeActions::Trim),
4 => Ok(CodeActions::Enquote),
0 => Ok(Self::RemoveBackslash),
1 => Ok(Self::PrefixUnderscore),
2 => Ok(Self::Remove),
3 => Ok(Self::Trim),
4 => Ok(Self::Enquote),
_ => Err("Invalid value"),
}
}

View file

@ -66,6 +66,7 @@ pub async fn completion<C: LspClient>(
insert_text_format: Some(InsertTextFormat::SNIPPET),
text_edit: Some(CompletionTextEdit::Edit(TextEdit {
range: Range::new(Position::new(0, 0), Position::new(0, line_len)),
#[allow(clippy::literal_string_with_formatting_args)]
new_text: String::from("; inherits: ${1:foo}"),
})),
..Default::default()
@ -743,6 +744,7 @@ mod test {
insert_text_format: Some(InsertTextFormat::SNIPPET),
text_edit: Some(CompletionTextEdit::Edit(TextEdit {
range: Range { start: Position { line: 0, character: 24 }, end: Position { line: 0, character: 25 } },
#[allow(clippy::literal_string_with_formatting_args)]
new_text: String::from("#set! ${1:text} ${2:text}") })),
..Default::default()
},
@ -824,6 +826,7 @@ the `inherits:` keyword, and there must be no spaces in-between module names.
insert_text_format: Some(InsertTextFormat::SNIPPET),
text_edit: Some(CompletionTextEdit::Edit(TextEdit {
range: Range::new(Position::new(0, 0), Position::new(0, 6)),
#[allow(clippy::literal_string_with_formatting_args)]
new_text: String::from("; inherits: ${1:foo}"),
})),
..Default::default()

View file

@ -1,5 +1,4 @@
use std::collections::HashSet;
use std::ops::Deref as _;
use std::sync::LazyLock;
use regex::Regex;
@ -328,7 +327,7 @@ fn handle_predicate(
};
for arg in &args[1..] {
if let QueryPredicateArg::String(kind) = arg
&& node_type == kind.deref()
&& node_type == &**kind
{
return false;
}

View file

@ -22,9 +22,11 @@ pub async fn initialize<C: LspClient>(
);
} else if let Some(root_uri) = params
.root_uri
.or(params
.root_path
.and_then(|p| Url::from_str(p.as_str()).ok()))
.or_else(|| {
params
.root_path
.and_then(|p| Url::from_str(p.as_str()).ok())
})
.and_then(|uri| uri.to_file_path().ok())
{
ws_uris.push(root_uri);

View file

@ -193,7 +193,7 @@ mod test {
name: String::from("@fold.imports"),
kind: SymbolKind::VARIABLE,
location: Location {
uri: cpp_folds_uri.clone(),
uri: cpp_folds_uri,
range: make_range(2, 20, 2, 33),
},
deprecated: None,
@ -226,7 +226,7 @@ mod test {
name: String::from("@constant"),
kind: SymbolKind::VARIABLE,
location: Location {
uri: other_highlights_uri.clone(),
uri: other_highlights_uri,
range: make_range(13, 2, 13, 11),
},
deprecated: None,

View file

@ -31,7 +31,7 @@ struct PredicateAux {
any: bool,
}
fn default_true() -> bool {
const fn default_true() -> bool {
true
}

View file

@ -8,8 +8,8 @@ use tracing_subscriber::registry::LookupSpan;
pub struct LspLogLayer(Client);
impl LspLogLayer {
pub fn new(client: Client) -> Self {
LspLogLayer(client)
pub const fn new(client: Client) -> Self {
Self(client)
}
}

View file

@ -137,8 +137,8 @@ struct ImportedUri {
}
impl ImportedUri {
fn new(start_col: u32, end_col: u32, name: String, uri: Option<Url>) -> ImportedUri {
ImportedUri {
const fn new(start_col: u32, end_col: u32, name: String, uri: Option<Url>) -> Self {
Self {
start_col,
end_col,
name,

View file

@ -68,21 +68,21 @@ pub mod helpers {
}
impl MockRequest {
pub fn from_request<R>(params: R::Params) -> MockRequest
pub fn from_request<R>(params: R::Params) -> Self
where
R: tower_lsp::lsp_types::request::Request,
{
MockRequest {
Self {
method: R::METHOD.to_string(),
params: serde_json::to_value(params).expect("Invalid parameters"),
}
}
pub fn from_notification<R>(params: R::Params) -> MockRequest
pub fn from_notification<R>(params: R::Params) -> Self
where
R: tower_lsp::lsp_types::notification::Notification,
{
MockRequest {
Self {
method: R::METHOD.to_string(),
params: serde_json::to_value(params).expect("Invalid parameters"),
}
@ -348,7 +348,7 @@ mod test {
&serde_json::from_value::<Options>(serde_json::to_value(options).unwrap()).unwrap();
let actual_options = backend.options.read().await;
assert_eq!(actual_options.deref(), options);
assert_eq!(&*actual_options, options);
assert_eq!(backend.document_map.len(), documents.len());
for (uri, source) in documents {
let doc = backend.document_map.get(uri).unwrap();
@ -362,8 +362,8 @@ mod test {
);
}
assert_eq!(
backend.client_capabilities.deref().read().await.deref(),
TEST_CLIENT_CAPABILITIES.deref()
&*backend.client_capabilities.deref().read().await,
&*TEST_CLIENT_CAPABILITIES
);
}
}

View file

@ -287,7 +287,7 @@ pub fn get_language_name(uri: &Url, options: &Options) -> Option<String> {
.parser_aliases
.get(capture.as_str())
.cloned()
.unwrap_or(capture.as_str().to_owned())
.unwrap_or_else(|| capture.as_str().to_owned())
})
}
@ -731,7 +731,7 @@ pub async fn get_work_done_token<C: LspClient>(
/// Remove unnecessary backslashes from the given string content.
pub fn remove_unnecessary_escapes(input: &str) -> String {
let mut result = String::new();
let mut chars = input.chars().peekable();
let mut chars = input.chars();
while let Some(c) = chars.next() {
if c == '\\' {