forked from extern/nushell
Rust 1.49 Clippy Fixes (#2835)
This commit is contained in:
parent
3ef53fe2cd
commit
15d49e4096
@ -238,6 +238,7 @@ pub trait WholeStreamCommand: Send + Sync {
|
|||||||
|
|
||||||
// Custom commands are blocks, so we can use the information in the block to also
|
// Custom commands are blocks, so we can use the information in the block to also
|
||||||
// implement a WholeStreamCommand
|
// implement a WholeStreamCommand
|
||||||
|
#[allow(clippy::suspicious_else_formatting)]
|
||||||
#[async_trait]
|
#[async_trait]
|
||||||
impl WholeStreamCommand for Block {
|
impl WholeStreamCommand for Block {
|
||||||
fn name(&self) -> &str {
|
fn name(&self) -> &str {
|
||||||
|
@ -35,7 +35,7 @@ fn from_attributes_to_value(attributes: &[roxmltree::Attribute], tag: impl Into<
|
|||||||
collected.into_value()
|
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();
|
let tag = tag.into();
|
||||||
|
|
||||||
if n.is_element() {
|
if n.is_element() {
|
||||||
|
@ -59,7 +59,7 @@ pub async fn bool_command(args: CommandArgs) -> Result<OutputStream, ShellError>
|
|||||||
if let Some(prob) = bias {
|
if let Some(prob) = bias {
|
||||||
probability = *prob as f64;
|
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 {
|
if !probability_is_valid {
|
||||||
return Err(ShellError::labeled_error(
|
return Err(ShellError::labeled_error(
|
||||||
|
@ -197,7 +197,7 @@ async fn seq_dates(args: CommandArgs) -> Result<OutputStream, ShellError> {
|
|||||||
let clone = i.clone();
|
let clone = i.clone();
|
||||||
i.to_value(clone.tag)
|
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 {
|
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 {
|
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(|_| {
|
SubstringText(start, _) => start.trim().parse().map_err(|_| {
|
||||||
ShellError::labeled_error(
|
ShellError::labeled_error(
|
||||||
"could not perform substring",
|
"could not perform substring",
|
||||||
@ -262,7 +262,7 @@ fn process_arguments(range: Value, name: impl Into<Tag>) -> Result<(isize, isize
|
|||||||
};
|
};
|
||||||
|
|
||||||
let end = match &search {
|
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(|_| {
|
SubstringText(_, end) => end.trim().parse().map_err(|_| {
|
||||||
ShellError::labeled_error(
|
ShellError::labeled_error(
|
||||||
"could not perform substring",
|
"could not perform substring",
|
||||||
|
@ -75,7 +75,7 @@ fn values_to_entries(
|
|||||||
let mut row: Vec<StyledString> = headers
|
let mut row: Vec<StyledString> = headers
|
||||||
.iter()
|
.iter()
|
||||||
.map(|d: &StyledString| {
|
.map(|d: &StyledString| {
|
||||||
if d.contents == "" {
|
if d.contents.is_empty() {
|
||||||
match value {
|
match value {
|
||||||
Value {
|
Value {
|
||||||
value: UntaggedValue::Row(..),
|
value: UntaggedValue::Row(..),
|
||||||
|
@ -284,7 +284,7 @@ async fn to_html(args: CommandArgs) -> Result<OutputStream, ShellError> {
|
|||||||
let input: Vec<Value> = input.collect().await;
|
let input: Vec<Value> = input.collect().await;
|
||||||
let headers = nu_protocol::merge_descriptors(&input);
|
let headers = nu_protocol::merge_descriptors(&input);
|
||||||
let headers = Some(headers)
|
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 output_string = String::new();
|
||||||
let mut regex_hm: HashMap<u32, (&str, String)> = HashMap::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 escaped_headers: Vec<String> = Vec::new();
|
||||||
let mut column_widths: Vec<usize> = 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 {
|
for header in &headers {
|
||||||
let escaped_header_string = htmlescape::encode_minimal(&header);
|
let escaped_header_string = htmlescape::encode_minimal(&header);
|
||||||
column_widths.push(escaped_header_string.len());
|
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::collections::HashSet;
|
||||||
use std::io::Cursor;
|
use std::io::Cursor;
|
||||||
use std::io::Write;
|
use std::io::Write;
|
||||||
use std::iter::FromIterator;
|
|
||||||
|
|
||||||
pub struct ToXML;
|
pub struct ToXML;
|
||||||
|
|
||||||
@ -77,7 +76,7 @@ pub fn get_children(row: &Value) -> Option<&Vec<Value>> {
|
|||||||
|
|
||||||
pub fn is_xml_row(row: &Value) -> bool {
|
pub fn is_xml_row(row: &Value) -> bool {
|
||||||
if let UntaggedValue::Row(r) = &row.value {
|
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 children: String = "children".to_string();
|
||||||
let attributes: String = "attributes".to_string();
|
let attributes: String = "attributes".to_string();
|
||||||
return keys.contains(&children) && keys.contains(&attributes) && keys.len() == 2;
|
return keys.contains(&children) && keys.contains(&attributes) && keys.len() == 2;
|
||||||
|
@ -38,7 +38,7 @@ impl Completer for CommandCompleter {
|
|||||||
})
|
})
|
||||||
.collect();
|
.collect();
|
||||||
|
|
||||||
if partial != "" {
|
if !partial.is_empty() {
|
||||||
let path_completer = crate::completion::path::PathCompleter;
|
let path_completer = crate::completion::path::PathCompleter;
|
||||||
let path_results = path_completer.path_suggestions(partial, matcher);
|
let path_results = path_completer.path_suggestions(partial, matcher);
|
||||||
let iter = path_results.into_iter().filter_map(|path_suggestion| {
|
let iter = path_results.into_iter().filter_map(|path_suggestion| {
|
||||||
|
@ -22,7 +22,7 @@ impl PathCompleter {
|
|||||||
None => ("", expanded),
|
None => ("", expanded),
|
||||||
};
|
};
|
||||||
|
|
||||||
let base_dir = if base_dir_name == "" {
|
let base_dir = if base_dir_name.is_empty() {
|
||||||
PathBuf::from(".")
|
PathBuf::from(".")
|
||||||
} else {
|
} else {
|
||||||
#[cfg(feature = "directories")]
|
#[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());
|
let mut pn = ParseNumber::new(self.str_buf.iter().cloned());
|
||||||
match pn.parse(false) {
|
match pn.parse(false) {
|
||||||
Ok(Number::F64(v)) => {
|
Ok(Number::F64(v)) => {
|
||||||
@ -435,7 +435,7 @@ where
|
|||||||
|
|
||||||
let n2 = self.decode_hex_escape()?;
|
let n2 = self.decode_hex_escape()?;
|
||||||
|
|
||||||
if n2 < 0xDC00 || n2 > 0xDFFF {
|
if !(0xDC00..=0xDFFF).contains(&n2) {
|
||||||
return Err(self
|
return Err(self
|
||||||
.rdr
|
.rdr
|
||||||
.error(ErrorCode::LoneLeadingSurrogateInHexEscape));
|
.error(ErrorCode::LoneLeadingSurrogateInHexEscape));
|
||||||
|
@ -107,7 +107,7 @@ impl Value {
|
|||||||
}
|
}
|
||||||
s.parse().ok()
|
s.parse().ok()
|
||||||
}
|
}
|
||||||
if pointer == "" {
|
if pointer.is_empty() {
|
||||||
return Some(self);
|
return Some(self);
|
||||||
}
|
}
|
||||||
if !pointer.starts_with('/') {
|
if !pointer.starts_with('/') {
|
||||||
|
@ -399,7 +399,7 @@ impl Tag {
|
|||||||
self.span.slice(source)
|
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()
|
self.span.slice(source).to_string()
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -407,7 +407,7 @@ impl Tag {
|
|||||||
self.span.slice(source).tagged(self)
|
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)
|
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()
|
self.slice(source).to_string()
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -603,7 +603,7 @@ impl Span {
|
|||||||
self.slice(source).spanned(*self)
|
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)
|
self.slice(source).to_string().spanned(*self)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -46,10 +46,7 @@ impl TextStyle {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn bold(&self, bool_value: Option<bool>) -> TextStyle {
|
pub fn bold(&self, bool_value: Option<bool>) -> TextStyle {
|
||||||
let bv = match bool_value {
|
let bv = bool_value.unwrap_or(false);
|
||||||
Some(v) => v,
|
|
||||||
None => false,
|
|
||||||
};
|
|
||||||
|
|
||||||
TextStyle {
|
TextStyle {
|
||||||
alignment: self.alignment,
|
alignment: self.alignment,
|
||||||
|
@ -74,7 +74,7 @@ pub fn split_sublines(input: &str) -> Vec<Vec<Subline>> {
|
|||||||
.collect::<Vec<_>>()
|
.collect::<Vec<_>>()
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn column_width<'a>(input: &[Vec<Subline<'a>>]) -> usize {
|
pub fn column_width(input: &[Vec<Subline>]) -> usize {
|
||||||
let mut max = 0;
|
let mut max = 0;
|
||||||
|
|
||||||
for line in input {
|
for line in input {
|
||||||
@ -100,7 +100,7 @@ pub fn column_width<'a>(input: &[Vec<Subline<'a>>]) -> usize {
|
|||||||
max
|
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;
|
use unicode_width::UnicodeWidthChar;
|
||||||
|
|
||||||
let mut output = vec![];
|
let mut output = vec![];
|
||||||
|
@ -79,7 +79,7 @@ impl Inc {
|
|||||||
Ok(UntaggedValue::int(i + 1).into_value(value.tag()))
|
Ok(UntaggedValue::int(i + 1).into_value(value.tag()))
|
||||||
}
|
}
|
||||||
UntaggedValue::Primitive(Primitive::Filesize(b)) => {
|
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)) => {
|
UntaggedValue::Primitive(Primitive::String(ref s)) => {
|
||||||
Ok(self.apply(&s)?.into_value(value.tag()))
|
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;
|
term_width = value.as_u64().unwrap_or(term_width as u64) as usize;
|
||||||
}
|
}
|
||||||
"tab_width" => {
|
"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),
|
"colored_output" => colored_output = value.as_bool().unwrap_or(true),
|
||||||
"true_color" => true_color = 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 {
|
fn comma_concat(acc: String, current: String) -> String {
|
||||||
if acc == "" {
|
if acc.is_empty() {
|
||||||
current
|
current
|
||||||
} else {
|
} else {
|
||||||
format!("{}, {}", acc, current)
|
format!("{}, {}", acc, current)
|
||||||
|
Loading…
Reference in New Issue
Block a user