Skip to content

Commit e7b02ae

Browse files
committed
chore: fix clippy warnings
1 parent 0b996fc commit e7b02ae

File tree

8 files changed

+42
-44
lines changed

8 files changed

+42
-44
lines changed

src/color.rs

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -26,70 +26,70 @@ pub trait ColorExt {
2626
where
2727
Self: Sized + Display,
2828
{
29-
format!("{}", self)
29+
format!("{self}")
3030
}
3131

3232
fn bright(self, _flags: &args::Flags) -> String
3333
where
3434
Self: Sized + Display,
3535
{
36-
format!("{}", self)
36+
format!("{self}")
3737
}
3838

3939
fn underline(self, _flags: &args::Flags) -> String
4040
where
4141
Self: Sized + Display,
4242
{
43-
format!("{}", self)
43+
format!("{self}")
4444
}
4545

4646
fn green(self, _flags: &args::Flags) -> String
4747
where
4848
Self: Sized + Display,
4949
{
50-
format!("{}", self)
50+
format!("{self}")
5151
}
5252

5353
fn yellow(self, _flags: &args::Flags) -> String
5454
where
5555
Self: Sized + Display,
5656
{
57-
format!("{}", self)
57+
format!("{self}")
5858
}
5959

6060
fn cyan(self, _flags: &args::Flags) -> String
6161
where
6262
Self: Sized + Display,
6363
{
64-
format!("{}", self)
64+
format!("{self}")
6565
}
6666

6767
fn white(self, _flags: &args::Flags) -> String
6868
where
6969
Self: Sized + Display,
7070
{
71-
format!("{}", self)
71+
format!("{self}")
7272
}
7373

7474
fn grey(self, _flags: &args::Flags) -> String
7575
where
7676
Self: Sized + Display,
7777
{
78-
format!("{}", self)
78+
format!("{self}")
7979
}
8080

8181
fn red(self, _flags: &args::Flags) -> String
8282
where
8383
Self: Sized + Display,
8484
{
85-
format!("{}", self)
85+
format!("{self}")
8686
}
8787

8888
fn custom(self, _color: &str, _flags: &args::Flags) -> String
8989
where
9090
Self: Sized + Display,
9191
{
92-
format!("{}", self)
92+
format!("{self}")
9393
}
9494
}
9595

