forked from extern/nushell
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:
parent
ad11e25fc5
commit
bd0032898f
@ -59,7 +59,7 @@ impl Command for KeybindingsList {
|
||||
_input: PipelineData,
|
||||
) -> Result<PipelineData, ShellError> {
|
||||
let records = if call.named_len() == 0 {
|
||||
let all_options = vec!["modifiers", "keycodes", "edits", "modes", "events"];
|
||||
let all_options = ["modifiers", "keycodes", "edits", "modes", "events"];
|
||||
all_options
|
||||
.iter()
|
||||
.flat_map(|argument| get_records(argument, &call.head))
|
||||
|
@ -205,10 +205,7 @@ impl Completer for CommandCompletion {
|
||||
vec![]
|
||||
};
|
||||
|
||||
subcommands
|
||||
.into_iter()
|
||||
.chain(commands.into_iter())
|
||||
.collect::<Vec<_>>()
|
||||
subcommands.into_iter().chain(commands).collect::<Vec<_>>()
|
||||
}
|
||||
|
||||
fn get_sort_by(&self) -> SortBy {
|
||||
|
@ -294,7 +294,7 @@ fn recursive_value(val: Value, sublevels: Vec<Vec<u8>>) -> Value {
|
||||
vals,
|
||||
span: _,
|
||||
} => {
|
||||
for item in cols.into_iter().zip(vals.into_iter()) {
|
||||
for item in cols.into_iter().zip(vals) {
|
||||
// Check if index matches with sublevel
|
||||
if item.0.as_bytes().to_vec() == next_sublevel {
|
||||
// If matches try to fetch recursively the next
|
||||
|
@ -150,7 +150,7 @@ impl SQLContext {
|
||||
let agg_df = df.groupby(group_by).agg(agg_projection);
|
||||
let mut final_proj_pos = groupby_pos
|
||||
.into_iter()
|
||||
.chain(agg_proj_pos.into_iter())
|
||||
.chain(agg_proj_pos)
|
||||
.collect::<Vec<_>>();
|
||||
|
||||
final_proj_pos.sort_by(|(proj_pa, _), (proj_pb, _)| proj_pa.cmp(proj_pb));
|
||||
|
@ -150,7 +150,7 @@ impl Command for UpdateCells {
|
||||
.iter()
|
||||
.map(|val| val.as_string())
|
||||
.collect::<Result<Vec<String>, ShellError>>()?;
|
||||
Some(HashSet::from_iter(cols.into_iter()))
|
||||
Some(HashSet::from_iter(cols))
|
||||
}
|
||||
None => None,
|
||||
};
|
||||
@ -197,7 +197,7 @@ impl Iterator for UpdateCellIterator {
|
||||
Value::Record { vals, cols, span } => Some(Value::Record {
|
||||
vals: cols
|
||||
.iter()
|
||||
.zip(vals.into_iter())
|
||||
.zip(vals)
|
||||
.map(|(col, val)| match &self.columns {
|
||||
Some(cols) if !cols.contains(col) => val,
|
||||
_ => process_cell(
|
||||
|
@ -188,8 +188,7 @@ pub fn check_all_signature_input_output_types_entries_have_examples(
|
||||
signature: Signature,
|
||||
witnessed_type_transformations: HashSet<(Type, Type)>,
|
||||
) {
|
||||
let declared_type_transformations =
|
||||
HashSet::from_iter(signature.input_output_types.into_iter());
|
||||
let declared_type_transformations = HashSet::from_iter(signature.input_output_types);
|
||||
assert!(
|
||||
witnessed_type_transformations.is_subset(&declared_type_transformations),
|
||||
"This should not be possible (bug in test): the type transformations \
|
||||
|
@ -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,10 +155,13 @@ 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()) {
|
||||
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
|
||||
return Ok(acc);
|
||||
}
|
||||
if let Value::String { val: s, span } = val {
|
||||
if s.to_lowercase().contains(&search_string) {
|
||||
*val = Value::String {
|
||||
@ -170,19 +173,12 @@ pub fn highlight_search_in_table(
|
||||
)?,
|
||||
span: *span,
|
||||
};
|
||||
Ok(true)
|
||||
} else {
|
||||
return Ok(true);
|
||||
}
|
||||
}
|
||||
// column does not contain the searched string
|
||||
acc
|
||||
}
|
||||
} else {
|
||||
// ignore non-string values
|
||||
acc
|
||||
}
|
||||
} else {
|
||||
// don't search this column
|
||||
acc
|
||||
}
|
||||
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)))
|
||||
}
|
||||
|
||||
|
@ -4023,7 +4023,7 @@ fn parse_table_expression(working_set: &mut StateWorkingSet, span: Span) -> Expr
|
||||
|
||||
let ty = if working_set.parse_errors.len() == errors {
|
||||
let (ty, errs) = table_type(&head, &rows);
|
||||
working_set.parse_errors.extend(errs.into_iter());
|
||||
working_set.parse_errors.extend(errs);
|
||||
ty
|
||||
} else {
|
||||
Type::Table(vec![])
|
||||
@ -5039,7 +5039,7 @@ pub fn parse_expression(
|
||||
String::from_utf8(bytes)
|
||||
.expect("builtin commands bytes should be able to convert to string"),
|
||||
String::from_utf8_lossy(match spans.len() {
|
||||
1 | 2 | 3 => b"value",
|
||||
1..=3 => b"value",
|
||||
_ => working_set.get_span_contents(spans[3]),
|
||||
})
|
||||
.to_string(),
|
||||
|
@ -64,11 +64,7 @@ impl RawStream {
|
||||
pub fn chain(self, stream: RawStream) -> RawStream {
|
||||
RawStream {
|
||||
stream: Box::new(self.stream.chain(stream.stream)),
|
||||
leftover: self
|
||||
.leftover
|
||||
.into_iter()
|
||||
.chain(stream.leftover.into_iter())
|
||||
.collect(),
|
||||
leftover: self.leftover.into_iter().chain(stream.leftover).collect(),
|
||||
ctrlc: self.ctrlc,
|
||||
is_binary: self.is_binary,
|
||||
span: self.span,
|
||||
|
@ -8,7 +8,7 @@ fn infers_types() {
|
||||
Playground::setup("filter_from_vcf_test_1", |dirs, sandbox| {
|
||||
sandbox.with_files(vec![FileWithContentToBeTrimmed(
|
||||
"contacts.vcf",
|
||||
r#"
|
||||
r"
|
||||
BEGIN:VCARD
|
||||
VERSION:3.0
|
||||
FN:John Doe
|
||||
@ -29,7 +29,7 @@ fn infers_types() {
|
||||
TEL;TYPE=CELL:(890) 123-4567
|
||||
CATEGORIES:Band,myContacts
|
||||
END:VCARD
|
||||
"#,
|
||||
",
|
||||
)]);
|
||||
|
||||
let cwd = dirs.test();
|
||||
@ -48,7 +48,7 @@ fn from_vcf_text_to_table() {
|
||||
Playground::setup("filter_from_vcf_test_2", |dirs, sandbox| {
|
||||
sandbox.with_files(vec![FileWithContentToBeTrimmed(
|
||||
"contacts.txt",
|
||||
r#"
|
||||
r"
|
||||
BEGIN:VCARD
|
||||
VERSION:3.0
|
||||
FN:John Doe
|
||||
@ -62,7 +62,7 @@ fn from_vcf_text_to_table() {
|
||||
NOTE:Facebook: john.doe.3\nWebsite: \nHometown: Cleveland\, Ohio
|
||||
CATEGORIES:myContacts
|
||||
END:VCARD
|
||||
"#,
|
||||
",
|
||||
)]);
|
||||
|
||||
let cwd = dirs.test();
|
||||
|
Loading…
Reference in New Issue
Block a user