Skip to content

Commit

Permalink
chore: fix clippy
Browse files Browse the repository at this point in the history
  • Loading branch information
LoricAndre committed Nov 7, 2024
1 parent a00e78c commit 8a57983
Show file tree
Hide file tree
Showing 20 changed files with 42 additions and 57 deletions.
2 changes: 1 addition & 1 deletion examples/custom_item.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ pub fn main() {

let selected_items = Skim::run_with(&options, Some(rx_item))
.map(|out| out.selected_items)
.unwrap_or_else(Vec::new);
.unwrap_or_default();

for item in selected_items.iter() {
println!("{}", item.output());
Expand Down
2 changes: 1 addition & 1 deletion examples/downcast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ pub fn main() {

let selected_items = Skim::run_with(&options, Some(rx))
.map(|out| out.selected_items)
.unwrap_or_else(Vec::new)
.unwrap_or_default()
.iter()
.map(|selected_item| (**selected_item).as_any().downcast_ref::<Item>().unwrap().to_owned())
.collect::<Vec<Item>>();
Expand Down
2 changes: 1 addition & 1 deletion examples/nth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ pub fn main() {
let items = item_reader.of_bufread(Cursor::new(input));
let selected_items = Skim::run_with(&options, Some(items))
.map(|out| out.selected_items)
.unwrap_or_else(Vec::new);
.unwrap_or_default();

for item in selected_items.iter() {
println!("{}", item.output());
Expand Down
4 changes: 2 additions & 2 deletions examples/option_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ pub fn main() {
let items = item_reader.of_bufread(Cursor::new(input));
let selected_items = Skim::run_with(&options, Some(items))
.map(|out| out.selected_items)
.unwrap_or_else(Vec::new);
.unwrap_or_default();

for item in selected_items.iter() {
println!("{}", item.output());
Expand All @@ -28,7 +28,7 @@ pub fn main() {
let items = item_reader.of_bufread(Cursor::new(input));
let selected_items = Skim::run_with(&options, Some(items))
.map(|out| out.selected_items)
.unwrap_or_else(Vec::new);
.unwrap_or_default();

for item in selected_items.iter() {
println!("{}", item.output());
Expand Down
2 changes: 1 addition & 1 deletion examples/sample.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ pub fn main() {

let selected_items = Skim::run_with(&options, None)
.map(|out| out.selected_items)
.unwrap_or_else(Vec::new);
.unwrap_or_default();

for item in selected_items.iter() {
println!("{}", item.output());
Expand Down
2 changes: 1 addition & 1 deletion src/ansi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -469,7 +469,7 @@ mod tests {
let input = "ab";
let ansistring = ANSIParser::default().parse_ansi(input);

assert_eq!(false, ansistring.has_attrs());
assert!(!ansistring.has_attrs());

let mut it = ansistring.iter();
assert_eq!(Some(('a', Attr::default())), it.next());
Expand Down
13 changes: 3 additions & 10 deletions src/engine/fuzzy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,10 @@ use crate::{MatchRange, MatchResult, SkimItem};
use bitflags::_core::cmp::min;

//------------------------------------------------------------------------------
#[derive(Debug, Copy, Clone)]
#[derive(Debug, Copy, Clone, Default)]
pub enum FuzzyAlgorithm {
SkimV1,
#[default]
SkimV2,
Clangd,
}
Expand All @@ -29,12 +30,6 @@ impl FuzzyAlgorithm {
}
}

impl Default for FuzzyAlgorithm {
fn default() -> Self {
FuzzyAlgorithm::SkimV2
}
}

const BYTES_1M: usize = 1024 * 1024 * 1024;

//------------------------------------------------------------------------------
Expand Down Expand Up @@ -146,9 +141,7 @@ impl MatchEngine for FuzzyEngine {
}
}

if matched_result == None {
return None;
}
matched_result.as_ref()?;

let (score, matched_range) = matched_result.unwrap();

Expand Down
2 changes: 1 addition & 1 deletion src/event.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ pub enum Event {
bitflags! {
/// `Effect` is the effect of a text
pub struct UpdateScreen: u8 {
const REDRAW = 0b0000_0000;
const REDRAW = 0b0000_0001;
const DONT_REDRAW = 0b0000_0010;
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/header.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
///! header of the items
//! header of the items
use crate::ansi::{ANSIParser, AnsiString};
use crate::event::UpdateScreen;
use crate::event::{Event, EventHandler};
Expand Down
8 changes: 4 additions & 4 deletions src/helper/item_reader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -170,10 +170,10 @@ impl SkimItemReader {
break;
}

if buffer.ends_with(&[b'\r', b'\n']) {
if buffer.ends_with(b"\r\n") {
buffer.pop();
buffer.pop();
} else if buffer.ends_with(&[b'\n']) || buffer.ends_with(&[b'\0']) {
} else if buffer.ends_with(b"\n") || buffer.ends_with(b"\0") {
buffer.pop();
}

Expand Down Expand Up @@ -264,10 +264,10 @@ impl SkimItemReader {
break;
}

if buffer.ends_with(&[b'\r', b'\n']) {
if buffer.ends_with(b"\r\n") {
buffer.pop();
buffer.pop();
} else if buffer.ends_with(&[b'\n']) || buffer.ends_with(&[b'\0']) {
} else if buffer.ends_with(b"\n") || buffer.ends_with(b"\0") {
buffer.pop();
}

Expand Down
6 changes: 3 additions & 3 deletions src/input.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
///! Input will listens to user input, modify the query string, send special
///! keystrokes(such as Enter, Ctrl-p, Ctrl-n, etc) to the controller.
//! Input will listens to user input, modify the query string, send special
//! keystrokes(such as Enter, Ctrl-p, Ctrl-n, etc) to the controller.
use crate::event::{parse_event, Event};
use regex::Regex;
use std::collections::HashMap;
Expand Down Expand Up @@ -39,7 +39,7 @@ impl Input {

pub fn bind(&mut self, key: &str, action_chain: ActionChain) {
let key = from_keyname(key);
if key == None || action_chain.is_empty() {
if key.is_none() || action_chain.is_empty() {
return;
}

Expand Down
6 changes: 3 additions & 3 deletions src/item.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
///! An item is line of text that read from `find` command or stdin together with
///! the internal states, such as selected or not
//! An item is line of text that read from `find` command or stdin together with
//! the internal states, such as selected or not
use std::cmp::min;
use std::default::Default;
use std::ops::Deref;
Expand Down Expand Up @@ -83,7 +83,7 @@ impl std::cmp::Eq for MatchedItem {}

impl PartialOrd for MatchedItem {
fn partial_cmp(&self, other: &Self) -> Option<CmpOrd> {
self.rank.partial_cmp(&other.rank)
Some(self.rank.cmp(&other.rank))
}
}

Expand Down
9 changes: 2 additions & 7 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -219,19 +219,14 @@ pub enum ItemPreview {
//==============================================================================
// A match engine will execute the matching algorithm

#[derive(Eq, PartialEq, Debug, Copy, Clone)]
#[derive(Eq, PartialEq, Debug, Copy, Clone, Default)]
pub enum CaseMatching {
Respect,
Ignore,
#[default]
Smart,
}

impl Default for CaseMatching {
fn default() -> Self {
CaseMatching::Smart
}
}

#[derive(PartialEq, Eq, Clone, Debug)]
#[allow(dead_code)]
pub enum MatchRange {
Expand Down
2 changes: 1 addition & 1 deletion src/model.rs
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ impl Model {
options
.preview_window
.map(Self::parse_preview_offset)
.unwrap_or_else(|| "".to_string()),
.unwrap_or_default(),
),
);
}
Expand Down
6 changes: 3 additions & 3 deletions src/orderedvec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ mod tests {
let a = vec![1, 3, 5, 7];
let b = vec![4, 8, 9];
let c = vec![2, 6, 10];
let d = vec![1, 3, 5, 7, 4, 8, 9, 2, 6, 10];
let d = [1, 3, 5, 7, 4, 8, 9, 2, 6, 10];
let mut ordered_vec = OrderedVec::new();
ordered_vec.nosort(true);
ordered_vec.append(a);
Expand All @@ -256,7 +256,7 @@ mod tests {
let a = vec![1, 3, 5, 7];
let b = vec![4, 8, 9];
let c = vec![2, 6, 10];
let d = vec![10, 6, 2, 9, 8, 4, 7, 5, 3, 1];
let d = [10, 6, 2, 9, 8, 4, 7, 5, 3, 1];
let mut ordered_vec = OrderedVec::new();
ordered_vec.nosort(true).tac(true);
ordered_vec.append(a);
Expand All @@ -271,7 +271,7 @@ mod tests {
fn test_equals() {
let a = vec![1, 2, 3, 4];
let b = vec![5, 6, 7, 8];
let target = vec![1, 2, 3, 4, 5, 6, 7, 8];
let target = [1, 2, 3, 4, 5, 6, 7, 8];
let mut ordered_vec = OrderedVec::new();
ordered_vec.append(a);
ordered_vec.append(b);
Expand Down
6 changes: 3 additions & 3 deletions src/previewer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ impl Previewer {
(None, None) => false,
(None, Some(_)) => true,
(Some(_), None) => true,
#[allow(clippy::vtable_address_comparisons)]
#[allow(ambiguous_wide_pointer_comparisons)]
(Some(prev), Some(new)) => !Arc::ptr_eq(prev, new),
};

Expand Down Expand Up @@ -464,7 +464,7 @@ where
.env("LINES", preview_cmd.lines.to_string())
.env("COLUMNS", preview_cmd.columns.to_string())
.arg("-c")
.arg(&cmd)
.arg(cmd)
.stdout(Stdio::piped())
.stderr(Stdio::piped())
.spawn();
Expand Down Expand Up @@ -624,7 +624,7 @@ impl Printer {

fn adjust_scroll_print(&self, canvas: &mut dyn Canvas, ch: char, attr: Attr) -> Result<usize> {
if self.row < self.skip_rows || self.col < self.skip_cols {
canvas.put_char_with_attr(usize::max_value(), usize::max_value(), ch, attr)
canvas.put_char_with_attr(usize::MAX, usize::MAX, ch, attr)
} else {
canvas.put_char_with_attr(self.row - self.skip_rows, self.col - self.skip_cols, ch, attr)
}
Expand Down
6 changes: 3 additions & 3 deletions src/reader.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//! Reader is used for reading items from datasource (e.g. stdin or command output)
//!
//! After reading in a line, reader will save an item into the pool(items)
use crate::global::mark_new_run;
///! Reader is used for reading items from datasource (e.g. stdin or command output)
///!
///! After reading in a line, reader will save an item into the pool(items)
use crate::options::SkimOptions;
use crate::spinlock::SpinLock;
use crate::{SkimItem, SkimItemReceiver};
Expand Down
2 changes: 1 addition & 1 deletion src/selection.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
//! Handle the selections of items
use std::cmp::max;
use std::cmp::min;
use std::collections::BTreeMap;
Expand All @@ -6,7 +7,6 @@ use std::sync::Arc;

use tuikit::prelude::{Event as TermEvent, *};

///! Handle the selections of items
use crate::event::{Event, EventHandler, UpdateScreen};
use crate::global::current_run_num;
use crate::item::MatchedItem;
Expand Down
15 changes: 6 additions & 9 deletions src/spinlock.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
///! SpinLock implemented using AtomicBool
///! Just like Mutex except:
///!
///! 1. It uses CAS for locking, more efficient in low contention
///! 2. Use `.lock()` instead of `.lock().unwrap()` to retrieve the guard.
///! 3. It doesn't handle poison so data is still available on thread panic.
//! SpinLock implemented using AtomicBool
//! Just like Mutex except:
//!
//! 1. It uses CAS for locking, more efficient in low contention
//! 2. Use `.lock()` instead of `.lock().unwrap()` to retrieve the guard.
//! 3. It doesn't handle poison so data is still available on thread panic.
use std::cell::UnsafeCell;
use std::ops::Deref;
use std::ops::DerefMut;
Expand Down Expand Up @@ -85,9 +85,6 @@ mod tests {
use std::sync::Arc;
use std::thread;

#[derive(Eq, PartialEq, Debug)]
struct NonCopy(i32);

#[test]
fn smoke() {
let m = SpinLock::new(());
Expand Down
2 changes: 1 addition & 1 deletion src/theme.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
///! Handle the color theme
//! Handle the color theme
use crate::options::SkimOptions;
use tuikit::prelude::*;

Expand Down

0 comments on commit 8a57983

Please sign in to comment.