Skip to content

Commit 2bfdabf

Browse files
committed
all: enable ciippy::collapsible_if
1 parent 4704cae commit 2bfdabf

File tree

44 files changed

+87
-9
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+87
-9
lines changed

Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -720,7 +720,6 @@ unexpected_cfgs = { level = "warn", check-cfg = [
720720
unused_qualifications = "warn"
721721

722722
[workspace.lints.clippy]
723-
collapsible_if = { level = "allow", priority = 127 } # remove me
724723
# The counts were generated with this command:
725724
# cargo clippy --all-targets --workspace --message-format=json --quiet \
726725
# | jq -r '.message.code.code | select(. != null and startswith("clippy::"))' \

src/uu/date/src/format_modifiers.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -316,6 +316,7 @@ fn strip_default_padding(value: &str) -> String {
316316
if stripped.is_empty() {
317317
return "0".to_string();
318318
}
319+
#[allow(clippy::collapsible_if)]
319320
if let Some(first_char) = stripped.chars().next() {
320321
if first_char.is_ascii_digit() {
321322
return stripped.to_string();
@@ -443,6 +444,7 @@ fn apply_modifiers(value: &str, parsed: &ParsedSpec<'_>) -> Result<String, Forma
443444
// GNU behavior: + only adds sign if:
444445
// 1. An explicit width is provided, OR
445446
// 2. The value exceeds the default width for that specifier (e.g., year > 4 digits)
447+
#[allow(clippy::collapsible_if)]
446448
if force_sign && !result.starts_with('+') && !result.starts_with('-') {
447449
if result.chars().next().is_some_and(|c| c.is_ascii_digit()) {
448450
let default_w = get_default_width(specifier);

src/uu/df/src/df.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ impl Options {
156156
let exclude: Option<Vec<_>> = matches
157157
.get_many::<OsString>(OPT_EXCLUDE_TYPE)
158158
.map(|v| v.map(|s| s.to_string_lossy().to_string()).collect());
159-
159+
#[allow(clippy::collapsible_if)]
160160
if let (Some(include), Some(exclude)) = (&include, &exclude) {
161161
if let Some(types) = Self::get_intersected_types(include, exclude) {
162162
return Err(OptionsError::FilesystemTypeBothSelectedAndExcluded(types));
@@ -235,11 +235,13 @@ fn is_included(mi: &MountInfo, opt: &Options) -> bool {
235235
}
236236

237237
// Don't show filesystems if they have been explicitly excluded.
238+
#[allow(clippy::collapsible_if)]
238239
if let Some(ref excludes) = opt.exclude {
239240
if excludes.contains(&mi.fs_type) {
240241
return false;
241242
}
242243
}
244+
#[allow(clippy::collapsible_if)]
243245
if let Some(ref includes) = opt.include {
244246
if !includes.contains(&mi.fs_type) {
245247
return false;
@@ -311,6 +313,7 @@ fn get_all_filesystems(opt: &Options) -> UResult<Vec<Filesystem>> {
311313
// this loop quadratic in the length of `vmi`. This could be
312314
// improved by a more efficient implementation of `is_best()`,
313315
// but `vmi` is probably not very long in practice.
316+
#[allow(clippy::collapsible_if)]
314317
if is_included(&mi, opt) && is_best(&mounts, &mi) {
315318
let dev_path: &Path = Path::new(&mi.dev_name);
316319
// Only check is_symlink() for absolute paths. For non-absolute paths

src/uu/du/src/du.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -517,6 +517,7 @@ fn safe_du(
517517
}
518518

519519
// Process directories recursively
520+
#[allow(clippy::collapsible_if)]
520521
if is_dir {
521522
if options.one_file_system {
522523
if let (Some(this_inode), Some(my_inode)) = (this_stat.inode, my_stat.inode) {
@@ -637,6 +638,7 @@ fn du_regular(
637638
&& options.dereference == Deref::All
638639
&& this_stat.metadata.is_dir()
639640
{
641+
#[allow(clippy::collapsible_if)]
640642
if let Some(inode) = this_stat.inode {
641643
if ancestors.contains(&inode) {
642644
// This symlink points to an ancestor directory - skip to avoid cycle
@@ -674,7 +676,7 @@ fn du_regular(
674676
// Mark this inode as seen
675677
seen_inodes.insert(inode);
676678
}
677-
679+
#[allow(clippy::collapsible_if)]
678680
if this_stat.metadata.is_dir() {
679681
if options.one_file_system {
680682
if let (Some(this_inode), Some(my_inode)) =
@@ -1143,6 +1145,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
11431145

11441146
// Pre-populate seen_inodes with the starting directory to detect cycles
11451147
let stat = Stat::new(&path, None, &traversal_options);
1148+
#[allow(clippy::collapsible_if)]
11461149
if let Ok(stat) = stat.as_ref() {
11471150
if let Some(inode) = stat.inode {
11481151
if !traversal_options.count_links && seen_inodes.contains(&inode) {
@@ -1172,6 +1175,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
11721175
}
11731176
Err(e) => {
11741177
// Check if this is our "already handled" error
1178+
#[allow(clippy::collapsible_if)]
11751179
if let mpsc::SendError(Err(simple_error)) = e.as_ref() {
11761180
if simple_error.code() == 0 {
11771181
// Error already handled, continue to next file

src/uu/env/src/env.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -697,6 +697,7 @@ impl EnvAppData {
697697
self.do_input_debug_printing = self
698698
.do_input_debug_printing
699699
.or(Some(matches.get_count("debug") >= 2));
700+
#[allow(clippy::collapsible_if)]
700701
if let Some(value) = self.do_input_debug_printing {
701702
if value {
702703
debug_print_args(&original_args);

src/uu/env/src/variable_parser.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ impl<'a> VariableParser<'a, '_> {
1818
}
1919

2020
fn check_variable_name_start(&self) -> Result<(), EnvError> {
21+
#[allow(clippy::collapsible_if)]
2122
if let Some(c) = self.get_current_char() {
2223
if c.is_ascii_digit() {
2324
return Err(EnvError::EnvParsingOfVariableUnexpectedNumber(

src/uu/expr/src/syntax_tree.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -518,6 +518,7 @@ fn evaluate_match_expression(left_bytes: Vec<u8>, right_bytes: Vec<u8>) -> ExprR
518518
let left_encoded = onig::EncodedBytes::ascii(&left_bytes);
519519
let pos = regex_search(&regex, left_encoded, left_bytes.len(), &mut region);
520520

521+
#[allow(clippy::collapsible_if)]
521522
if pos.is_some() {
522523
if let Some((start, end)) = region.pos(1) {
523524
let capture_bytes = &left_bytes[start..end];

src/uu/ln/src/ln.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -298,6 +298,7 @@ fn link_files_in_dir(files: &[PathBuf], target_dir: &Path, settings: &Settings)
298298
let remove_target = || {
299299
// In that case, we don't want to do link resolution
300300
// We need to clean the target
301+
#[allow(clippy::collapsible_if)]
301302
if target_dir.is_file() {
302303
if let Err(e) = fs::remove_file(target_dir) {
303304
show_error!(
@@ -374,6 +375,7 @@ fn link_files_in_dir(files: &[PathBuf], target_dir: &Path, settings: &Settings)
374375
}
375376

376377
fn relative_path<'a>(src: &'a Path, dst: &Path) -> Cow<'a, Path> {
378+
#[allow(clippy::collapsible_if)]
377379
if let Ok(src_abs) = canonicalize(src, MissingHandling::Missing, ResolveMode::Physical) {
378380
if let Ok(dst_abs) = canonicalize(
379381
dst.parent().unwrap(),

src/uu/ls/src/colors.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ impl<'a> StyleManager<'a> {
7373
let mut force_suffix_reset: bool = false;
7474
let mut applied_raw_code = false;
7575

76+
#[allow(clippy::collapsible_if)]
7677
if self.is_reset() {
7778
if let Some(norm_sty) = self.get_normal_style().copied() {
7879
style_code.push_str(&self.get_style_code(&norm_sty));
@@ -324,6 +325,7 @@ impl<'a> StyleManager<'a> {
324325
return None;
325326
}
326327
let mut target = path.path().read_link().ok()?;
328+
#[allow(clippy::collapsible_if)]
327329
if target.is_relative() {
328330
if let Some(parent) = path.path().parent() {
329331
target = parent.join(target);
@@ -404,6 +406,7 @@ impl<'a> StyleManager<'a> {
404406

405407
#[cfg(unix)]
406408
fn indicator_for_file(&self, path: &PathData) -> Option<Indicator> {
409+
#[allow(clippy::collapsible_if)]
407410
if self.needs_file_metadata() {
408411
if let Some(metadata) = path.metadata() {
409412
let mode = metadata.mode();
@@ -442,6 +445,7 @@ impl<'a> StyleManager<'a> {
442445

443446
#[cfg(unix)]
444447
fn indicator_for_directory(&self, path: &PathData) -> Option<Indicator> {
448+
#[allow(clippy::collapsible_if)]
445449
if self.needs_dir_metadata() {
446450
if let Some(metadata) = path.metadata() {
447451
let mode = metadata.mode();
@@ -541,6 +545,7 @@ pub(crate) fn color_name(
541545
}
542546
}
543547

548+
#[allow(clippy::collapsible_if)]
544549
if target_symlink.is_none() && path.file_type().is_some_and(fs::FileType::is_symlink) {
545550
if let Some(colored) = style_manager.color_symlink_name(path, name.clone(), wrap) {
546551
return colored;

src/uu/ls/src/config.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -719,6 +719,7 @@ impl Config {
719719
{
720720
format = Format::Long;
721721
} else if let Some(mut indices) = options.indices_of(options::format::ONE_LINE) {
722+
#[allow(clippy::collapsible_if)]
722723
if options.value_source(options::format::ONE_LINE)
723724
== Some(clap::parser::ValueSource::CommandLine)
724725
&& indices.any(|i| i > idx)
@@ -918,6 +919,7 @@ impl Config {
918919
locale_quoting = None;
919920
}
920921

922+
#[allow(clippy::collapsible_if)]
921923
if needs_color {
922924
if let Err(err) = validate_ls_colors_env() {
923925
if let LsColorsParseError::UnrecognizedPrefix(prefix) = &err {

0 commit comments

Comments
 (0)