diff --git a/crates/nu-cli/src/commands/command.rs b/crates/nu-cli/src/commands/command.rs index d2b68557fa..4e95bb1111 100644 --- a/crates/nu-cli/src/commands/command.rs +++ b/crates/nu-cli/src/commands/command.rs @@ -238,6 +238,7 @@ pub trait WholeStreamCommand: Send + Sync { // Custom commands are blocks, so we can use the information in the block to also // implement a WholeStreamCommand +#[allow(clippy::suspicious_else_formatting)] #[async_trait] impl WholeStreamCommand for Block { fn name(&self) -> &str { diff --git a/crates/nu-cli/src/commands/from_xml.rs b/crates/nu-cli/src/commands/from_xml.rs index 26df9a4dcb..4882ab93d0 100644 --- a/crates/nu-cli/src/commands/from_xml.rs +++ b/crates/nu-cli/src/commands/from_xml.rs @@ -35,7 +35,7 @@ fn from_attributes_to_value(attributes: &[roxmltree::Attribute], tag: impl Into< collected.into_value() } -fn from_node_to_value<'a, 'd>(n: &roxmltree::Node<'a, 'd>, tag: impl Into) -> Value { +fn from_node_to_value(n: &roxmltree::Node, tag: impl Into) -> Value { let tag = tag.into(); if n.is_element() { diff --git a/crates/nu-cli/src/commands/random/bool.rs b/crates/nu-cli/src/commands/random/bool.rs index f6e9625f4a..4c3f9717cb 100644 --- a/crates/nu-cli/src/commands/random/bool.rs +++ b/crates/nu-cli/src/commands/random/bool.rs @@ -59,7 +59,7 @@ pub async fn bool_command(args: CommandArgs) -> Result if let Some(prob) = bias { probability = *prob as f64; - let probability_is_valid = 0.0 <= probability && probability <= 1.0; + let probability_is_valid = (0.0..=1.0).contains(&probability); if !probability_is_valid { return Err(ShellError::labeled_error( diff --git a/crates/nu-cli/src/commands/seq_dates.rs b/crates/nu-cli/src/commands/seq_dates.rs index 3134b86d36..31649a1a5b 100644 --- a/crates/nu-cli/src/commands/seq_dates.rs +++ b/crates/nu-cli/src/commands/seq_dates.rs @@ -197,7 +197,7 @@ async fn seq_dates(args: CommandArgs) -> Result { let clone = i.clone(); i.to_value(clone.tag) } - _ => (1 as i64).to_value_create_tag(), + _ => (1_i64).to_value_create_tag(), }; let day_count: Option = match days { diff --git a/crates/nu-cli/src/commands/str_/substring.rs b/crates/nu-cli/src/commands/str_/substring.rs index 00f7229063..bba59bd3a3 100644 --- a/crates/nu-cli/src/commands/str_/substring.rs +++ b/crates/nu-cli/src/commands/str_/substring.rs @@ -251,7 +251,7 @@ fn process_arguments(range: Value, name: impl Into) -> Result<(isize, isize }?; let start = match &search { - SubstringText(start, _) if start == "" || start == "_" => 0, + SubstringText(start, _) if start.is_empty() || start == "_" => 0, SubstringText(start, _) => start.trim().parse().map_err(|_| { ShellError::labeled_error( "could not perform substring", @@ -262,7 +262,7 @@ fn process_arguments(range: Value, name: impl Into) -> Result<(isize, isize }; let end = match &search { - SubstringText(_, end) if end == "" || end == "_" => isize::max_value(), + SubstringText(_, end) if end.is_empty() || end == "_" => isize::max_value(), SubstringText(_, end) => end.trim().parse().map_err(|_| { ShellError::labeled_error( "could not perform substring", diff --git a/crates/nu-cli/src/commands/table/command.rs b/crates/nu-cli/src/commands/table/command.rs index 436ae43204..ad2772f15a 100644 --- a/crates/nu-cli/src/commands/table/command.rs +++ b/crates/nu-cli/src/commands/table/command.rs @@ -75,7 +75,7 @@ fn values_to_entries( let mut row: Vec = headers .iter() .map(|d: &StyledString| { - if d.contents == "" { + if d.contents.is_empty() { match value { Value { value: UntaggedValue::Row(..), diff --git a/crates/nu-cli/src/commands/to_html.rs b/crates/nu-cli/src/commands/to_html.rs index 0ffe6a9bcd..6493764e61 100644 --- a/crates/nu-cli/src/commands/to_html.rs +++ b/crates/nu-cli/src/commands/to_html.rs @@ -284,7 +284,7 @@ async fn to_html(args: CommandArgs) -> Result { let input: Vec = input.collect().await; let headers = nu_protocol::merge_descriptors(&input); let headers = Some(headers) - .filter(|headers| !headers.is_empty() && (headers.len() > 1 || headers[0] != "")); + .filter(|headers| !headers.is_empty() && (headers.len() > 1 || !headers[0].is_empty())); let mut output_string = String::new(); let mut regex_hm: HashMap = HashMap::new(); diff --git a/crates/nu-cli/src/commands/to_md.rs b/crates/nu-cli/src/commands/to_md.rs index 058857a9ac..7a407541ed 100644 --- a/crates/nu-cli/src/commands/to_md.rs +++ b/crates/nu-cli/src/commands/to_md.rs @@ -59,7 +59,7 @@ async fn to_md(args: CommandArgs) -> Result { let mut escaped_headers: Vec = Vec::new(); let mut column_widths: Vec = Vec::new(); - if !headers.is_empty() && (headers.len() > 1 || headers[0] != "") { + if !headers.is_empty() && (headers.len() > 1 || !headers[0].is_empty()) { for header in &headers { let escaped_header_string = htmlescape::encode_minimal(&header); column_widths.push(escaped_header_string.len()); diff --git a/crates/nu-cli/src/commands/to_xml.rs b/crates/nu-cli/src/commands/to_xml.rs index adf0d878b9..f40a213136 100644 --- a/crates/nu-cli/src/commands/to_xml.rs +++ b/crates/nu-cli/src/commands/to_xml.rs @@ -7,7 +7,6 @@ use quick_xml::events::{BytesEnd, BytesStart, BytesText, Event}; use std::collections::HashSet; use std::io::Cursor; use std::io::Write; -use std::iter::FromIterator; pub struct ToXML; @@ -77,7 +76,7 @@ pub fn get_children(row: &Value) -> Option<&Vec> { pub fn is_xml_row(row: &Value) -> bool { if let UntaggedValue::Row(r) = &row.value { - let keys: HashSet<&String> = HashSet::from_iter(r.keys()); + let keys: HashSet<&String> = r.keys().collect(); let children: String = "children".to_string(); let attributes: String = "attributes".to_string(); return keys.contains(&children) && keys.contains(&attributes) && keys.len() == 2; diff --git a/crates/nu-cli/src/completion/command.rs b/crates/nu-cli/src/completion/command.rs index 05ff53e7b2..e056ee904d 100644 --- a/crates/nu-cli/src/completion/command.rs +++ b/crates/nu-cli/src/completion/command.rs @@ -38,7 +38,7 @@ impl Completer for CommandCompleter { }) .collect(); - if partial != "" { + if !partial.is_empty() { let path_completer = crate::completion::path::PathCompleter; let path_results = path_completer.path_suggestions(partial, matcher); let iter = path_results.into_iter().filter_map(|path_suggestion| { diff --git a/crates/nu-cli/src/completion/path.rs b/crates/nu-cli/src/completion/path.rs index af6a3d9258..28afb764d2 100644 --- a/crates/nu-cli/src/completion/path.rs +++ b/crates/nu-cli/src/completion/path.rs @@ -22,7 +22,7 @@ impl PathCompleter { None => ("", expanded), }; - let base_dir = if base_dir_name == "" { + let base_dir = if base_dir_name.is_empty() { PathBuf::from(".") } else { #[cfg(feature = "directories")] diff --git a/crates/nu-json/src/de.rs b/crates/nu-json/src/de.rs index b11906ff97..10c5a85e2e 100644 --- a/crates/nu-json/src/de.rs +++ b/crates/nu-json/src/de.rs @@ -243,7 +243,7 @@ where } } _ => { - if chf == b'-' || chf >= b'0' && chf <= b'9' { + if chf == b'-' || (b'0'..=b'9').contains(&chf) { let mut pn = ParseNumber::new(self.str_buf.iter().cloned()); match pn.parse(false) { Ok(Number::F64(v)) => { @@ -435,7 +435,7 @@ where let n2 = self.decode_hex_escape()?; - if n2 < 0xDC00 || n2 > 0xDFFF { + if !(0xDC00..=0xDFFF).contains(&n2) { return Err(self .rdr .error(ErrorCode::LoneLeadingSurrogateInHexEscape)); diff --git a/crates/nu-json/src/value.rs b/crates/nu-json/src/value.rs index a97d0c8cec..a5eff0d095 100644 --- a/crates/nu-json/src/value.rs +++ b/crates/nu-json/src/value.rs @@ -107,7 +107,7 @@ impl Value { } s.parse().ok() } - if pointer == "" { + if pointer.is_empty() { return Some(self); } if !pointer.starts_with('/') { diff --git a/crates/nu-source/src/meta.rs b/crates/nu-source/src/meta.rs index 03a915ea02..a6d857bdc6 100644 --- a/crates/nu-source/src/meta.rs +++ b/crates/nu-source/src/meta.rs @@ -399,7 +399,7 @@ impl Tag { self.span.slice(source) } - pub fn string<'a>(&self, source: &'a str) -> String { + pub fn string(&self, source: &str) -> String { self.span.slice(source).to_string() } @@ -407,7 +407,7 @@ impl Tag { self.span.slice(source).tagged(self) } - pub fn tagged_string<'a>(&self, source: &'a str) -> Tagged { + pub fn tagged_string(&self, source: &str) -> Tagged { self.span.slice(source).to_string().tagged(self) } @@ -595,7 +595,7 @@ impl Span { } } - pub fn string<'a>(&self, source: &'a str) -> String { + pub fn string(&self, source: &str) -> String { self.slice(source).to_string() } @@ -603,7 +603,7 @@ impl Span { self.slice(source).spanned(*self) } - pub fn spanned_string<'a>(&self, source: &'a str) -> Spanned { + pub fn spanned_string(&self, source: &str) -> Spanned { self.slice(source).to_string().spanned(*self) } diff --git a/crates/nu-table/src/table.rs b/crates/nu-table/src/table.rs index f391119873..653f85a9fa 100644 --- a/crates/nu-table/src/table.rs +++ b/crates/nu-table/src/table.rs @@ -46,10 +46,7 @@ impl TextStyle { } pub fn bold(&self, bool_value: Option) -> TextStyle { - let bv = match bool_value { - Some(v) => v, - None => false, - }; + let bv = bool_value.unwrap_or(false); TextStyle { alignment: self.alignment, diff --git a/crates/nu-table/src/wrap.rs b/crates/nu-table/src/wrap.rs index a54874d0fa..38e99457db 100644 --- a/crates/nu-table/src/wrap.rs +++ b/crates/nu-table/src/wrap.rs @@ -74,7 +74,7 @@ pub fn split_sublines(input: &str) -> Vec> { .collect::>() } -pub fn column_width<'a>(input: &[Vec>]) -> usize { +pub fn column_width(input: &[Vec]) -> usize { let mut max = 0; for line in input { @@ -100,7 +100,7 @@ pub fn column_width<'a>(input: &[Vec>]) -> usize { max } -fn split_word<'a>(cell_width: usize, word: &'a str) -> Vec> { +fn split_word(cell_width: usize, word: &str) -> Vec { use unicode_width::UnicodeWidthChar; let mut output = vec![]; diff --git a/crates/nu_plugin_inc/src/inc.rs b/crates/nu_plugin_inc/src/inc.rs index 6599734535..2d2a6ab13c 100644 --- a/crates/nu_plugin_inc/src/inc.rs +++ b/crates/nu_plugin_inc/src/inc.rs @@ -79,7 +79,7 @@ impl Inc { Ok(UntaggedValue::int(i + 1).into_value(value.tag())) } UntaggedValue::Primitive(Primitive::Filesize(b)) => { - Ok(UntaggedValue::filesize(b + 1 as u64).into_value(value.tag())) + Ok(UntaggedValue::filesize(b + 1_u64).into_value(value.tag())) } UntaggedValue::Primitive(Primitive::String(ref s)) => { Ok(self.apply(&s)?.into_value(value.tag())) diff --git a/crates/nu_plugin_textview/src/textview.rs b/crates/nu_plugin_textview/src/textview.rs index a39363d15d..d22343466c 100644 --- a/crates/nu_plugin_textview/src/textview.rs +++ b/crates/nu_plugin_textview/src/textview.rs @@ -40,7 +40,7 @@ pub fn view_text_value(value: &Value) { term_width = value.as_u64().unwrap_or(term_width as u64) as usize; } "tab_width" => { - tab_width = value.as_u64().unwrap_or(4 as u64); + tab_width = value.as_u64().unwrap_or(4_u64); } "colored_output" => colored_output = value.as_bool().unwrap_or(true), "true_color" => true_color = value.as_bool().unwrap_or(true), diff --git a/crates/nu_plugin_to_sqlite/src/to_sqlite.rs b/crates/nu_plugin_to_sqlite/src/to_sqlite.rs index fb79be837b..1e400ab577 100644 --- a/crates/nu_plugin_to_sqlite/src/to_sqlite.rs +++ b/crates/nu_plugin_to_sqlite/src/to_sqlite.rs @@ -16,7 +16,7 @@ impl ToSqlite { } } fn comma_concat(acc: String, current: String) -> String { - if acc == "" { + if acc.is_empty() { current } else { format!("{}, {}", acc, current)