fix(lints): clippy 1.84

This commit is contained in:
Rolo 2025-01-09 09:02:21 -08:00 committed by Michael Davis
parent 168b11e091
commit c1d382a532
15 changed files with 34 additions and 42 deletions

View file

@ -204,13 +204,9 @@ pub fn find_block_comments(
range: *range,
start_pos,
end_pos,
start_margin: selection_slice
.get_char(after_start)
.map_or(false, |c| c == ' '),
start_margin: selection_slice.get_char(after_start) == Some(' '),
end_margin: after_start != before_end
&& selection_slice
.get_char(before_end)
.map_or(false, |c| c == ' '),
&& (selection_slice.get_char(before_end) == Some(' ')),
start_token: start_token.to_string(),
end_token: end_token.to_string(),
});

View file

@ -380,9 +380,10 @@ impl<'t> DocumentFormatter<'t> {
// by a newline/eof character here.
Ordering::Equal
if self.text_fmt.soft_wrap_at_text_width
&& self.peek_grapheme(col, char_pos).map_or(false, |grapheme| {
grapheme.is_newline() || grapheme.is_eof()
}) => {}
&& self
.peek_grapheme(col, char_pos)
.is_some_and(|grapheme| grapheme.is_newline() || grapheme.is_eof()) => {
}
Ordering::Equal if word_width > self.text_fmt.max_wrap as usize => return,
Ordering::Greater if word_width > self.text_fmt.max_wrap as usize => {
self.peeked_grapheme = self.word_buf.pop();

View file

@ -456,7 +456,7 @@ struct IndentQueryResult<'a> {
fn get_node_start_line(node: Node, new_line_byte_pos: Option<usize>) -> usize {
let mut node_line = node.start_position().row;
// Adjust for the new line that will be inserted
if new_line_byte_pos.map_or(false, |pos| node.start_byte() >= pos) {
if new_line_byte_pos.is_some_and(|pos| node.start_byte() >= pos) {
node_line += 1;
}
node_line
@ -464,7 +464,7 @@ fn get_node_start_line(node: Node, new_line_byte_pos: Option<usize>) -> usize {
fn get_node_end_line(node: Node, new_line_byte_pos: Option<usize>) -> usize {
let mut node_line = node.end_position().row;
// Adjust for the new line that will be inserted (with a strict inequality since end_byte is exclusive)
if new_line_byte_pos.map_or(false, |pos| node.end_byte() > pos) {
if new_line_byte_pos.is_some_and(|pos| node.end_byte() > pos) {
node_line += 1;
}
node_line

View file

@ -273,12 +273,12 @@ fn fetch_grammar(grammar: GrammarConfiguration) -> Result<FetchStatus> {
}
// ensure the remote matches the configured remote
if get_remote_url(&grammar_dir).map_or(true, |s| s != remote) {
if get_remote_url(&grammar_dir).as_ref() != Some(&remote) {
set_remote(&grammar_dir, &remote)?;
}
// ensure the revision matches the configured revision
if get_revision(&grammar_dir).map_or(true, |s| s != revision) {
if get_revision(&grammar_dir).as_ref() != Some(&revision) {
// Fetch the exact revision from the remote.
// Supported by server-side git since v2.5.0 (July 2015),
// enabled by default on major git hosts.

View file

@ -85,7 +85,7 @@ impl Client {
.and_then(|root| lsp::Url::from_file_path(root).ok());
if self.root_path == root.unwrap_or(workspace)
|| root_uri.as_ref().map_or(false, |root_uri| {
|| root_uri.as_ref().is_some_and(|root_uri| {
self.workspace_folders
.lock()
.iter()

View file

@ -43,7 +43,7 @@ impl<'a> RopeSliceExt<'a> for RopeSlice<'a> {
return false;
}
self.get_byte_slice(len - text.len()..)
.map_or(false, |end| end == text)
.is_some_and(|end| end == text)
}
fn starts_with(self, text: &str) -> bool {
@ -52,7 +52,7 @@ impl<'a> RopeSliceExt<'a> for RopeSlice<'a> {
return false;
}
self.get_byte_slice(..text.len())
.map_or(false, |start| start == text)
.is_some_and(|start| start == text)
}
fn regex_input(self) -> RegexInput<RopeyCursor<'a>> {

View file

@ -2493,7 +2493,7 @@ fn global_search(cx: &mut Context) {
let doc = documents.iter().find(|&(doc_path, _)| {
doc_path
.as_ref()
.map_or(false, |doc_path| doc_path == entry.path())
.is_some_and(|doc_path| doc_path == entry.path())
});
let result = if let Some((_, doc)) = doc {
@ -4066,7 +4066,7 @@ pub mod insert {
let on_auto_pair = doc
.auto_pairs(cx.editor)
.and_then(|pairs| pairs.get(prev))
.map_or(false, |pair| pair.open == prev && pair.close == curr);
.is_some_and(|pair| pair.open == prev && pair.close == curr);
let local_offs = if let Some(token) = continue_comment_token {
new_text.reserve_exact(line_ending.len() + indent.len() + token.len() + 1);

View file

@ -1288,7 +1288,7 @@ fn compute_inlay_hints_for_view(
if !doc.inlay_hints_oudated
&& doc
.inlay_hints(view_id)
.map_or(false, |dih| dih.id == new_doc_inlay_hints_id)
.is_some_and(|dih| dih.id == new_doc_inlay_hints_id)
{
return None;
}

View file

@ -63,7 +63,7 @@ fn filter_picker_entry(entry: &DirEntry, root: &Path, dedup_symlinks: bool) -> b
.path()
.canonicalize()
.ok()
.map_or(false, |path| !path.starts_with(root));
.is_some_and(|path| !path.starts_with(root));
}
true

View file

@ -53,9 +53,10 @@ impl menu::Item for CompletionItem {
let deprecated = match self {
CompletionItem::Lsp(LspCompletionItem { item, .. }) => {
item.deprecated.unwrap_or_default()
|| item.tags.as_ref().map_or(false, |tags| {
tags.contains(&lsp::CompletionItemTag::DEPRECATED)
})
|| item
.tags
.as_ref()
.is_some_and(|tags| tags.contains(&lsp::CompletionItemTag::DEPRECATED))
}
CompletionItem::Other(_) => false,
};

View file

@ -363,7 +363,7 @@ pub mod completers {
git_ignore: bool,
) -> Vec<Completion> {
filename_impl(editor, input, git_ignore, |entry| {
let is_dir = entry.file_type().map_or(false, |entry| entry.is_dir());
let is_dir = entry.file_type().is_some_and(|entry| entry.is_dir());
if is_dir {
FileMatch::AcceptIncomplete
@ -414,7 +414,7 @@ pub mod completers {
git_ignore: bool,
) -> Vec<Completion> {
filename_impl(editor, input, git_ignore, |entry| {
let is_dir = entry.file_type().map_or(false, |entry| entry.is_dir());
let is_dir = entry.file_type().is_some_and(|entry| entry.is_dir());
if is_dir {
FileMatch::Accept

View file

@ -178,7 +178,7 @@ impl<'a> InlineDiagnosticAccumulator<'a> {
horizontal_off: usize,
) -> bool {
// TODO: doing the cursor tracking here works well but is somewhat
// duplicate effort/tedious maybe centralize this somehwere?
// duplicate effort/tedious maybe centralize this somewhere?
// In the DocFormatter?
if grapheme.char_idx == self.cursor {
self.cursor_line = true;
@ -248,9 +248,9 @@ impl<'a> InlineDiagnosticAccumulator<'a> {
}
pub fn has_multi(&self, width: u16) -> bool {
self.stack.last().map_or(false, |&(_, anchor)| {
anchor > self.config.max_diagnostic_start(width)
})
self.stack
.last()
.is_some_and(|&(_, anchor)| anchor > self.config.max_diagnostic_start(width))
}
}

View file

@ -717,10 +717,7 @@ impl Document {
config: Arc<dyn DynAccess<Config>>,
) -> Result<Self, DocumentOpenError> {
// If the path is not a regular file (e.g.: /dev/random) it should not be opened.
if path
.metadata()
.map_or(false, |metadata| !metadata.is_file())
{
if path.metadata().is_ok_and(|metadata| !metadata.is_file()) {
return Err(DocumentOpenError::IrregularFile);
}
@ -2004,8 +2001,8 @@ impl Document {
};
let ends_at_word =
start != end && end != 0 && text.get_char(end - 1).map_or(false, char_is_word);
let starts_at_word = start != end && text.get_char(start).map_or(false, char_is_word);
start != end && end != 0 && text.get_char(end - 1).is_some_and(char_is_word);
let starts_at_word = start != end && text.get_char(start).is_some_and(char_is_word);
Some(Diagnostic {
range: Range { start, end },
@ -2038,7 +2035,7 @@ impl Document {
self.clear_diagnostics(language_server_id);
} else {
self.diagnostics.retain(|d| {
if language_server_id.map_or(false, |id| id != d.provider) {
if language_server_id.is_some_and(|id| id != d.provider) {
return true;
}

View file

@ -244,7 +244,7 @@ impl Editor {
ResourceOp::Create(op) => {
let uri = Uri::try_from(&op.uri)?;
let path = uri.as_path().expect("URIs are valid paths");
let ignore_if_exists = op.options.as_ref().map_or(false, |options| {
let ignore_if_exists = op.options.as_ref().is_some_and(|options| {
!options.overwrite.unwrap_or(false) && options.ignore_if_exists.unwrap_or(false)
});
if !ignore_if_exists || !path.exists() {
@ -288,7 +288,7 @@ impl Editor {
let from = from_uri.as_path().expect("URIs are valid paths");
let to_uri = Uri::try_from(&op.new_uri)?;
let to = to_uri.as_path().expect("URIs are valid paths");
let ignore_if_exists = op.options.as_ref().map_or(false, |options| {
let ignore_if_exists = op.options.as_ref().is_some_and(|options| {
!options.overwrite.unwrap_or(false) && options.ignore_if_exists.unwrap_or(false)
});
if !ignore_if_exists || !to.exists() {

View file

@ -500,10 +500,7 @@ impl ThemePalette {
let modifiers = value.as_array().ok_or("Modifiers should be an array")?;
for modifier in modifiers {
if modifier
.as_str()
.map_or(false, |modifier| modifier == "underlined")
{
if modifier.as_str() == Some("underlined") {
*style = style.underline_style(UnderlineStyle::Line);
} else {
*style = style.add_modifier(Self::parse_modifier(modifier)?);