Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix ignored clippy lints #12160

Merged
merged 2 commits into from Mar 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 0 additions & 1 deletion crates/nu-command/src/debug/inspect_table.rs
Expand Up @@ -48,7 +48,6 @@ pub fn build_table(value: Value, description: String, termsize: usize) -> String

add_padding_to_widths(&mut widths);

#[allow(clippy::manual_clamp)]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah they made that generally allow again. I think this is only an undefined resolution for float. So the code below could be a safe clamp, right?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah the .max/.min solution never panics.

let width = val_table_width.max(desc_table_width).min(termsize);

let mut desc_table = Table::from_iter([[String::from("description"), desc]]);
Expand Down
1 change: 0 additions & 1 deletion crates/nu-command/src/filesystem/util.rs
Expand Up @@ -39,7 +39,6 @@ pub fn try_interaction(
(interaction, confirmed)
}

#[allow(dead_code)]
fn get_interactive_confirmation(prompt: String) -> Result<bool, Box<dyn Error>> {
let input = Input::new()
.with_prompt(prompt)
Expand Down
1 change: 0 additions & 1 deletion crates/nu-command/src/filters/reverse.rs
Expand Up @@ -66,7 +66,6 @@ impl Command for Reverse {
) -> Result<PipelineData, ShellError> {
let metadata = input.metadata();

#[allow(clippy::needless_collect)]
let v: Vec<_> = input.into_iter_strict(call.head)?.collect();
let iter = v.into_iter().rev();
Ok(iter.into_pipeline_data_with_metadata(metadata, engine_state.ctrlc.clone()))
Expand Down
4 changes: 1 addition & 3 deletions crates/nu-command/src/filters/utils.rs
Expand Up @@ -41,9 +41,7 @@ pub fn boolean_fold(

let ctrlc = engine_state.ctrlc.clone();

// TODO: This Clippy lint is incorrectly triggered in our CI for come reason
#[allow(clippy::needless_borrow)]
let eval_block = get_eval_block(&engine_state);
let eval_block = get_eval_block(engine_state);

for value in input.into_interruptible_iter(ctrlc) {
// with_env() is used here to ensure that each iteration uses
Expand Down
3 changes: 1 addition & 2 deletions crates/nu-command/src/help/help_commands.rs
Expand Up @@ -7,7 +7,6 @@ use nu_protocol::{
record, span, Category, IntoInterruptiblePipelineData, IntoPipelineData, PipelineData,
ShellError, Signature, Span, Spanned, SyntaxShape, Type, Value,
};
use std::borrow::Borrow;

#[derive(Clone)]
pub struct HelpCommands;
Expand Down Expand Up @@ -127,7 +126,7 @@ fn build_help_commands(engine_state: &EngineState, span: Span) -> Vec<Value> {

for (_, decl_id) in commands {
let decl = engine_state.get_decl(decl_id);
let sig = decl.signature().update_from_command(decl.borrow());
let sig = decl.signature().update_from_command(decl);

let key = sig.name;
let usage = sig.usage;
Expand Down
11 changes: 5 additions & 6 deletions crates/nu-command/src/network/http/client.rs
Expand Up @@ -421,7 +421,6 @@ pub struct RequestFlags {
pub full: bool,
}

#[allow(clippy::needless_return)]
fn transform_response_using_content_type(
engine_state: &EngineState,
stack: &mut Stack,
Expand Down Expand Up @@ -464,20 +463,20 @@ fn transform_response_using_content_type(

let output = response_to_buffer(resp, engine_state, span);
if flags.raw {
return Ok(output);
Ok(output)
} else if let Some(ext) = ext {
return match engine_state.find_decl(format!("from {ext}").as_bytes(), &[]) {
match engine_state.find_decl(format!("from {ext}").as_bytes(), &[]) {
Some(converter_id) => engine_state.get_decl(converter_id).run(
engine_state,
stack,
&Call::new(span),
output,
),
None => Ok(output),
};
}
} else {
return Ok(output);
};
Ok(output)
}
}

pub fn check_response_redirection(
Expand Down
1 change: 0 additions & 1 deletion crates/nu-command/src/strings/detect_columns.rs
Expand Up @@ -109,7 +109,6 @@ fn detect_columns(
let config = engine_state.get_config();
let input = input.collect_string("", config)?;

#[allow(clippy::needless_collect)]
let input: Vec<_> = input
.lines()
.skip(num_rows_to_skip.unwrap_or_default())
Expand Down
1 change: 0 additions & 1 deletion crates/nu-command/src/viewers/table.rs
Expand Up @@ -989,7 +989,6 @@ enum TableView {
},
}

#[allow(clippy::manual_filter)]
fn maybe_strip_color(output: String, config: &Config) -> String {
// the terminal is for when people do ls from vim, there should be no coloring there
if !config.use_ansi_coloring || !std::io::stdout().is_terminal() {
Expand Down
1 change: 0 additions & 1 deletion crates/nu-command/tests/commands/table.rs
Expand Up @@ -2346,7 +2346,6 @@ fn join_lines(lines: impl IntoIterator<Item = impl AsRef<str>>) -> String {
}

// util function to easier copy && paste
#[allow(dead_code)]
fn _print_lines(s: &str, w: usize) {
eprintln!("{:#?}", _split_str_by_width(s, w));
}
Expand Down
2 changes: 1 addition & 1 deletion crates/nu-command/tests/commands/where_.rs
@@ -1,5 +1,5 @@
use nu_test_support::nu;
#[allow(unused_imports)]
#[cfg(feature = "sqlite")]
use nu_test_support::pipeline;

#[test]
Expand Down
3 changes: 1 addition & 2 deletions crates/nu-command/tests/format_conversions/csv.rs
Expand Up @@ -183,7 +183,6 @@ fn from_csv_text_with_tab_separator_to_table() {
}

#[test]
#[allow(clippy::needless_raw_string_hashes)]
fn from_csv_text_with_comments_to_table() {
Playground::setup("filter_from_csv_test_5", |dirs, sandbox| {
sandbox.with_files(vec![FileWithContentToBeTrimmed(
Expand Down Expand Up @@ -377,7 +376,7 @@ fn from_csv_text_with_wrong_type_separator() {
fn table_with_record_error() {
let actual = nu!(pipeline(
r#"
[[a b]; [1 2] [3 {a: 1 b: 2}]]
[[a b]; [1 2] [3 {a: 1 b: 2}]]
| to csv
"#
));
Expand Down
1 change: 0 additions & 1 deletion crates/nu-command/tests/format_conversions/tsv.rs
Expand Up @@ -106,7 +106,6 @@ fn from_tsv_text_to_table() {
}

#[test]
#[allow(clippy::needless_raw_string_hashes)]
fn from_tsv_text_with_comments_to_table() {
Playground::setup("filter_from_tsv_test_2", |dirs, sandbox| {
sandbox.with_files(vec![FileWithContentToBeTrimmed(
Expand Down
4 changes: 0 additions & 4 deletions crates/nu-engine/src/env.rs
Expand Up @@ -19,11 +19,9 @@ const ENV_PATH_NAME: &str = "PATH";

const ENV_CONVERSIONS: &str = "ENV_CONVERSIONS";

#[allow(dead_code)]
enum ConversionResult {
Ok(Value),
ConversionError(ShellError), // Failure during the conversion itself
GeneralError(ShellError), // Other error not directly connected to running the conversion
CellPathError, // Error looking up the ENV_VAR.to_/from_string fields in $env.ENV_CONVERSIONS
}

Expand All @@ -46,7 +44,6 @@ pub fn convert_env_values(engine_state: &mut EngineState, stack: &Stack) -> Opti
let _ = new_scope.insert(name.to_string(), v);
}
ConversionResult::ConversionError(e) => error = error.or(Some(e)),
ConversionResult::GeneralError(_) => continue,
ConversionResult::CellPathError => {
let _ = new_scope.insert(name.to_string(), val.clone());
}
Expand Down Expand Up @@ -101,7 +98,6 @@ pub fn env_to_string(
match get_converted_value(engine_state, stack, env_name, value, "to_string") {
ConversionResult::Ok(v) => Ok(v.coerce_into_string()?),
ConversionResult::ConversionError(e) => Err(e),
ConversionResult::GeneralError(e) => Err(e),
ConversionResult::CellPathError => match value.coerce_string() {
Ok(s) => Ok(s),
Err(_) => {
Expand Down
1 change: 0 additions & 1 deletion crates/nu-explore/src/pager/mod.rs
Expand Up @@ -148,7 +148,6 @@ impl<'a> Pager<'a> {
}

#[derive(Debug, Clone)]
#[allow(dead_code)]
pub enum Transition {
Ok,
Exit,
Expand Down
85 changes: 44 additions & 41 deletions crates/nu-glob/src/lib.rs
Expand Up @@ -73,6 +73,7 @@ extern crate doc_comment;
doctest!("../README.md");

use std::cmp;
use std::cmp::Ordering;
use std::error::Error;
use std::fmt;
use std::fs;
Expand Down Expand Up @@ -346,7 +347,6 @@ impl Error for GlobError {
self.error.description()
}

#[allow(unknown_lints, bare_trait_objects)]
fn cause(&self) -> Option<&dyn Error> {
Some(&self.error)
}
Expand Down Expand Up @@ -505,7 +505,6 @@ impl Iterator for Paths {

/// A pattern parsing error.
#[derive(Debug)]
#[allow(missing_copy_implementations)]
pub struct PatternError {
/// The approximate character index of where the error occurred.
pub pos: usize,
Expand Down Expand Up @@ -630,53 +629,58 @@ impl Pattern {

let count = i - old;

#[allow(clippy::comparison_chain)]
if count > 2 {
return Err(PatternError {
pos: old + 2,
msg: ERROR_WILDCARDS,
});
} else if count == 2 {
// ** can only be an entire path component
// i.e. a/**/b is valid, but a**/b or a/**b is not
// invalid matches are treated literally
let is_valid = if i == 2 || path::is_separator(chars[i - count - 1]) {
// it ends in a '/'
if i < chars.len() && path::is_separator(chars[i]) {
i += 1;
true
// or the pattern ends here
// this enables the existing globbing mechanism
} else if i == chars.len() {
true
// `**` ends in non-separator
match count.cmp(&2) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not quite sure if this monster gets much more readable. maybe worth pullilng the Less branch up?

Ordering::Greater => {
return Err(PatternError {
pos: old + 2,
msg: ERROR_WILDCARDS,
});
}
Ordering::Equal => {
// ** can only be an entire path component
// i.e. a/**/b is valid, but a**/b or a/**b is not
// invalid matches are treated literally
let is_valid = if i == 2 || path::is_separator(chars[i - count - 1]) {
// it ends in a '/'
if i < chars.len() && path::is_separator(chars[i]) {
i += 1;
true
// or the pattern ends here
// this enables the existing globbing mechanism
} else if i == chars.len() {
true
// `**` ends in non-separator
} else {
return Err(PatternError {
pos: i,
msg: ERROR_RECURSIVE_WILDCARDS,
});
}
// `**` begins with non-separator
} else {
return Err(PatternError {
pos: i,
pos: old - 1,
msg: ERROR_RECURSIVE_WILDCARDS,
});
}
// `**` begins with non-separator
} else {
return Err(PatternError {
pos: old - 1,
msg: ERROR_RECURSIVE_WILDCARDS,
});
};
};

if is_valid {
// collapse consecutive AnyRecursiveSequence to a
// single one
if is_valid {
// collapse consecutive AnyRecursiveSequence to a
// single one

let tokens_len = tokens.len();
let tokens_len = tokens.len();

if !(tokens_len > 1 && tokens[tokens_len - 1] == AnyRecursiveSequence) {
is_recursive = true;
tokens.push(AnyRecursiveSequence);
if !(tokens_len > 1
&& tokens[tokens_len - 1] == AnyRecursiveSequence)
{
is_recursive = true;
tokens.push(AnyRecursiveSequence);
}
}
}
} else {
tokens.push(AnySequence);
Ordering::Less => {
tokens.push(AnySequence);
}
}
}
'[' => {
Expand Down Expand Up @@ -1051,7 +1055,6 @@ fn chars_eq(a: char, b: char, case_sensitive: bool) -> bool {
}

/// Configuration options to modify the behaviour of `Pattern::matches_with(..)`.
#[allow(missing_copy_implementations)]
#[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub struct MatchOptions {
/// Whether or not patterns should be matched in a case-sensitive manner.
Expand Down