mirror of
https://github.com/nushell/nushell
synced 2024-12-27 21:43:09 +00:00
Rust 1.49 Clippy Fixes (#2835)
This commit is contained in:
parent
3ef53fe2cd
commit
15d49e4096
19 changed files with 25 additions and 28 deletions
|
@ -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 {
|
||||
|
|
|
@ -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<Tag>) -> Value {
|
||||
fn from_node_to_value(n: &roxmltree::Node, tag: impl Into<Tag>) -> Value {
|
||||
let tag = tag.into();
|
||||
|
||||
if n.is_element() {
|
||||
|
|
|
@ -59,7 +59,7 @@ pub async fn bool_command(args: CommandArgs) -> Result<OutputStream, ShellError>
|
|||
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(
|
||||
|
|
|
@ -197,7 +197,7 @@ async fn seq_dates(args: CommandArgs) -> Result<OutputStream, ShellError> {
|
|||
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<Value> = match days {
|
||||
|
|
|
@ -251,7 +251,7 @@ fn process_arguments(range: Value, name: impl Into<Tag>) -> 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<Tag>) -> 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",
|
||||
|
|
|
@ -75,7 +75,7 @@ fn values_to_entries(
|
|||
let mut row: Vec<StyledString> = headers
|
||||
.iter()
|
||||
.map(|d: &StyledString| {
|
||||
if d.contents == "" {
|
||||
if d.contents.is_empty() {
|
||||
match value {
|
||||
Value {
|
||||
value: UntaggedValue::Row(..),
|
||||
|
|
|
@ -284,7 +284,7 @@ async fn to_html(args: CommandArgs) -> Result<OutputStream, ShellError> {
|
|||
let input: Vec<Value> = 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<u32, (&str, String)> = HashMap::new();
|
||||
|
||||
|
|
|
@ -59,7 +59,7 @@ async fn to_md(args: CommandArgs) -> Result<OutputStream, ShellError> {
|
|||
let mut escaped_headers: Vec<String> = Vec::new();
|
||||
let mut column_widths: Vec<usize> = 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());
|
||||
|
|
|
@ -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<Value>> {
|
|||
|
||||
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;
|
||||
|
|
|
@ -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| {
|
||||
|
|
|
@ -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")]
|
||||
|
|
|
@ -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));
|
||||
|
|
|
@ -107,7 +107,7 @@ impl Value {
|
|||
}
|
||||
s.parse().ok()
|
||||
}
|
||||
if pointer == "" {
|
||||
if pointer.is_empty() {
|
||||
return Some(self);
|
||||
}
|
||||
if !pointer.starts_with('/') {
|
||||
|
|
|
@ -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<String> {
|
||||
pub fn tagged_string(&self, source: &str) -> Tagged<String> {
|
||||
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<String> {
|
||||
pub fn spanned_string(&self, source: &str) -> Spanned<String> {
|
||||
self.slice(source).to_string().spanned(*self)
|
||||
}
|
||||
|
||||
|
|
|
@ -46,10 +46,7 @@ impl TextStyle {
|
|||
}
|
||||
|
||||
pub fn bold(&self, bool_value: Option<bool>) -> TextStyle {
|
||||
let bv = match bool_value {
|
||||
Some(v) => v,
|
||||
None => false,
|
||||
};
|
||||
let bv = bool_value.unwrap_or(false);
|
||||
|
||||
TextStyle {
|
||||
alignment: self.alignment,
|
||||
|
|
|
@ -74,7 +74,7 @@ pub fn split_sublines(input: &str) -> Vec<Vec<Subline>> {
|
|||
.collect::<Vec<_>>()
|
||||
}
|
||||
|
||||
pub fn column_width<'a>(input: &[Vec<Subline<'a>>]) -> usize {
|
||||
pub fn column_width(input: &[Vec<Subline>]) -> usize {
|
||||
let mut max = 0;
|
||||
|
||||
for line in input {
|
||||
|
@ -100,7 +100,7 @@ pub fn column_width<'a>(input: &[Vec<Subline<'a>>]) -> usize {
|
|||
max
|
||||
}
|
||||
|
||||
fn split_word<'a>(cell_width: usize, word: &'a str) -> Vec<Subline<'a>> {
|
||||
fn split_word(cell_width: usize, word: &str) -> Vec<Subline> {
|
||||
use unicode_width::UnicodeWidthChar;
|
||||
|
||||
let mut output = vec![];
|
||||
|
|
|
@ -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()))
|
||||
|
|
|
@ -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),
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Reference in a new issue