mirror of
https://github.com/nushell/nushell.git
synced 2025-08-09 07:05:47 +02:00
Apply nightly clippy lints (#9654)
# Description - A new one is the removal of unnecessary `#` in raw strings without `"` inside. - https://rust-lang.github.io/rust-clippy/master/index.html#/needless_raw_string_hashes - The automatically applied removal of `.into_iter()` touched several places where #9648 will change to the use of the record API. If necessary I can remove them @IanManske to avoid churn with this PR. - Manually applied `.try_fold` in two places - Removed a dead `if` - Manual: Combat rightward-drift with early return
This commit is contained in:
committed by
GitHub
parent
ad11e25fc5
commit
bd0032898f
@ -67,7 +67,7 @@ impl Command for Start {
|
||||
} else {
|
||||
// open crate does not allow opening URL without prefix
|
||||
let path_with_prefix = Path::new("https://").join(&path.item);
|
||||
let common_domains = vec!["com", "net", "org", "edu", "sh"];
|
||||
let common_domains = ["com", "net", "org", "edu", "sh"];
|
||||
if let Some(url) = path_with_prefix.to_str() {
|
||||
let url = url::Url::parse(url).map_err(|_| {
|
||||
ShellError::GenericError(
|
||||
|
@ -98,7 +98,7 @@ impl Command for Items {
|
||||
PipelineData::Empty => Ok(PipelineData::Empty),
|
||||
PipelineData::Value(Value::Record { cols, vals, .. }, ..) => Ok(cols
|
||||
.into_iter()
|
||||
.zip(vals.into_iter())
|
||||
.zip(vals)
|
||||
.map_while(run_for_each_item)
|
||||
.into_pipeline_data(ctrlc)),
|
||||
// Errors
|
||||
|
@ -250,8 +250,6 @@ fn move_record_columns(
|
||||
}
|
||||
}
|
||||
|
||||
if columns.is_empty() {}
|
||||
|
||||
let mut out_cols: Vec<String> = Vec::with_capacity(inp_cols.len());
|
||||
let mut out_vals: Vec<Value> = Vec::with_capacity(inp_vals.len());
|
||||
|
||||
|
@ -105,7 +105,7 @@ only unwrap the outer list, and leave the variable's contents untouched."#
|
||||
|
||||
Ok(vec
|
||||
.into_iter()
|
||||
.chain(input.into_iter())
|
||||
.chain(input)
|
||||
.into_pipeline_data(engine_state.ctrlc.clone())
|
||||
.set_metadata(metadata))
|
||||
}
|
||||
|
@ -98,7 +98,7 @@ impl Command for Zip {
|
||||
|
||||
Ok(input
|
||||
.into_iter()
|
||||
.zip(other.into_pipeline_data().into_iter())
|
||||
.zip(other.into_pipeline_data())
|
||||
.map(move |(x, y)| Value::List {
|
||||
vals: vec![x, y],
|
||||
span: head,
|
||||
|
@ -355,7 +355,7 @@ fn parse_attributes(
|
||||
vals: Vec<Value>,
|
||||
) -> Result<IndexMap<String, String>, ShellError> {
|
||||
let mut h = IndexMap::new();
|
||||
for (k, v) in cols.into_iter().zip(vals.into_iter()) {
|
||||
for (k, v) in cols.into_iter().zip(vals) {
|
||||
if let Value::String { val, .. } = v {
|
||||
h.insert(k, val);
|
||||
} else {
|
||||
|
@ -155,34 +155,30 @@ pub fn highlight_search_in_table(
|
||||
});
|
||||
};
|
||||
|
||||
let has_match = cols.iter().zip(vals.iter_mut()).fold(
|
||||
Ok(false),
|
||||
|acc: Result<bool, ShellError>, (col, val)| {
|
||||
if searched_cols.contains(&col.as_str()) {
|
||||
if let Value::String { val: s, span } = val {
|
||||
if s.to_lowercase().contains(&search_string) {
|
||||
*val = Value::String {
|
||||
val: highlight_search_string(
|
||||
s,
|
||||
orig_search_string,
|
||||
string_style,
|
||||
highlight_style,
|
||||
)?,
|
||||
span: *span,
|
||||
};
|
||||
Ok(true)
|
||||
} else {
|
||||
// column does not contain the searched string
|
||||
acc
|
||||
}
|
||||
} else {
|
||||
// ignore non-string values
|
||||
acc
|
||||
}
|
||||
} else {
|
||||
let has_match = cols.iter().zip(vals.iter_mut()).try_fold(
|
||||
false,
|
||||
|acc: bool, (col, val)| -> Result<bool, ShellError> {
|
||||
if !searched_cols.contains(&col.as_str()) {
|
||||
// don't search this column
|
||||
acc
|
||||
return Ok(acc);
|
||||
}
|
||||
if let Value::String { val: s, span } = val {
|
||||
if s.to_lowercase().contains(&search_string) {
|
||||
*val = Value::String {
|
||||
val: highlight_search_string(
|
||||
s,
|
||||
orig_search_string,
|
||||
string_style,
|
||||
highlight_style,
|
||||
)?,
|
||||
span: *span,
|
||||
};
|
||||
return Ok(true);
|
||||
}
|
||||
}
|
||||
// column does not contain the searched string
|
||||
// ignore non-string values
|
||||
Ok(acc)
|
||||
},
|
||||
)?;
|
||||
|
||||
|
@ -100,8 +100,8 @@ impl Command for SubCommand {
|
||||
let url_components = cols
|
||||
.iter()
|
||||
.zip(vals.iter())
|
||||
.fold(Ok(UrlComponents::new()), |url, (k, v)| {
|
||||
url?.add_component(k.clone(), v.clone(), span)
|
||||
.try_fold(UrlComponents::new(), |url, (k, v)| {
|
||||
url.add_component(k.clone(), v.clone(), span)
|
||||
});
|
||||
|
||||
url_components?.to_url(span)
|
||||
|
@ -515,12 +515,12 @@ impl Command for AnsiCommand {
|
||||
)
|
||||
.switch(
|
||||
"escape", // \x1b[
|
||||
r#"escape sequence without the escape character(s) ('\x1b[' is not required)"#,
|
||||
r"escape sequence without the escape character(s) ('\x1b[' is not required)",
|
||||
Some('e'),
|
||||
)
|
||||
.switch(
|
||||
"osc", // \x1b]
|
||||
r#"operating system command (osc) escape sequence without the escape character(s) ('\x1b]' is not required)"#,
|
||||
r"operating system command (osc) escape sequence without the escape character(s) ('\x1b]' is not required)",
|
||||
Some('o'),
|
||||
)
|
||||
.switch("list", "list available ansi code names", Some('l'))
|
||||
|
@ -128,12 +128,12 @@ impl Command for SubCommand {
|
||||
},
|
||||
Example {
|
||||
description: "Find and replace contents without using the replace parameter as a regular expression",
|
||||
example: r#"'dogs_$1_cats' | str replace '\$1' '$2' -n"#,
|
||||
example: r"'dogs_$1_cats' | str replace '\$1' '$2' -n",
|
||||
result: Some(Value::test_string("dogs_$2_cats")),
|
||||
},
|
||||
Example {
|
||||
description: "Find and replace the first occurrence using string replacement *not* regular expressions",
|
||||
example: r#"'c:\some\cool\path' | str replace 'c:\some\cool' '~' -s"#,
|
||||
example: r"'c:\some\cool\path' | str replace 'c:\some\cool' '~' -s",
|
||||
result: Some(Value::test_string("~\\path")),
|
||||
},
|
||||
Example {
|
||||
@ -148,7 +148,7 @@ impl Command for SubCommand {
|
||||
},
|
||||
Example {
|
||||
description: "Find and replace with fancy-regex",
|
||||
example: r#"'a successful b' | str replace '\b([sS])uc(?:cs|s?)e(ed(?:ed|ing|s?)|ss(?:es|ful(?:ly)?|i(?:ons?|ve(?:ly)?)|ors?)?)\b' '${1}ucce$2'"#,
|
||||
example: r"'a successful b' | str replace '\b([sS])uc(?:cs|s?)e(ed(?:ed|ing|s?)|ss(?:es|ful(?:ly)?|i(?:ons?|ve(?:ly)?)|ors?)?)\b' '${1}ucce$2'",
|
||||
result: Some(Value::test_string("a successful b")),
|
||||
},
|
||||
Example {
|
||||
|
@ -114,7 +114,7 @@ prints out the list properly."#
|
||||
// dbg!("value::record");
|
||||
let mut items = vec![];
|
||||
|
||||
for (i, (c, v)) in cols.into_iter().zip(vals.into_iter()).enumerate() {
|
||||
for (i, (c, v)) in cols.into_iter().zip(vals).enumerate() {
|
||||
items.push((i, c, v.into_string(", ", config)))
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user