Skip to content

Commit 718d0f7

Browse files
committed
refactor: clippy lints
Signed-off-by: Christina Sørensen <ces@fem.gg>
1 parent 765807b commit 718d0f7

27 files changed

+94
-98
lines changed

benches/my_benchmark.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ use criterion::{black_box, criterion_group, criterion_main, Criterion};
99
pub fn criterion_benchmark(c: &mut Criterion) {
1010
c.bench_function("logger", |b| {
1111
b.iter(|| {
12-
eza::logger::configure(black_box(std::env::var_os(eza::options::vars::EZA_DEBUG)))
13-
})
12+
eza::logger::configure(black_box(std::env::var_os(eza::options::vars::EZA_DEBUG)));
13+
});
1414
});
1515
}
1616

build.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,12 @@
99
/// just the version for *release* versions so the builds are reproducible.
1010
///
1111
/// This script generates the string from the environment variables that Cargo
12-
/// adds (http://doc.crates.io/environment-variables.html) and runs `git` to
12+
/// adds (<http://doc.crates.io/environment-variables.html>) and runs `git` to
1313
/// get the SHA1 hash. It then writes the string into a file, which exa then
1414
/// includes at build-time.
1515
///
16-
/// - https://stackoverflow.com/q/43753491/3484614
17-
/// - https://crates.io/crates/vergen
16+
/// - <https://stackoverflow.com/q/43753491/3484614>
17+
/// - <https://crates.io/crates/vergen>
1818
use std::env;
1919
use std::fs::File;
2020
use std::io::{self, Write};
@@ -116,7 +116,7 @@ fn version_string() -> String {
116116

117117
/// Finds whether a feature is enabled by examining the Cargo variable.
118118
fn feature_enabled(name: &str) -> bool {
119-
env::var(format!("CARGO_FEATURE_{}", name))
119+
env::var(format!("CARGO_FEATURE_{name}"))
120120
.map(|e| !e.is_empty())
121121
.unwrap_or(false)
122122
}

src/fs/dir.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ use std::io;
1212
use std::path::{Path, PathBuf};
1313
use std::slice::Iter as SliceIter;
1414

15-
use log::*;
15+
use log::info;
1616

1717
use crate::fs::File;
1818

@@ -50,7 +50,7 @@ impl Dir {
5050

5151
/// Produce an iterator of IO results of trying to read all the files in
5252
/// this directory.
53-
pub fn files<'dir, 'ig>(
53+
#[must_use] pub fn files<'dir, 'ig>(
5454
&'dir self,
5555
dots: DotFilter,
5656
git: Option<&'ig GitCache>,
@@ -71,12 +71,12 @@ impl Dir {
7171
}
7272

7373
/// Whether this directory contains a file with the given path.
74-
pub fn contains(&self, path: &Path) -> bool {
74+
#[must_use] pub fn contains(&self, path: &Path) -> bool {
7575
self.contents.iter().any(|p| p.path().as_path() == path)
7676
}
7777

7878
/// Append a path onto the path specified by this directory.
79-
pub fn join(&self, child: &Path) -> PathBuf {
79+
#[must_use] pub fn join(&self, child: &Path) -> PathBuf {
8080
self.path.join(child)
8181
}
8282
}

src/fs/dir_action.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,15 +43,15 @@ pub enum DirAction {
4343

4444
impl DirAction {
4545
/// Gets the recurse options, if this dir action has any.
46-
pub fn recurse_options(self) -> Option<RecurseOptions> {
46+
#[must_use] pub fn recurse_options(self) -> Option<RecurseOptions> {
4747
match self {
4848
Self::Recurse(o) => Some(o),
4949
_ => None,
5050
}
5151
}
5252

5353
/// Whether to treat directories as regular files or not.
54-
pub fn treat_dirs_as_files(self) -> bool {
54+
#[must_use] pub fn treat_dirs_as_files(self) -> bool {
5555
match self {
5656
Self::AsFile => true,
5757
Self::Recurse(o) => o.tree,
@@ -74,7 +74,7 @@ pub struct RecurseOptions {
7474

7575
impl RecurseOptions {
7676
/// Returns whether a directory of the given depth would be too deep.
77-
pub fn is_too_deep(self, depth: usize) -> bool {
77+
#[must_use] pub fn is_too_deep(self, depth: usize) -> bool {
7878
match self.max_depth {
7979
None => false,
8080
Some(d) => d <= depth,

src/fs/feature/git.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ use std::path::{Path, PathBuf};
1414
use std::sync::Mutex;
1515

1616
use git2::StatusEntry;
17-
use log::*;
17+
use log::{debug, error, info, warn};
1818

1919
use crate::fs::fields as f;
2020

@@ -31,11 +31,11 @@ pub struct GitCache {
3131
}
3232

3333
impl GitCache {
34-
pub fn has_anything_for(&self, index: &Path) -> bool {
34+
#[must_use] pub fn has_anything_for(&self, index: &Path) -> bool {
3535
self.repos.iter().any(|e| e.has_path(index))
3636
}
3737

38-
pub fn get(&self, index: &Path, prefix_lookup: bool) -> f::Git {
38+
#[must_use] pub fn get(&self, index: &Path, prefix_lookup: bool) -> f::Git {
3939
self.repos
4040
.iter()
4141
.find(|repo| repo.has_path(index))
@@ -410,7 +410,7 @@ fn current_branch(repo: &git2::Repository) -> Option<String> {
410410
}
411411

412412
impl f::SubdirGitRepo {
413-
pub fn from_path(dir: &Path, status: bool) -> Self {
413+
#[must_use] pub fn from_path(dir: &Path, status: bool) -> Self {
414414
let path = &reorient(dir);
415415

416416
if let Ok(repo) = git2::Repository::open(path) {

src/fs/fields.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ pub enum Type {
6262
}
6363

6464
impl Type {
65-
pub fn is_regular_file(self) -> bool {
65+
#[must_use] pub fn is_regular_file(self) -> bool {
6666
matches!(self, Self::File)
6767
}
6868
}

src/fs/file.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ use std::time::SystemTime;
2424

2525
use chrono::prelude::*;
2626

27-
use log::*;
27+
use log::{debug, error, trace};
2828
#[cfg(unix)]
2929
use std::sync::LazyLock;
3030

@@ -209,18 +209,18 @@ impl<'dir> File<'dir> {
209209
file
210210
}
211211

212-
pub fn new_aa_current(parent_dir: &'dir Dir, total_size: bool) -> File<'dir> {
212+
#[must_use] pub fn new_aa_current(parent_dir: &'dir Dir, total_size: bool) -> File<'dir> {
213213
File::new_aa(parent_dir.path.clone(), parent_dir, ".", total_size)
214214
}
215215

216-
pub fn new_aa_parent(path: PathBuf, parent_dir: &'dir Dir, total_size: bool) -> File<'dir> {
216+
#[must_use] pub fn new_aa_parent(path: PathBuf, parent_dir: &'dir Dir, total_size: bool) -> File<'dir> {
217217
File::new_aa(path, parent_dir, "..", total_size)
218218
}
219219

220220
/// A file’s name is derived from its string. This needs to handle directories
221221
/// such as `/` or `..`, which have no `file_name` component. So instead, just
222222
/// use the last component as the name.
223-
pub fn filename(path: &Path) -> String {
223+
#[must_use] pub fn filename(path: &Path) -> String {
224224
if let Some(back) = path.components().next_back() {
225225
back.as_os_str().to_string_lossy().to_string()
226226
} else {
@@ -1016,7 +1016,7 @@ pub enum FileTarget<'dir> {
10161016
impl<'dir> FileTarget<'dir> {
10171017
/// Whether this link doesn’t lead to a file, for whatever reason. This
10181018
/// gets used to determine how to highlight the link in grid views.
1019-
pub fn is_broken(&self) -> bool {
1019+
#[must_use] pub fn is_broken(&self) -> bool {
10201020
matches!(self, Self::Broken(_) | Self::Err(_))
10211021
}
10221022
}

src/fs/filter.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -365,7 +365,7 @@ impl IgnorePatterns {
365365
}
366366

367367
/// Create a new empty set of patterns that matches nothing.
368-
pub fn empty() -> Self {
368+
#[must_use] pub fn empty() -> Self {
369369
Self {
370370
patterns: Vec::new(),
371371
}

src/fs/recursive_size.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ impl RecursiveSize {
3737
/// assert_eq!(x.is_none(), false);
3838
/// ```
3939
#[inline]
40-
pub const fn is_none(&self) -> bool {
40+
#[must_use] pub const fn is_none(&self) -> bool {
4141
matches!(*self, Self::None)
4242
}
4343

@@ -53,7 +53,7 @@ impl RecursiveSize {
5353
/// assert_eq!(RecursiveSize::Some(2, 3).unwrap_bytes_or(1), 2);
5454
/// ```
5555
#[inline]
56-
pub const fn unwrap_bytes_or(self, default: u64) -> u64 {
56+
#[must_use] pub const fn unwrap_bytes_or(self, default: u64) -> u64 {
5757
match self {
5858
Self::Some(bytes, _blocks) => bytes,
5959
_ => default,

src/options/config.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
// SPDX-FileCopyrightText: 2014 Benjamin Sago
66
// SPDX-License-Identifier: MIT
77
use crate::theme::ThemeFileType as FileType;
8-
use crate::theme::*;
8+
use crate::theme::{FileKinds, FileNameStyle, Git, GitRepo, IconStyle, Links, Permissions, SELinuxContext, SecurityContext, Size, UiStyles, Users};
99
use nu_ansi_term::{Color, Style};
1010
use serde::{Deserialize, Deserializer, Serialize};
1111
use serde_norway;
@@ -49,7 +49,7 @@ where
4949

5050
#[rustfmt::skip]
5151
fn color_from_str(s: &str) -> Option<Color> {
52-
use Color::*;
52+
use Color::{Black, Blue, Cyan, DarkGray, Default, Fixed, Green, LightBlue, LightCyan, LightGray, LightGreen, LightMagenta, LightPurple, LightRed, LightYellow, Magenta, Purple, Red, Rgb, White, Yellow};
5353
match s {
5454
// nothing
5555
"" | "none" | "None" => None,
@@ -604,10 +604,10 @@ impl FromOverride<UiStylesOverride> for UiStyles {
604604
}
605605
}
606606
impl ThemeConfig {
607-
pub fn from_path(path: PathBuf) -> Self {
607+
#[must_use] pub fn from_path(path: PathBuf) -> Self {
608608
ThemeConfig { location: path }
609609
}
610-
pub fn to_theme(&self) -> Option<UiStyles> {
610+
#[must_use] pub fn to_theme(&self) -> Option<UiStyles> {
611611
let ui_styles_override: Option<UiStylesOverride> = {
612612
let file = std::fs::File::open(&self.location).ok()?;
613613
serde_norway::from_reader(&file).ok()
@@ -650,7 +650,7 @@ mod tests {
650650

651651
#[test]
652652
fn parse_short_hex_color_from_string() {
653-
for case in ["#f0f", "#F0F"].iter() {
653+
for case in &["#f0f", "#F0F"] {
654654
assert_eq!(color_from_str(case), Some(Color::Rgb(255, 0, 255)));
655655
}
656656
}

0 commit comments

Comments
 (0)