Fix a bunch of future clippy warnings (#3586)

* Fix a bunch of future clippy warnings

* Fix a bunch of future clippy warnings
This commit is contained in:
JT
2021-06-10 07:08:12 +12:00
committed by GitHub
parent e8a2250ef8
commit 383e874166
86 changed files with 237 additions and 258 deletions

View File

@ -183,9 +183,9 @@ fn add_months_of_year_to_table(
}
let add_month_to_table_result = add_month_to_table(
&args,
args,
&mut calendar_vec_deque,
&tag,
tag,
selected_year,
month_number,
new_current_day_option,

View File

@ -625,26 +625,26 @@ mod tests {
#[test]
fn checks_quotes_from_argument_to_be_passed_in() {
assert_eq!(argument_is_quoted(""), false);
assert!(!argument_is_quoted(""));
assert_eq!(argument_is_quoted("'"), false);
assert_eq!(argument_is_quoted("'a"), false);
assert_eq!(argument_is_quoted("a"), false);
assert_eq!(argument_is_quoted("a'"), false);
assert_eq!(argument_is_quoted("''"), true);
assert!(!argument_is_quoted("'"));
assert!(!argument_is_quoted("'a"));
assert!(!argument_is_quoted("a"));
assert!(!argument_is_quoted("a'"));
assert!(argument_is_quoted("''"));
assert_eq!(argument_is_quoted(r#"""#), false);
assert_eq!(argument_is_quoted(r#""a"#), false);
assert_eq!(argument_is_quoted(r#"a"#), false);
assert_eq!(argument_is_quoted(r#"a""#), false);
assert_eq!(argument_is_quoted(r#""""#), true);
assert!(!argument_is_quoted(r#"""#));
assert!(!argument_is_quoted(r#""a"#));
assert!(!argument_is_quoted(r#"a"#));
assert!(!argument_is_quoted(r#"a""#));
assert!(argument_is_quoted(r#""""#));
assert_eq!(argument_is_quoted("'andrés"), false);
assert_eq!(argument_is_quoted("andrés'"), false);
assert_eq!(argument_is_quoted(r#""andrés"#), false);
assert_eq!(argument_is_quoted(r#"andrés""#), false);
assert_eq!(argument_is_quoted("'andrés'"), true);
assert_eq!(argument_is_quoted(r#""andrés""#), true);
assert!(!argument_is_quoted("'andrés"));
assert!(!argument_is_quoted("andrés'"));
assert!(!argument_is_quoted(r#""andrés"#));
assert!(!argument_is_quoted(r#"andrés""#));
assert!(argument_is_quoted("'andrés'"));
assert!(argument_is_quoted(r#""andrés""#));
}
#[test]

View File

@ -73,7 +73,7 @@ impl Iterator for EachGroupIterator {
let mut group = vec![];
let mut current_count = 0;
while let Some(next) = self.input.next() {
for next in &mut self.input {
group.push(next);
current_count += 1;

View File

@ -85,7 +85,7 @@ fn flat_value(
} = value
{
if column_requested.is_none() && !columns.is_empty() {
if out.contains_key(&column) {
if out.contains_key(column) {
out.insert_value(format!("{}_{}", column, column), value.clone());
} else {
out.insert_value(column, value.clone());
@ -141,7 +141,7 @@ fn flat_value(
}
} else if a_table.is_none() {
a_table = Some(TableInside::Entries(
&column,
column,
&value.tag,
value.table_entries().collect(),
))

View File

@ -56,7 +56,7 @@ fn format_command(args: CommandArgs) -> Result<OutputStream, ShellError> {
for command in &*commands {
match command {
FormatCommand::Text(s) => {
output.push_str(&s);
output.push_str(s);
}
FormatCommand::Column(c) => {
// FIXME: use the correct spans
@ -97,7 +97,7 @@ fn format(input: &str) -> Vec<FormatCommand> {
loop {
let mut before = String::new();
while let Some(c) = loop_input.next() {
for c in &mut loop_input {
if c == '{' {
break;
}
@ -110,7 +110,7 @@ fn format(input: &str) -> Vec<FormatCommand> {
// Look for column as we're now at one
let mut column = String::new();
while let Some(c) = loop_input.next() {
for c in &mut loop_input {
if c == '}' {
break;
}

View File

@ -102,7 +102,7 @@ fn from_eml(args: CommandArgs) -> Result<OutputStream, ShellError> {
}
for HeaderField { name, value } in eml.headers.iter() {
dict.insert_untagged(name, headerfieldvalue_to_value(&tag, &value));
dict.insert_untagged(name, headerfieldvalue_to_value(&tag, value));
}
if let Some(body) = eml.body {

View File

@ -60,7 +60,7 @@ fn from_node_to_value(n: &roxmltree::Node, tag: impl Into<Tag>) -> Value {
let mut collected = TaggedDictBuilder::new(&tag);
let attribute_value: Value = from_attributes_to_value(&n.attributes(), &tag);
let attribute_value: Value = from_attributes_to_value(n.attributes(), &tag);
let mut row = TaggedDictBuilder::new(&tag);
row.insert_untagged(

View File

@ -99,7 +99,7 @@ fn convert_yaml_value_to_nu_value(
.first()
.and_then(|e| match e {
(serde_yaml::Value::String(s), serde_yaml::Value::Null) => Some(
UntaggedValue::string("{{ ".to_owned() + &s + " }}")
UntaggedValue::string("{{ ".to_owned() + s + " }}")
.into_value(tag),
),
_ => None,

View File

@ -120,7 +120,7 @@ pub fn get_column_path(path: &ColumnPath, obj: &Value) -> Result<Value, ShellErr
_ => {}
}
if let Some(suggestions) = did_you_mean(&obj_source, column_path_tried.as_string()) {
if let Some(suggestions) = did_you_mean(obj_source, column_path_tried.as_string()) {
ShellError::labeled_error(
"Unknown column",
format!("did you mean '{}'?", suggestions[0]),
@ -146,7 +146,7 @@ pub fn get_column_path_from_table_error(
let suggestions: IndexSet<_> = rows
.iter()
.filter_map(|r| did_you_mean(&r, column_path_tried.as_string()))
.filter_map(|r| did_you_mean(r, column_path_tried.as_string()))
.map(|s| s[0].to_owned())
.collect();
let mut existing_columns: IndexSet<_> = IndexSet::default();
@ -223,7 +223,7 @@ pub fn get_column_from_row_error(
} => {
let primary_label = format!("There isn't a column named '{}'", &column);
did_you_mean(&obj_source, column_path_tried.as_string()).map(|suggestions| {
did_you_mean(obj_source, column_path_tried.as_string()).map(|suggestions| {
ShellError::labeled_error_with_secondary(
"Unknown column",
primary_label,

View File

@ -241,16 +241,16 @@ pub fn group(
let block = Box::new(move |_, row: &Value| {
match row.get_data_by_key(column_name.borrow_spanned()) {
Some(group_key) => Ok(as_string(&group_key)?),
None => Err(suggestions(column_name.borrow_tagged(), &row)),
None => Err(suggestions(column_name.borrow_tagged(), row)),
}
});
nu_data::utils::group(&values, &Some(block), &name)
nu_data::utils::group(values, &Some(block), &name)
}
Grouper::ByColumn(None) => {
let block = Box::new(move |_, row: &Value| as_string(row));
nu_data::utils::group(&values, &Some(block), &name)
nu_data::utils::group(values, &Some(block), &name)
}
Grouper::ByBlock => Err(ShellError::unimplemented(
"Block not implemented: This should never happen.",

View File

@ -91,7 +91,7 @@ pub fn group_by_date(args: CommandArgs) -> Result<OutputStream, ShellError> {
let block = Box::new(move |_, row: &Value| {
let group_key = row
.get_data_by_key(column_name.borrow_spanned())
.ok_or_else(|| suggestions(column_name.borrow_tagged(), &row));
.ok_or_else(|| suggestions(column_name.borrow_tagged(), row));
group_key?.format("%Y-%m-%d")
});
@ -107,7 +107,7 @@ pub fn group_by_date(args: CommandArgs) -> Result<OutputStream, ShellError> {
let block = Box::new(move |_, row: &Value| {
let group_key = row
.get_data_by_key(column_name.borrow_spanned())
.ok_or_else(|| suggestions(column_name.borrow_tagged(), &row));
.ok_or_else(|| suggestions(column_name.borrow_tagged(), row));
group_key?.format(&fmt)
});

View File

@ -48,7 +48,7 @@ fn help(args: CommandArgs) -> Result<ActionStream, ShellError> {
// Internal only commands shouldn't be displayed
.filter(|cmd_name| {
scope
.get_command(&cmd_name)
.get_command(cmd_name)
.filter(|command| !command.is_internal())
.is_some()
})
@ -63,7 +63,7 @@ fn help(args: CommandArgs) -> Result<ActionStream, ShellError> {
) -> Result<(), ShellError> {
let document_tag = rest[0].tag.clone();
let value = command_dict(
scope.get_command(&cmd_name).ok_or_else(|| {
scope.get_command(cmd_name).ok_or_else(|| {
ShellError::labeled_error(
format!("Could not load {}", cmd_name),
"could not load command",

View File

@ -165,11 +165,9 @@ pub fn histogram(args: CommandArgs) -> Result<ActionStream, ShellError> {
);
fact.insert_untagged("percentage", UntaggedValue::string(fmt_percentage));
let string = std::iter::repeat("*")
.take(percentage.as_u64().map_err(|_| {
ShellError::labeled_error("expected a number", "expected a number", &name)
})? as usize)
.collect::<String>();
let string = "*".repeat(percentage.as_u64().map_err(|_| {
ShellError::labeled_error("expected a number", "expected a number", &name)
})? as usize);
fact.insert_untagged(&frequency_column_name, UntaggedValue::string(string));
@ -209,7 +207,7 @@ fn splitter(
)),
}
}),
None => Box::new(move |_, row: &Value| nu_value_ext::as_string(&row)),
None => Box::new(move |_, row: &Value| nu_value_ext::as_string(row)),
}
}

View File

@ -101,7 +101,7 @@ fn if_command(raw_args: CommandArgs) -> Result<OutputStream, ShellError> {
context.scope.add_vars(&condition.captured.entries);
//FIXME: should we use the scope that's brought in as well?
let condition = evaluate_baseline_expr(&cond, &*context);
let condition = evaluate_baseline_expr(cond, &*context);
match condition {
Ok(condition) => match condition.as_bool() {
Ok(b) => {

View File

@ -98,7 +98,7 @@ pub fn letcmd(args: CommandArgs) -> Result<ActionStream, ShellError> {
};
ctx.scope.enter_scope();
let value = evaluate_baseline_expr(&expr, &ctx);
let value = evaluate_baseline_expr(expr, &ctx);
ctx.scope.exit_scope();
let value = value?;

View File

@ -46,7 +46,7 @@ pub fn mode(values: &[Value], name: &Tag) -> Result<Value, ShellError> {
let mut max_freq = -1;
let mut modes = Vec::<Value>::new();
for (value, frequency) in frequency_map.iter() {
match max_freq.cmp(&frequency) {
match max_freq.cmp(frequency) {
Ordering::Less => {
max_freq = *frequency;
modes.clear();

View File

@ -60,7 +60,7 @@ pub fn run_with_numerical_functions_on_stream(
pub fn calculate(values: &[Value], name: &Tag, mf: MathFunction) -> Result<Value, ShellError> {
if values.iter().all(|v| v.is_primitive()) {
mf(&values, &name)
mf(values, name)
} else {
// If we are not dealing with Primitives, then perhaps we are dealing with a table
// Create a key for each column name
@ -78,7 +78,7 @@ pub fn calculate(values: &[Value], name: &Tag, mf: MathFunction) -> Result<Value
// The mathematical function operates over the columns of the table
let mut column_totals = IndexMap::new();
for (col_name, col_vals) in column_values {
if let Ok(out) = mf(&col_vals, &name) {
if let Ok(out) = mf(&col_vals, name) {
column_totals.insert(col_name, out);
}
}

View File

@ -181,7 +181,7 @@ where
let cloned_args = Arc::clone(&args);
ret = match ret.swap_data_by_column_path(
path,
Box::new(move |old| handle_value(&action, &old, span, cloned_args)),
Box::new(move |old| handle_value(&action, old, span, cloned_args)),
) {
Ok(v) => v,
Err(e) => Value::error(e),

View File

@ -77,14 +77,12 @@ fn roll_by(value: Value, options: &Arguments) -> Option<Vec<Value>> {
let direction = options.direction();
if value.is_row() {
let columns = value.data_descriptors();
if options.move_headers() {
let columns = value.data_descriptors();
if let Some(fields) = rotate(columns, &options.by, direction) {
return Some(vec![select_fields(&value, &fields, &tag)]);
}
} else {
let columns = value.data_descriptors();
let values_rotated = rotate(
value
.row_entries()

View File

@ -135,7 +135,7 @@ fn maybe_autocd_dir(cmd: &ExternalCommand, ctx: &mut EvaluationContext) -> Optio
|| (cmd.args.is_empty()
&& PathBuf::from(name).is_dir()
&& dunce::canonicalize(name).is_ok()
&& !ctx.host.lock().is_external_cmd(&name))
&& !ctx.host.lock().is_external_cmd(name))
{
Some(name)
} else {

View File

@ -65,7 +65,7 @@ fn select(args: CommandArgs) -> Result<OutputStream, ShellError> {
for path in &columns {
let fetcher = get_data_by_column_path(
&value,
&path,
path,
move |obj_source, path_member_tried, error| {
if let PathMember {
unspanned: UnspannedPathMember::String(column),

View File

@ -71,16 +71,16 @@ pub fn split(
let block = Box::new(move |_, row: &Value| {
match row.get_data_by_key(column_name.borrow_spanned()) {
Some(group_key) => Ok(as_string(&group_key)?),
None => Err(suggestions(column_name.borrow_tagged(), &row)),
None => Err(suggestions(column_name.borrow_tagged(), row)),
}
});
nu_data::utils::split(&values, &Some(block), &name)
nu_data::utils::split(values, &Some(block), &name)
}
Grouper::ByColumn(None) => {
let block = Box::new(move |_, row: &Value| as_string(row));
nu_data::utils::split(&values, &Some(block), &name)
nu_data::utils::split(values, &Some(block), &name)
}
}
}

View File

@ -62,7 +62,7 @@ pub fn collect(args: CommandArgs) -> Result<ActionStream, ShellError> {
match strings {
Ok(strings) => {
let output = strings.join(&separator);
let output = strings.join(separator);
Ok(ActionStream::one(ReturnSuccess::value(
UntaggedValue::string(output).into_value(tag),

View File

@ -114,7 +114,7 @@ mod tests {
let pattern = ".toml";
let expected = UntaggedValue::boolean(true).into_untagged_value();
let actual = action(&word, &pattern, Tag::unknown()).unwrap();
let actual = action(&word, pattern, Tag::unknown()).unwrap();
assert_eq!(actual, expected);
}
@ -124,7 +124,7 @@ mod tests {
let pattern = "Car";
let expected = UntaggedValue::boolean(false).into_untagged_value();
let actual = action(&word, &pattern, Tag::unknown()).unwrap();
let actual = action(&word, pattern, Tag::unknown()).unwrap();
assert_eq!(actual, expected);
}
}

View File

@ -101,7 +101,7 @@ fn action(
) -> Result<Value, ShellError> {
match &input.value {
UntaggedValue::Primitive(Primitive::String(s)) => {
let FindReplace(find, replacement) = FindReplace(&find, &replace);
let FindReplace(find, replacement) = FindReplace(find, replace);
let regex = Regex::new(find);
Ok(match regex {

View File

@ -138,7 +138,7 @@ fn action(
None => UntaggedValue::string("").into_value(&tag),
};
let r = process_range(&input, &range)?;
let r = process_range(input, &range)?;
match &input.value {
UntaggedValue::Primitive(Primitive::String(s)) => {

View File

@ -114,7 +114,7 @@ mod tests {
let pattern = "Car";
let expected = UntaggedValue::boolean(true).into_untagged_value();
let actual = action(&word, &pattern, Tag::unknown()).unwrap();
let actual = action(&word, pattern, Tag::unknown()).unwrap();
assert_eq!(actual, expected);
}
@ -124,7 +124,7 @@ mod tests {
let pattern = ".toml";
let expected = UntaggedValue::boolean(false).into_untagged_value();
let actual = action(&word, &pattern, Tag::unknown()).unwrap();
let actual = action(&word, pattern, Tag::unknown()).unwrap();
assert_eq!(actual, expected);
}
}

View File

@ -90,7 +90,7 @@ where
.map(|(k, v)| -> Result<_, ShellError> {
Ok((
k.clone(),
action(&v, tag.clone(), char_, trim_operation, mode)?,
action(v, tag.clone(), char_, trim_operation, mode)?,
))
})
.collect();

View File

@ -57,13 +57,7 @@ pub fn from_list(
.into_iter()
.map(|x| StyledString::new(x, header_style))
.collect();
let entries = values_to_entries(
values,
&mut headers,
&configuration,
starting_idx,
&color_hm,
);
let entries = values_to_entries(values, &mut headers, configuration, starting_idx, color_hm);
nu_table::Table {
headers,
data: entries,
@ -96,11 +90,11 @@ fn values_to_entries(
..
} => StyledString::new(
format_leaf(&UntaggedValue::nothing()).plain_string(100_000),
style_leaf(&UntaggedValue::nothing(), &color_hm),
style_leaf(&UntaggedValue::nothing(), color_hm),
),
_ => StyledString::new(
format_leaf(value).plain_string(100_000),
style_leaf(value, &color_hm),
style_leaf(value, color_hm),
),
}
} else {
@ -113,12 +107,12 @@ fn values_to_entries(
StyledString::new(
format_leaf(data.borrow()).plain_string(100_000),
style_leaf(data.borrow(), &color_hm),
style_leaf(data.borrow(), color_hm),
)
}
_ => StyledString::new(
format_leaf(&UntaggedValue::nothing()).plain_string(100_000),
style_leaf(&UntaggedValue::nothing(), &color_hm),
style_leaf(&UntaggedValue::nothing(), color_hm),
),
}
}

View File

@ -23,7 +23,7 @@ fn from_value_to_delimited_string(
for (k, v) in o.entries.iter() {
fields.push_back(k.clone());
values.push_back(to_string_tagged_value(&v)?);
values.push_back(to_string_tagged_value(v)?);
}
wtr.write_record(fields).expect("can not write.");
@ -50,7 +50,7 @@ fn from_value_to_delimited_string(
.delimiter(separator as u8)
.from_writer(vec![]);
let merged_descriptors = merge_descriptors(&list);
let merged_descriptors = merge_descriptors(list);
if merged_descriptors.is_empty() {
wtr.write_record(

View File

@ -285,18 +285,13 @@ fn to_html(args: CommandArgs) -> Result<OutputStream, ShellError> {
output_string.push_str("\nScreenshots of themes can be found here:\n");
output_string.push_str("https://github.com/mbadolato/iTerm2-Color-Schemes\n");
// Short circuit and return the output_string
Ok(OutputStream::one(
UntaggedValue::string(output_string).into_value(name_tag),
))
} else {
let theme_tag = match &theme {
Some(v) => &v.tag,
None => &name_tag,
};
let color_hm = get_theme_from_asset_file(dark, &theme, &theme_tag);
let color_hm = get_theme_from_asset_file(dark, &theme, theme_tag);
let color_hm = match color_hm {
Ok(c) => c,
_ => {
@ -362,11 +357,10 @@ fn to_html(args: CommandArgs) -> Result<OutputStream, ShellError> {
setup_no_color_regexes(&mut regex_hm);
output_string = run_regexes(&regex_hm, &output_string);
}
Ok(OutputStream::one(
UntaggedValue::string(output_string).into_value(name_tag),
))
}
Ok(OutputStream::one(
UntaggedValue::string(output_string).into_value(name_tag),
))
}
fn html_list(list: Vec<Value>) -> String {
@ -393,7 +387,7 @@ fn html_table(table: Vec<Value>, headers: Vec<String>) -> String {
output_string.push_str("<tr>");
for header in &headers {
output_string.push_str("<th>");
output_string.push_str(&htmlescape::encode_minimal(&header));
output_string.push_str(&htmlescape::encode_minimal(header));
output_string.push_str("</th>");
}
output_string.push_str("</tr>");

View File

@ -189,9 +189,7 @@ fn to_json(args: CommandArgs) -> Result<OutputStream, ShellError> {
serde_json_string.as_str(),
)
{
let indentation_string = std::iter::repeat(" ")
.take(pretty_u64 as usize)
.collect::<String>();
let indentation_string = " ".repeat(pretty_u64 as usize);
let serde_formatter =
serde_json::ser::PrettyFormatter::with_indent(
indentation_string.as_bytes(),

View File

@ -117,7 +117,7 @@ fn process(
})
.collect::<String>()
} else {
table(&input, pretty)
table(input, pretty)
}
}
@ -158,7 +158,7 @@ fn collect_headers(headers: &[String]) -> (Vec<String>, Vec<usize>) {
if !headers.is_empty() && (headers.len() > 1 || !headers[0].is_empty()) {
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());
escaped_headers.push(escaped_header_string);
}
@ -170,7 +170,7 @@ fn collect_headers(headers: &[String]) -> (Vec<String>, Vec<usize>) {
}
fn table(input: &[Value], pretty: bool) -> String {
let headers = nu_protocol::merge_descriptors(&input);
let headers = nu_protocol::merge_descriptors(input);
let (escaped_headers, mut column_widths) = collect_headers(&headers);

View File

@ -51,7 +51,7 @@ where
for path in &paths {
ret = ret.swap_data_by_column_path(
path,
Box::new(move |old| handle_value(&action, &old)),
Box::new(move |old| handle_value(&action, old)),
)?;
}

View File

@ -125,7 +125,7 @@ impl Iterator for WhereIterator {
type Item = Value;
fn next(&mut self) -> Option<Self::Item> {
while let Some(x) = self.input.next() {
for x in &mut self.input {
self.context.scope.enter_scope();
self.context.scope.add_vars(&self.block.captured.entries);

View File

@ -209,7 +209,7 @@ fn parse_line(line: &str, ctx: &EvaluationContext) -> Result<ClassifiedBlock, Sh
line
};
let (lite_result, err) = nu_parser::lex(&line, 0);
let (lite_result, err) = nu_parser::lex(line, 0);
if let Some(err) = err {
return Err(err.into());
}