@@ -100,79 +100,79 @@ where
100100
{
101101
fn reset(self, flags: &args::Flags) -> String {
102102
if flags.no_color {
103-
format!("{}", self)
103+
format!("{self}")
104104
} else {
105105
format!("{}{}", self, String::from(RESET))
106106
}
107107
}
108108

109109
fn bright(self, flags: &args::Flags) -> String {
110110
if flags.no_color {
111-
format!("{}", self)
111+
format!("{self}")
112112
} else {
113113
format!("{}{}", String::from(BRIGHT), self)
114114
}
115115
}
116116

117117
fn underline(self, flags: &args::Flags) -> String {
118118
if flags.no_color {
119-
format!("{}", self)
119+
format!("{self}")
120120
} else {
121121
format!("{}{}", String::from(UNDERLINE), self)
122122
}
123123
}
124124

125125
fn green(self, flags: &args::Flags) -> String {
126126
if flags.no_color {
127-
format!("{}", self)
127+
format!("{self}")
128128
} else {
129129
format!("{}{}", String::from(GREEN), self)
130130
}
131131
}
132132

133133
fn yellow(self, flags: &args::Flags) -> String {
134134
if flags.no_color {
135-
format!("{}", self)
135+
format!("{self}")
136136
} else {
137137
format!("{}{}", String::from(YELLOW), self)
138138
}
139139
}
140140

141141
fn cyan(self, flags: &args::Flags) -> String {
142142
if flags.no_color {
143-
format!("{}", self)
143+
format!("{self}")
144144
} else {
145145
format!("{}{}", String::from(CYAN), self)
146146
}
147147
}
148148

149149
fn white(self, flags: &args::Flags) -> String {
150150
if flags.no_color {
151-
format!("{}", self)
151+
format!("{self}")
152152
} else {
153153
format!("{}{}", String::from(WHITE), self)
154154
}
155155
}
156156

157157
fn grey(self, flags: &args::Flags) -> String {
158158
if flags.no_color {
159-
format!("{}", self)
159+
format!("{self}")
160160
} else {
161161
format!("{}{}", String::from(GREY), self)
162162
}
163163
}
164164

165165
fn red(self, flags: &args::Flags) -> String {
166166
if flags.no_color {
167-
format!("{}", self)
167+
format!("{self}")
168168
} else {
169169
format!("{}{}", String::from(RED), self)
170170
}
171171
}
172172

173173
fn custom(self, color: &str, flags: &args::Flags) -> String {
174174
if flags.no_color {
175-
format!("{}", self)
175+
format!("{self}")
176176
} else {
177177
format!("{}{}", String::from(color), self)
178178
}
@@ -198,7 +198,7 @@ mod tests {
198198
theme: None,
199199
};
200200

201-
assert_eq!(format!("{}abc{}", CYAN, RESET), format!("{}", "abc".cyan(&flags).reset(&flags)));
201+
assert_eq!(format!("{CYAN}abc{RESET}"), format!("{}", "abc".cyan(&flags).reset(&flags)));
202202
}
203203

204204
#[test]

src/core/args.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ pub fn get() -> (Flags, Vec<String>) {
4949
.skip(1) // remove first argument which is self
5050
.flat_map(|arg: String| {
5151
if arg.starts_with('-') && arg.get(1..2) != Some("-") && arg.get(1..).map(|text| text.len()) > Some(1) {
52-
arg.chars().skip(1).map(|c: char| format!("-{}", c)).collect::<Vec<String>>()
52+
arg.chars().skip(1).map(|c: char| format!("-{c}")).collect::<Vec<String>>()
5353
} else {
5454
vec![arg]
5555
}

src/core/config.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,11 @@ pub fn parse_arg(arg: &str, flags: &Flags) -> bool {
1515
let name = parts[0];
1616
let value = parts[1];
1717

18-
println!("set {}={}", name, value);
18+
println!("set {name}={value}");
1919
let content_split = match fs::read_to_string(CONFIG_NAME) {
2020
Ok(x) => x,
2121
Err(_) => {
22-
fs::write(CONFIG_NAME, format!("{}={}", name, value)).die("Unable to save config file", flags);
22+
fs::write(CONFIG_NAME, format!("{name}={value}")).die("Unable to save config file", flags);
2323
return true;
2424
}
2525
};
@@ -32,10 +32,10 @@ pub fn parse_arg(arg: &str, flags: &Flags) -> bool {
3232

3333
for (i, line) in contents.iter().enumerate() {
3434
let final_line = &(line.replace("\r", "").trim().to_string());
35-
if final_line.starts_with(format!("{}=", name).as_str()) {
35+
if final_line.starts_with(format!("{name}=").as_str()) {
3636
found = true;
3737

38-
edited_line = format!("{}={}", name, value);
38+
edited_line = format!("{name}={value}");
3939
contents[i] = edited_line.as_str();
4040

4141
break;
@@ -44,7 +44,7 @@ pub fn parse_arg(arg: &str, flags: &Flags) -> bool {
4444

4545
// append to file
4646
if !found {
47-
edited_line2 = format!("{}={}", name, value);
47+
edited_line2 = format!("{name}={value}");
4848
contents.push(edited_line2.as_str());
4949
}
5050

@@ -63,7 +63,7 @@ pub fn parse_arg(arg: &str, flags: &Flags) -> bool {
6363

6464
for line in contents.split('\n') {
6565
let final_line = &(line.trim().to_string());
66-
if final_line.starts_with(format!("{}=", body).as_str()) {
66+
if final_line.starts_with(format!("{body}=").as_str()) {
6767
found = true;
6868

6969
let parts: Vec<&str> = final_line.split('=').collect();
@@ -74,7 +74,7 @@ pub fn parse_arg(arg: &str, flags: &Flags) -> bool {
7474
}
7575

7676
if !found {
77-
println!("config {} not found", body);
77+
println!("config {body} not found");
7878
}
7979
}
8080

@@ -93,7 +93,7 @@ pub fn get_bool(name: &str, default: bool) -> bool {
9393

9494
for line in contents.split('\n') {
9595
let final_line = &(line.trim().to_string());
96-
if final_line.starts_with(format!("{}=", name).as_str()) {
96+
if final_line.starts_with(format!("{name}=").as_str()) {
9797
let parts: Vec<&str> = final_line.split('=').collect();
9898

9999
return parts[1] == "true";

src/main.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ fn print_item(root: &path::Path, path: path::PathBuf, theme: &themes::Theme, fla
144144
}
145145

146146
fn do_scan(root: &path::Path, path_to_scan: &path::Path, theme: &themes::Theme, flags: &args::Flags) {
147-
if !flags.all && file_detection::is_hidden(&path_to_scan.to_path_buf(), flags) {
147+
if !flags.all && file_detection::is_hidden(path_to_scan, flags) {
148148
return;
149149
}
150150

@@ -244,7 +244,7 @@ fn main() {
244244
} else {
245245
newline = "\n";
246246
}
247-
println!("{}", format!("{}Folder {}:", newline, arg).underline(&flags).bright(&flags).reset(&flags));
247+
println!("{}", format!("{newline}Folder {arg}:").underline(&flags).bright(&flags).reset(&flags));
248248
}
249249
for entry in fs::read_dir(path_to_scan).die("Directory cannot be accessed", &flags) {
250250
let path = entry.die("Failed retrieving path", &flags).path();

src/modules/file_size.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ const FILE_SIZE_WIDTH: usize = 5;
33
pub fn human_readable_size(size: u64) -> String {
44
if size < 1024 {
55
// bytes
6-
return format!("{1:>0$}B", FILE_SIZE_WIDTH, size);
6+
format!("{size:>FILE_SIZE_WIDTH$}B")
77
} else if size < 1049000 {
88
// kibibytes
99
format!("{1:>0$.1}K", FILE_SIZE_WIDTH, size as f64 / 1024f64)

src/themes/lang.rs

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -41,15 +41,13 @@ impl<'a> Language<'a> {
4141
index,
4242
original.to_owned(),
4343
format!(
44-
"Line must include a pair of key and value separated by a equal (=) in text line \"{key}={value}\" ({key}={value})",
45-
key = key,
46-
value = value
44+
"Line must include a pair of key and value separated by a equal (=) in text line \"{key}={value}\" ({key}={value})"
4745
),
4846
));
4947
} else if key.is_empty() {
50-
return Err(ParserError::new(index, original.to_owned(), format!("Missing key in text line \"{}={}\"", key, value)));
48+
return Err(ParserError::new(index, original.to_owned(), format!("Missing key in text line \"{key}={value}\"")));
5149
} else if value.is_empty() {
52-
return Err(ParserError::new(index, original.to_owned(), format!("Missing value in text line \"{}={}\"", key, value)));
50+
return Err(ParserError::new(index, original.to_owned(), format!("Missing value in text line \"{key}={value}\"")));
5351
} else if key == "e" || key == "extensions" {
5452
let mut ext = String::new();
5553
for (i, mut ch) in value.char_indices() {
@@ -80,7 +78,7 @@ impl<'a> Language<'a> {
8078
));
8179
}
8280
if num.len() > 3 {
83-
return Err(ParserError::new(index, original.to_owned(), format!("Color must range from 0 to 255, received {}", num)));
81+
return Err(ParserError::new(index, original.to_owned(), format!("Color must range from 0 to 255, received {num}")));
8482
}
8583
if ch == ',' && i == 0 {
8684
continue;
@@ -114,11 +112,11 @@ impl<'a> Language<'a> {
114112
),
115113
));
116114
}
117-
if !value.chars().all(|c| c.is_digit(16)) {
115+
if !value.chars().all(|c| c.is_ascii_hexdigit()) {
118116
return Err(ParserError::new(
119117
index,
120118
original.to_owned(),
121-
format!("One or more characters in \"{}\" icon are not valid hexadecimal characters", value),
119+
format!("One or more characters in \"{value}\" icon are not valid hexadecimal characters"),
122120
));
123121
}
124122
icon = value.to_owned()

src/themes/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,15 +27,15 @@ pub fn get_theme(name: &Option<String>, flags: &Flags) -> String {
2727
Some(path) => {
2828
let theme_dir = home::home_dir().die("Unable to get home directory", flags).join(".lsfp-themes");
2929
if Path::new(&path).exists() && (path.contains('.') || path.contains('/') || path.contains('\\')) {
30-
std::fs::read_to_string(&path).die("Unable to read passed file path", flags)
30+
std::fs::read_to_string(path).die("Unable to read passed file path", flags)
3131
} else {
3232
let mut text = String::new();
3333
if !theme_dir.exists() {
3434
std::fs::create_dir(&theme_dir).die("Unable to create theme directory", flags);
3535
};
3636
for item in std::fs::read_dir(&theme_dir).die("Unable to read theme directory", flags) {
3737
if item.die("Unable to unwrap theme directory read result", flags).file_name() == std::ffi::OsString::from(&path) {
38-
text = std::fs::read_to_string(&theme_dir.join(&path)).die(&format!("Unable to read named file {}", path), flags)
38+
text = std::fs::read_to_string(theme_dir.join(path)).die(&format!("Unable to read named file {path}"), flags)
3939
}
4040
}
4141
text

src/themes/types.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ pub trait VecConvert {
1313

1414
impl VecConvert for Vec<u8> {
1515
fn as_color(&self) -> Color {
16-
(*self.get(0).unwrap_or(&0), *self.get(1).unwrap_or(&0), *self.get(2).unwrap_or(&0))
16+
(*self.first().unwrap_or(&0), *self.get(1).unwrap_or(&0), *self.get(2).unwrap_or(&0))
1717
}
1818
}
1919

0 commit comments

Comments
 (0)