From e35d477a8cf28a9cabed9496400fab49247dd3a3 Mon Sep 17 00:00:00 2001 From: Sylvestre Ledru Date: Sat, 6 May 2023 14:50:40 +0200 Subject: [PATCH 1/3] change the cognitive_complexity to a lower value --- .clippy.toml | 1 + 1 file changed, 1 insertion(+) diff --git a/.clippy.toml b/.clippy.toml index 22fd4be73..bee70857b 100644 --- a/.clippy.toml +++ b/.clippy.toml @@ -1 +1,2 @@ msrv = "1.64.0" +cognitive-complexity-threshold = 10 From f8d7bebed30c777dcb0e8fb157b0184f11af871e Mon Sep 17 00:00:00 2001 From: Sylvestre Ledru Date: Sat, 6 May 2023 14:50:55 +0200 Subject: [PATCH 2/3] ignore some cognitive_complexity for now --- src/bin/coreutils.rs | 1 + src/uu/cat/src/cat.rs | 1 + src/uu/cp/src/cp.rs | 2 ++ src/uu/csplit/src/csplit.rs | 1 + src/uu/date/src/date.rs | 1 + src/uu/dd/src/dd.rs | 1 + src/uu/dd/src/parseargs.rs | 2 ++ src/uu/dircolors/src/dircolors.rs | 1 + src/uu/du/src/du.rs | 2 ++ src/uu/env/src/env.rs | 1 + src/uu/expand/src/expand.rs | 1 + src/uu/fmt/src/fmt.rs | 1 + src/uu/fmt/src/linebreak.rs | 1 + src/uu/fmt/src/parasplit.rs | 1 + src/uu/fold/src/fold.rs | 1 + src/uu/hashsum/src/hashsum.rs | 1 + src/uu/head/src/head.rs | 1 + src/uu/head/src/parse.rs | 1 + src/uu/join/src/join.rs | 1 + src/uu/ln/src/ln.rs | 2 ++ src/uu/ls/src/ls.rs | 5 +++++ src/uu/mv/src/mv.rs | 1 + src/uu/nl/src/helper.rs | 1 + src/uu/nl/src/nl.rs | 1 + src/uu/numfmt/src/options.rs | 1 + src/uu/od/src/parse_formats.rs | 1 + src/uu/paste/src/paste.rs | 1 + src/uu/pr/src/pr.rs | 2 ++ src/uu/ptx/src/ptx.rs | 1 + src/uu/rm/src/rm.rs | 2 ++ src/uu/shred/src/shred.rs | 1 + src/uu/sort/src/numeric_str_cmp.rs | 1 + src/uu/sort/src/sort.rs | 2 ++ src/uu/tac/src/tac.rs | 1 + src/uu/tail/src/follow/watch.rs | 2 ++ src/uu/touch/src/touch.rs | 1 + src/uu/unexpand/src/unexpand.rs | 1 + src/uu/wc/src/utf8/read.rs | 1 + src/uu/wc/src/wc.rs | 1 + src/uucore/src/lib/features/fs.rs | 2 ++ src/uucore/src/lib/features/perms.rs | 3 +++ .../features/tokenize/num_format/formatters/float_common.rs | 2 ++ .../src/lib/features/tokenize/num_format/formatters/intf.rs | 1 + .../src/lib/features/tokenize/num_format/num_format.rs | 1 + src/uucore/src/lib/features/tokenize/sub.rs | 2 ++ src/uucore/src/lib/features/tokenize/unescaped_text.rs | 1 + 46 files changed, 63 insertions(+) diff --git a/src/bin/coreutils.rs b/src/bin/coreutils.rs index cc18d3ee2..8440689c6 100644 --- a/src/bin/coreutils.rs +++ b/src/bin/coreutils.rs @@ -47,6 +47,7 @@ fn name(binary_path: &Path) -> Option<&str> { binary_path.file_stem()?.to_str() } +#[allow(clippy::cognitive_complexity)] fn main() { uucore::panic::mute_sigpipe_panic(); diff --git a/src/uu/cat/src/cat.rs b/src/uu/cat/src/cat.rs index e90bdd116..4a5e7e0ad 100644 --- a/src/uu/cat/src/cat.rs +++ b/src/uu/cat/src/cat.rs @@ -456,6 +456,7 @@ fn write_fast(handle: &mut InputHandle) -> CatResult<()> { /// Outputs file contents to stdout in a line-by-line fashion, /// propagating any errors that might occur. +#[allow(clippy::cognitive_complexity)] fn write_lines( handle: &mut InputHandle, options: &OutputOptions, diff --git a/src/uu/cp/src/cp.rs b/src/uu/cp/src/cp.rs index 270335b97..3e69e5791 100644 --- a/src/uu/cp/src/cp.rs +++ b/src/uu/cp/src/cp.rs @@ -727,6 +727,7 @@ impl Attributes { } impl Options { + #[allow(clippy::cognitive_complexity)] fn from_matches(matches: &ArgMatches) -> CopyResult { let not_implemented_opts = vec![ #[cfg(not(any(windows, unix)))] @@ -1467,6 +1468,7 @@ fn aligned_ancestors<'a>(source: &'a Path, dest: &'a Path) -> Vec<(&'a Path, &'a /// /// The original permissions of `source` will be copied to `dest` /// after a successful copy. +#[allow(clippy::cognitive_complexity)] fn copy_file( progress_bar: &Option, source: &Path, diff --git a/src/uu/csplit/src/csplit.rs b/src/uu/csplit/src/csplit.rs index 6e1eaf1a3..1a94b4156 100644 --- a/src/uu/csplit/src/csplit.rs +++ b/src/uu/csplit/src/csplit.rs @@ -356,6 +356,7 @@ impl<'a> SplitWriter<'a> { /// - if no line matched, an [`CsplitError::MatchNotFound`]. /// - if there are not enough lines to accommodate the offset, an /// [`CsplitError::LineOutOfRange`]. + #[allow(clippy::cognitive_complexity)] fn do_to_match( &mut self, pattern_as_str: &str, diff --git a/src/uu/date/src/date.rs b/src/uu/date/src/date.rs index 8b4338620..a94ffd65f 100644 --- a/src/uu/date/src/date.rs +++ b/src/uu/date/src/date.rs @@ -141,6 +141,7 @@ impl<'a> From<&'a str> for Rfc3339Format { } #[uucore::main] +#[allow(clippy::cognitive_complexity)] pub fn uumain(args: impl uucore::Args) -> UResult<()> { let matches = uu_app().try_get_matches_from(args)?; diff --git a/src/uu/dd/src/dd.rs b/src/uu/dd/src/dd.rs index 6f75f4707..836456635 100644 --- a/src/uu/dd/src/dd.rs +++ b/src/uu/dd/src/dd.rs @@ -752,6 +752,7 @@ fn finalize( } #[cfg(any(target_os = "linux", target_os = "android"))] +#[allow(clippy::cognitive_complexity)] fn make_linux_oflags(oflags: &OFlags) -> Option { let mut flag = 0; diff --git a/src/uu/dd/src/parseargs.rs b/src/uu/dd/src/parseargs.rs index 96f6ebfaa..b9a3baf09 100644 --- a/src/uu/dd/src/parseargs.rs +++ b/src/uu/dd/src/parseargs.rs @@ -293,6 +293,7 @@ impl Parser { } } + #[allow(clippy::cognitive_complexity)] fn parse_input_flags(&mut self, val: &str) -> Result<(), ParseError> { let mut i = &mut self.iflag; for f in val.split(',') { @@ -324,6 +325,7 @@ impl Parser { Ok(()) } + #[allow(clippy::cognitive_complexity)] fn parse_output_flags(&mut self, val: &str) -> Result<(), ParseError> { let mut o = &mut self.oflag; for f in val.split(',') { diff --git a/src/uu/dircolors/src/dircolors.rs b/src/uu/dircolors/src/dircolors.rs index 6b2bd9a98..fe78924f4 100644 --- a/src/uu/dircolors/src/dircolors.rs +++ b/src/uu/dircolors/src/dircolors.rs @@ -284,6 +284,7 @@ enum ParseState { use std::collections::HashMap; use uucore::{format_usage, parse_glob}; +#[allow(clippy::cognitive_complexity)] fn parse(lines: T, fmt: &OutputFmt, fp: &str) -> Result where T: IntoIterator, diff --git a/src/uu/du/src/du.rs b/src/uu/du/src/du.rs index f6a631d20..3325ca1f5 100644 --- a/src/uu/du/src/du.rs +++ b/src/uu/du/src/du.rs @@ -289,6 +289,7 @@ fn choose_size(matches: &ArgMatches, stat: &Stat) -> u64 { // this takes `my_stat` to avoid having to stat files multiple times. // XXX: this should use the impl Trait return type when it is stabilized +#[allow(clippy::cognitive_complexity)] fn du( mut my_stat: Stat, options: &Options, @@ -521,6 +522,7 @@ fn build_exclude_patterns(matches: &ArgMatches) -> UResult> { } #[uucore::main] +#[allow(clippy::cognitive_complexity)] pub fn uumain(args: impl uucore::Args) -> UResult<()> { let args = args.collect_ignore(); diff --git a/src/uu/env/src/env.rs b/src/uu/env/src/env.rs index 0ef191b8d..b293bc9bf 100644 --- a/src/uu/env/src/env.rs +++ b/src/uu/env/src/env.rs @@ -175,6 +175,7 @@ pub fn uu_app() -> Command { .arg(Arg::new("vars").action(ArgAction::Append)) } +#[allow(clippy::cognitive_complexity)] fn run_env(args: impl uucore::Args) -> UResult<()> { let app = uu_app(); let matches = app.try_get_matches_from(args).with_exit_code(125)?; diff --git a/src/uu/expand/src/expand.rs b/src/uu/expand/src/expand.rs index 40928aeaf..98b292771 100644 --- a/src/uu/expand/src/expand.rs +++ b/src/uu/expand/src/expand.rs @@ -373,6 +373,7 @@ enum CharType { Other, } +#[allow(clippy::cognitive_complexity)] fn expand(options: &Options) -> std::io::Result<()> { use self::CharType::*; diff --git a/src/uu/fmt/src/fmt.rs b/src/uu/fmt/src/fmt.rs index 0fd863730..d144bdd8a 100644 --- a/src/uu/fmt/src/fmt.rs +++ b/src/uu/fmt/src/fmt.rs @@ -69,6 +69,7 @@ pub struct FmtOptions { /// # Returns /// /// A tuple containing a vector of file names and a `FmtOptions` struct. +#[allow(clippy::cognitive_complexity)] fn parse_arguments(args: impl uucore::Args) -> UResult<(Vec, FmtOptions)> { let matches = uu_app().try_get_matches_from(args)?; diff --git a/src/uu/fmt/src/linebreak.rs b/src/uu/fmt/src/linebreak.rs index 75cd633bb..e86623c88 100644 --- a/src/uu/fmt/src/linebreak.rs +++ b/src/uu/fmt/src/linebreak.rs @@ -223,6 +223,7 @@ struct LineBreak<'a> { fresh: bool, } +#[allow(clippy::cognitive_complexity)] fn find_kp_breakpoints<'a, T: Iterator>>( iter: T, args: &BreakArgs<'a>, diff --git a/src/uu/fmt/src/parasplit.rs b/src/uu/fmt/src/parasplit.rs index d2e3d292d..a2d70b088 100644 --- a/src/uu/fmt/src/parasplit.rs +++ b/src/uu/fmt/src/parasplit.rs @@ -275,6 +275,7 @@ impl<'a> ParagraphStream<'a> { impl<'a> Iterator for ParagraphStream<'a> { type Item = Result; + #[allow(clippy::cognitive_complexity)] fn next(&mut self) -> Option> { // return a NoFormatLine in an Err; it should immediately be output let noformat = match self.lines.peek() { diff --git a/src/uu/fold/src/fold.rs b/src/uu/fold/src/fold.rs index 01eba0b82..d53573d82 100644 --- a/src/uu/fold/src/fold.rs +++ b/src/uu/fold/src/fold.rs @@ -207,6 +207,7 @@ fn fold_file_bytewise(mut file: BufReader, spaces: bool, width: usiz /// /// If `spaces` is `true`, attempt to break lines at whitespace boundaries. #[allow(unused_assignments)] +#[allow(clippy::cognitive_complexity)] fn fold_file(mut file: BufReader, spaces: bool, width: usize) -> UResult<()> { let mut line = String::new(); let mut output = String::new(); diff --git a/src/uu/hashsum/src/hashsum.rs b/src/uu/hashsum/src/hashsum.rs index 44e0cbcd8..af05ddbd9 100644 --- a/src/uu/hashsum/src/hashsum.rs +++ b/src/uu/hashsum/src/hashsum.rs @@ -224,6 +224,7 @@ fn detect_algo( /// # Panics /// /// Panics if multiple hash algorithms are specified or if a required flag is missing. +#[allow(clippy::cognitive_complexity)] fn create_algorithm_from_flags(matches: &ArgMatches) -> (&'static str, Box, usize) { let mut alg: Option> = None; let mut name: &'static str = ""; diff --git a/src/uu/head/src/head.rs b/src/uu/head/src/head.rs index b9ac5024b..2ccf20904 100644 --- a/src/uu/head/src/head.rs +++ b/src/uu/head/src/head.rs @@ -432,6 +432,7 @@ fn head_file(input: &mut std::fs::File, options: &HeadOptions) -> std::io::Resul } } +#[allow(clippy::cognitive_complexity)] fn uu_head(options: &HeadOptions) -> UResult<()> { let mut first = true; for file in &options.files { diff --git a/src/uu/head/src/parse.rs b/src/uu/head/src/parse.rs index cbfc97152..b24b6591e 100644 --- a/src/uu/head/src/parse.rs +++ b/src/uu/head/src/parse.rs @@ -13,6 +13,7 @@ pub enum ParseError { } /// Parses obsolete syntax /// head -NUM\[kmzv\] // spell-checker:disable-line +#[allow(clippy::cognitive_complexity)] pub fn parse_obsolete(src: &str) -> Option, ParseError>> { let mut chars = src.char_indices(); if let Some((_, '-')) = chars.next() { diff --git a/src/uu/join/src/join.rs b/src/uu/join/src/join.rs index baf70c259..de1a9181b 100644 --- a/src/uu/join/src/join.rs +++ b/src/uu/join/src/join.rs @@ -600,6 +600,7 @@ impl<'a> State<'a> { } #[uucore::main] +#[allow(clippy::cognitive_complexity)] pub fn uumain(args: impl uucore::Args) -> UResult<()> { let matches = uu_app().try_get_matches_from(args)?; diff --git a/src/uu/ln/src/ln.rs b/src/uu/ln/src/ln.rs index d98f3afb1..c2bf25c5c 100644 --- a/src/uu/ln/src/ln.rs +++ b/src/uu/ln/src/ln.rs @@ -292,6 +292,7 @@ fn exec(files: &[PathBuf], settings: &Settings) -> UResult<()> { link(&files[0], &files[1], settings) } +#[allow(clippy::cognitive_complexity)] fn link_files_in_dir(files: &[PathBuf], target_dir: &Path, settings: &Settings) -> UResult<()> { if !target_dir.is_dir() { return Err(LnError::TargetIsDirectory(target_dir.to_owned()).into()); @@ -364,6 +365,7 @@ fn relative_path<'a>(src: &'a Path, dst: &Path) -> Cow<'a, Path> { src.into() } +#[allow(clippy::cognitive_complexity)] fn link(src: &Path, dst: &Path, settings: &Settings) -> UResult<()> { let mut backup_path = None; let source: Cow<'_, Path> = if settings.relative { diff --git a/src/uu/ls/src/ls.rs b/src/uu/ls/src/ls.rs index 52ac489ef..db8024c2e 100644 --- a/src/uu/ls/src/ls.rs +++ b/src/uu/ls/src/ls.rs @@ -650,6 +650,7 @@ fn extract_indicator_style(options: &clap::ArgMatches) -> IndicatorStyle { } impl Config { + #[allow(clippy::cognitive_complexity)] pub fn from(options: &clap::ArgMatches) -> UResult { let context = options.get_flag(options::CONTEXT); let (mut format, opt) = extract_format(options); @@ -1997,6 +1998,7 @@ fn should_display(entry: &DirEntry, config: &Config) -> bool { .any(|p| p.matches_with(&file_name, options)) } +#[allow(clippy::cognitive_complexity)] fn enter_directory( path_data: &PathData, read_dir: ReadDir, @@ -2187,6 +2189,7 @@ fn display_additional_leading_info( Ok(result) } +#[allow(clippy::cognitive_complexity)] fn display_items(items: &[PathData], config: &Config, out: &mut BufWriter) -> UResult<()> { // `-Z`, `--context`: // Display the SELinux security context or '?' if none is found. When used with the `-l` @@ -2376,6 +2379,7 @@ fn display_grid( /// ``` /// that decide the maximum possible character count of each field. #[allow(clippy::write_literal)] +#[allow(clippy::cognitive_complexity)] fn display_item_long( item: &PathData, padding: &PaddingCollection, @@ -2806,6 +2810,7 @@ fn classify_file(path: &PathData, out: &mut BufWriter) -> Option { /// Note that non-unicode sequences in symlink targets are dealt with using /// [`std::path::Path::to_string_lossy`]. #[allow(unused_variables)] +#[allow(clippy::cognitive_complexity)] fn display_file_name( path: &PathData, config: &Config, diff --git a/src/uu/mv/src/mv.rs b/src/uu/mv/src/mv.rs index 9632ddabf..fdf8d358b 100644 --- a/src/uu/mv/src/mv.rs +++ b/src/uu/mv/src/mv.rs @@ -321,6 +321,7 @@ fn exec(files: &[OsString], b: &Behavior) -> UResult<()> { } } +#[allow(clippy::cognitive_complexity)] fn move_files_into_dir(files: &[PathBuf], target_dir: &Path, b: &Behavior) -> UResult<()> { if !target_dir.is_dir() { return Err(MvError::NotADirectory(target_dir.quote().to_string()).into()); diff --git a/src/uu/nl/src/helper.rs b/src/uu/nl/src/helper.rs index fa59d329a..a62936d75 100644 --- a/src/uu/nl/src/helper.rs +++ b/src/uu/nl/src/helper.rs @@ -25,6 +25,7 @@ fn parse_style(chars: &[char]) -> Result { // parse_options loads the options into the settings, returning an array of // error messages. +#[allow(clippy::cognitive_complexity)] pub fn parse_options(settings: &mut crate::Settings, opts: &clap::ArgMatches) -> Vec { // This vector holds error messages encountered. let mut errs: Vec = vec![]; diff --git a/src/uu/nl/src/nl.rs b/src/uu/nl/src/nl.rs index eb33eb3b8..44fdec8c7 100644 --- a/src/uu/nl/src/nl.rs +++ b/src/uu/nl/src/nl.rs @@ -236,6 +236,7 @@ pub fn uu_app() -> Command { } // nl implements the main functionality for an individual buffer. +#[allow(clippy::cognitive_complexity)] fn nl(reader: &mut BufReader, settings: &Settings) -> UResult<()> { let regexp: regex::Regex = regex::Regex::new(r".?").unwrap(); let mut line_no = settings.starting_line_number; diff --git a/src/uu/numfmt/src/options.rs b/src/uu/numfmt/src/options.rs index 131ad378b..b70cf87e4 100644 --- a/src/uu/numfmt/src/options.rs +++ b/src/uu/numfmt/src/options.rs @@ -95,6 +95,7 @@ impl FromStr for FormatOptions { // An optional zero (%010f) will zero pad the number. // An optional negative value (%-10f) will left align. // An optional precision (%.1f) determines the precision of the number. + #[allow(clippy::cognitive_complexity)] fn from_str(s: &str) -> Result { let mut iter = s.chars().peekable(); let mut options = Self::default(); diff --git a/src/uu/od/src/parse_formats.rs b/src/uu/od/src/parse_formats.rs index 9614ed9c0..c414abebe 100644 --- a/src/uu/od/src/parse_formats.rs +++ b/src/uu/od/src/parse_formats.rs @@ -96,6 +96,7 @@ fn od_argument_with_option(ch: char) -> bool { /// arguments with parameters like -w16 can only appear at the end: -fvoxw16 /// parameters of -t/--format specify 1 or more formats. /// if -- appears on the command line, parsing should stop. +#[allow(clippy::cognitive_complexity)] pub fn parse_format_flags(args: &[String]) -> Result, String> { let mut formats = Vec::new(); diff --git a/src/uu/paste/src/paste.rs b/src/uu/paste/src/paste.rs index c8d807635..6e52727f7 100644 --- a/src/uu/paste/src/paste.rs +++ b/src/uu/paste/src/paste.rs @@ -111,6 +111,7 @@ pub fn uu_app() -> Command { ) } +#[allow(clippy::cognitive_complexity)] fn paste( filenames: Vec, serial: bool, diff --git a/src/uu/pr/src/pr.rs b/src/uu/pr/src/pr.rs index 63df207da..b3be8a755 100644 --- a/src/uu/pr/src/pr.rs +++ b/src/uu/pr/src/pr.rs @@ -488,6 +488,7 @@ fn parse_usize(matches: &ArgMatches, opt: &str) -> Option .map(from_parse_error_to_pr_error) } +#[allow(clippy::cognitive_complexity)] fn build_options( matches: &ArgMatches, paths: &[&str], @@ -1021,6 +1022,7 @@ fn print_page( Ok(lines_written) } +#[allow(clippy::cognitive_complexity)] fn write_columns( lines: &[FileLine], options: &OutputOptions, diff --git a/src/uu/ptx/src/ptx.rs b/src/uu/ptx/src/ptx.rs index 4d411ed31..ecfd67ce8 100644 --- a/src/uu/ptx/src/ptx.rs +++ b/src/uu/ptx/src/ptx.rs @@ -107,6 +107,7 @@ struct WordFilter { } impl WordFilter { + #[allow(clippy::cognitive_complexity)] fn new(matches: &clap::ArgMatches, config: &Config) -> UResult { let (o, oset): (bool, HashSet) = if matches.contains_id(options::ONLY_FILE) { let words = diff --git a/src/uu/rm/src/rm.rs b/src/uu/rm/src/rm.rs index 02aa96e24..7937faf74 100644 --- a/src/uu/rm/src/rm.rs +++ b/src/uu/rm/src/rm.rs @@ -274,6 +274,7 @@ fn remove(files: &[String], options: &Options) -> bool { had_err } +#[allow(clippy::cognitive_complexity)] fn handle_dir(path: &Path, options: &Options) -> bool { let mut had_err = false; @@ -422,6 +423,7 @@ fn remove_file(path: &Path, options: &Options) -> bool { false } +#[allow(clippy::cognitive_complexity)] fn prompt_file(path: &Path, options: &Options, is_dir: bool) -> bool { // If interactive is Never we never want to send prompts if options.interactive == InteractiveMode::Never { diff --git a/src/uu/shred/src/shred.rs b/src/uu/shred/src/shred.rs index 1c7d6ab13..89f857b19 100644 --- a/src/uu/shred/src/shred.rs +++ b/src/uu/shred/src/shred.rs @@ -361,6 +361,7 @@ fn pass_name(pass_type: &PassType) -> String { } #[allow(clippy::too_many_arguments)] +#[allow(clippy::cognitive_complexity)] fn wipe_file( path_str: &str, n_passes: usize, diff --git a/src/uu/sort/src/numeric_str_cmp.rs b/src/uu/sort/src/numeric_str_cmp.rs index 21d733877..05f81c897 100644 --- a/src/uu/sort/src/numeric_str_cmp.rs +++ b/src/uu/sort/src/numeric_str_cmp.rs @@ -52,6 +52,7 @@ impl NumInfo { /// an empty range (idx..idx) is returned so that idx is the char after the last zero. /// If the input is not a number (which has to be treated as zero), the returned empty range /// will be 0..0. + #[allow(clippy::cognitive_complexity)] pub fn parse(num: &str, parse_settings: &NumInfoParseSettings) -> (Self, Range) { let mut exponent = -1; let mut had_decimal_pt = false; diff --git a/src/uu/sort/src/sort.rs b/src/uu/sort/src/sort.rs index 1744148f2..80c2275e9 100644 --- a/src/uu/sort/src/sort.rs +++ b/src/uu/sort/src/sort.rs @@ -1033,6 +1033,7 @@ fn make_sort_mode_arg(mode: &'static str, short: char, help: &'static str) -> Ar } #[uucore::main] +#[allow(clippy::cognitive_complexity)] pub fn uumain(args: impl uucore::Args) -> UResult<()> { let args = args.collect_ignore(); let mut settings = GlobalSettings::default(); @@ -1654,6 +1655,7 @@ fn compare_by<'a>( // In contrast to numeric compare, GNU general numeric/FP sort *should* recognize positive signs and // scientific notation, so we strip those lines only after the end of the following numeric string. // For example, 5e10KFD would be 5e10 or 5x10^10 and +10000HFKJFK would become 10000. +#[allow(clippy::cognitive_complexity)] fn get_leading_gen(input: &str) -> Range { let trimmed = input.trim_start(); let leading_whitespace_len = input.len() - trimmed.len(); diff --git a/src/uu/tac/src/tac.rs b/src/uu/tac/src/tac.rs index aef9932a2..96bb82f1e 100644 --- a/src/uu/tac/src/tac.rs +++ b/src/uu/tac/src/tac.rs @@ -222,6 +222,7 @@ fn buffer_tac(data: &[u8], before: bool, separator: &str) -> std::io::Result<()> Ok(()) } +#[allow(clippy::cognitive_complexity)] fn tac(filenames: &[&str], before: bool, regex: bool, separator: &str) -> UResult<()> { // Compile the regular expression pattern if it is provided. let maybe_pattern = if regex { diff --git a/src/uu/tail/src/follow/watch.rs b/src/uu/tail/src/follow/watch.rs index 2c3cf10b8..67ad8f0c2 100644 --- a/src/uu/tail/src/follow/watch.rs +++ b/src/uu/tail/src/follow/watch.rs @@ -303,6 +303,7 @@ impl Observer { Ok(()) } + #[allow(clippy::cognitive_complexity)] fn handle_event( &mut self, event: ¬ify::Event, @@ -471,6 +472,7 @@ impl Observer { } } +#[allow(clippy::cognitive_complexity)] pub fn follow(mut observer: Observer, settings: &Settings) -> UResult<()> { if observer.files.no_files_remaining(settings) && !observer.files.only_stdin_remaining() { return Err(USimpleError::new(1, text::NO_FILES_REMAINING.to_string())); diff --git a/src/uu/touch/src/touch.rs b/src/uu/touch/src/touch.rs index 00d23da75..55663fdab 100644 --- a/src/uu/touch/src/touch.rs +++ b/src/uu/touch/src/touch.rs @@ -65,6 +65,7 @@ fn dt_to_filename(tm: time::PrimitiveDateTime) -> FileTime { } #[uucore::main] +#[allow(clippy::cognitive_complexity)] pub fn uumain(args: impl uucore::Args) -> UResult<()> { let matches = uu_app().try_get_matches_from(args)?; diff --git a/src/uu/unexpand/src/unexpand.rs b/src/uu/unexpand/src/unexpand.rs index da60aa1c2..dd4471e2d 100644 --- a/src/uu/unexpand/src/unexpand.rs +++ b/src/uu/unexpand/src/unexpand.rs @@ -318,6 +318,7 @@ fn next_char_info(uflag: bool, buf: &[u8], byte: usize) -> (CharType, usize, usi (ctype, cwidth, nbytes) } +#[allow(clippy::cognitive_complexity)] fn unexpand(options: &Options) -> std::io::Result<()> { let mut output = BufWriter::new(stdout()); let ts = &options.tabstops[..]; diff --git a/src/uu/wc/src/utf8/read.rs b/src/uu/wc/src/utf8/read.rs index eb4684f7f..1b5bbbe7f 100644 --- a/src/uu/wc/src/utf8/read.rs +++ b/src/uu/wc/src/utf8/read.rs @@ -60,6 +60,7 @@ impl BufReadDecoder { /// This is similar to `Iterator::next`, /// except that decoded chunks borrow the decoder (~iterator) /// so they need to be handled or copied before the next chunk can start decoding. + #[allow(clippy::cognitive_complexity)] pub fn next_strict(&mut self) -> Option> { enum BytesSource { BufRead(usize), diff --git a/src/uu/wc/src/wc.rs b/src/uu/wc/src/wc.rs index 949f05d65..9d7a23d1f 100644 --- a/src/uu/wc/src/wc.rs +++ b/src/uu/wc/src/wc.rs @@ -450,6 +450,7 @@ fn word_count_from_reader( } } +#[allow(clippy::cognitive_complexity)] fn word_count_from_reader_specialized< T: WordCountable, const SHOW_CHARS: bool, diff --git a/src/uucore/src/lib/features/fs.rs b/src/uucore/src/lib/features/fs.rs index 6dc371a10..4de07f502 100644 --- a/src/uucore/src/lib/features/fs.rs +++ b/src/uucore/src/lib/features/fs.rs @@ -326,6 +326,7 @@ impl<'a> From> for OwningComponent { /// * [`ResolveMode::Logical`] makes this function resolve '..' components /// before symlinks /// +#[allow(clippy::cognitive_complexity)] pub fn canonicalize>( original: P, miss_mode: MissingHandling, @@ -457,6 +458,7 @@ pub fn display_permissions(metadata: &fs::Metadata, display_file_type: bool) -> // The logic below is more readable written this way. #[allow(clippy::if_not_else)] +#[allow(clippy::cognitive_complexity)] #[cfg(unix)] /// Display the permissions of a file on a unix like system pub fn display_permissions_unix(mode: mode_t, display_file_type: bool) -> String { diff --git a/src/uucore/src/lib/features/perms.rs b/src/uucore/src/lib/features/perms.rs index 110313642..984d6dd40 100644 --- a/src/uucore/src/lib/features/perms.rs +++ b/src/uucore/src/lib/features/perms.rs @@ -203,6 +203,7 @@ impl ChownExecutor { Ok(()) } + #[allow(clippy::cognitive_complexity)] fn traverse>(&self, root: P) -> i32 { let path = root.as_ref(); let meta = match self.obtain_meta(path, self.dereference) { @@ -270,6 +271,7 @@ impl ChownExecutor { } } + #[allow(clippy::cognitive_complexity)] fn dive_into>(&self, root: P) -> i32 { let root = root.as_ref(); @@ -421,6 +423,7 @@ type GidUidFilterParser = fn(&ArgMatches) -> UResult<(Option, Option, /// `parse_gid_uid_and_filter` will be called to obtain the target gid and uid, and the filter, /// from `ArgMatches`. /// `groups_only` determines whether verbose output will only mention the group. +#[allow(clippy::cognitive_complexity)] pub fn chown_base( mut command: Command, args: impl crate::Args, diff --git a/src/uucore/src/lib/features/tokenize/num_format/formatters/float_common.rs b/src/uucore/src/lib/features/tokenize/num_format/formatters/float_common.rs index c277e60a6..e0a29217c 100644 --- a/src/uucore/src/lib/features/tokenize/num_format/formatters/float_common.rs +++ b/src/uucore/src/lib/features/tokenize/num_format/formatters/float_common.rs @@ -40,6 +40,7 @@ fn has_enough_digits( } impl FloatAnalysis { + #[allow(clippy::cognitive_complexity)] pub fn analyze( str_in: &str, initial_prefix: &InitialPrefix, @@ -219,6 +220,7 @@ fn round_terminal_digit( (before_dec, after_dec, false) } +#[allow(clippy::cognitive_complexity)] pub fn get_primitive_dec( initial_prefix: &InitialPrefix, str_in: &str, diff --git a/src/uucore/src/lib/features/tokenize/num_format/formatters/intf.rs b/src/uucore/src/lib/features/tokenize/num_format/formatters/intf.rs index e0eb0ffd3..0f6e78de6 100644 --- a/src/uucore/src/lib/features/tokenize/num_format/formatters/intf.rs +++ b/src/uucore/src/lib/features/tokenize/num_format/formatters/intf.rs @@ -40,6 +40,7 @@ impl Intf { // is_zero: true if number is zero, false otherwise // len_digits: length of digits used to create the int // important, for example, if we run into a non-valid character + #[allow(clippy::cognitive_complexity)] fn analyze(str_in: &str, signed_out: bool, initial_prefix: &InitialPrefix) -> IntAnalysis { // the maximum number of digits we could conceivably // have before the decimal point without exceeding the diff --git a/src/uucore/src/lib/features/tokenize/num_format/num_format.rs b/src/uucore/src/lib/features/tokenize/num_format/num_format.rs index 9aa97f811..c9b1178b6 100644 --- a/src/uucore/src/lib/features/tokenize/num_format/num_format.rs +++ b/src/uucore/src/lib/features/tokenize/num_format/num_format.rs @@ -87,6 +87,7 @@ fn get_provided(str_in_opt: Option<&String>) -> Option { // a base, // and an offset for index after all // initial spacing, sign, base prefix, and leading zeroes +#[allow(clippy::cognitive_complexity)] fn get_initial_prefix(str_in: &str, field_type: &FieldType) -> InitialPrefix { let mut str_it = str_in.chars(); let mut ret = InitialPrefix { diff --git a/src/uucore/src/lib/features/tokenize/sub.rs b/src/uucore/src/lib/features/tokenize/sub.rs index af13fb83f..5bdb24dc6 100644 --- a/src/uucore/src/lib/features/tokenize/sub.rs +++ b/src/uucore/src/lib/features/tokenize/sub.rs @@ -173,6 +173,7 @@ impl SubParser { prefix_char, )) } + #[allow(clippy::cognitive_complexity)] fn sub_vals_retrieved(&mut self, it: &mut PutBackN) -> UResult { if !Self::successfully_eat_prefix(it, &mut self.text_so_far)? { return Ok(false); @@ -342,6 +343,7 @@ impl SubParser { } impl Sub { + #[allow(clippy::cognitive_complexity)] pub(crate) fn write(&self, writer: &mut W, pf_args_it: &mut Peekable>) where W: Write, diff --git a/src/uucore/src/lib/features/tokenize/unescaped_text.rs b/src/uucore/src/lib/features/tokenize/unescaped_text.rs index b4f632901..29c657ed8 100644 --- a/src/uucore/src/lib/features/tokenize/unescaped_text.rs +++ b/src/uucore/src/lib/features/tokenize/unescaped_text.rs @@ -197,6 +197,7 @@ impl UnescapedText { // and return a wrapper around a Vec of unescaped bytes // break on encounter of sub symbol ('%[^%]') unless called // through %b subst. + #[allow(clippy::cognitive_complexity)] pub fn from_it_core( writer: &mut W, it: &mut PutBackN, From cd688662ec2df3ef18cd6357de8bde4e07d586b5 Mon Sep 17 00:00:00 2001 From: Sylvestre Ledru Date: Sat, 6 May 2023 14:53:28 +0200 Subject: [PATCH 3/3] fix some lines_filter_map_ok clippy warnings --- src/uu/dircolors/src/dircolors.rs | 2 +- src/uucore/src/lib/features/fsext.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/uu/dircolors/src/dircolors.rs b/src/uu/dircolors/src/dircolors.rs index fe78924f4..19c3f7e31 100644 --- a/src/uu/dircolors/src/dircolors.rs +++ b/src/uu/dircolors/src/dircolors.rs @@ -136,7 +136,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> { )); } else if files[0].eq("-") { let fin = BufReader::new(std::io::stdin()); - result = parse(fin.lines().filter_map(Result::ok), &out_format, files[0]); + result = parse(fin.lines().map_while(Result::ok), &out_format, files[0]); } else { let path = Path::new(files[0]); if path.is_dir() { diff --git a/src/uucore/src/lib/features/fsext.rs b/src/uucore/src/lib/features/fsext.rs index 1e7f84e6a..89f1d6e71 100644 --- a/src/uucore/src/lib/features/fsext.rs +++ b/src/uucore/src/lib/features/fsext.rs @@ -409,7 +409,7 @@ pub fn read_fs_list() -> Result, std::io::Error> { let reader = BufReader::new(f); Ok(reader .lines() - .filter_map(|line| line.ok()) + .map_while(Result::ok) .filter_map(|line| { let raw_data = line.split_whitespace().collect::>(); MountInfo::new(file_name, &raw_data)