Skip to content

Commit

Permalink
Apply nightly clippy lints (#9654)
Browse files Browse the repository at this point in the history
# 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
  • Loading branch information
sholderbach committed Jul 11, 2023
1 parent ad11e25 commit bd00328
Show file tree
Hide file tree
Showing 20 changed files with 49 additions and 63 deletions.
2 changes: 1 addition & 1 deletion crates/nu-cli/src/commands/keybindings_list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
5 changes: 1 addition & 4 deletions crates/nu-cli/src/completions/command_completions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion crates/nu-cli/src/completions/variable_completions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion crates/nu-cmd-dataframe/src/dataframe/eager/sql_context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down
4 changes: 2 additions & 2 deletions crates/nu-cmd-extra/src/extra/filters/update_cells.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
};
Expand Down Expand Up @@ -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(
Expand Down
3 changes: 1 addition & 2 deletions crates/nu-cmd-lang/src/example_support.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 \
Expand Down
2 changes: 1 addition & 1 deletion crates/nu-command/src/filesystem/start.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
2 changes: 1 addition & 1 deletion crates/nu-command/src/filters/items.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 0 additions & 2 deletions crates/nu-command/src/filters/move_.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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());

Expand Down
2 changes: 1 addition & 1 deletion crates/nu-command/src/filters/prepend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}
Expand Down
2 changes: 1 addition & 1 deletion crates/nu-command/src/filters/zip.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion crates/nu-command/src/formats/to/xml.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
48 changes: 22 additions & 26 deletions crates/nu-command/src/help/help_.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
},
)?;

Expand Down
4 changes: 2 additions & 2 deletions crates/nu-command/src/network/url/join.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions crates/nu-command/src/platform/ansi/ansi_.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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'))
Expand Down
6 changes: 3 additions & 3 deletions crates/nu-command/src/strings/str_/replace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion crates/nu-command/src/viewers/griddle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)))
}

Expand Down
4 changes: 2 additions & 2 deletions crates/nu-parser/src/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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![])
Expand Down Expand Up @@ -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(),
Expand Down
6 changes: 1 addition & 5 deletions crates/nu-protocol/src/value/stream.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
8 changes: 4 additions & 4 deletions tests/plugins/formats/vcf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -29,7 +29,7 @@ fn infers_types() {
TEL;TYPE=CELL:(890) 123-4567
CATEGORIES:Band,myContacts
END:VCARD
"#,
",
)]);

let cwd = dirs.test();
Expand All @@ -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
Expand All @@ -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();
Expand Down

0 comments on commit bd00328

Please sign in to comment.