Skip to content

Commit 01e7f27

Browse files
committed
refactor: change from match to if for NO_EMOJI
1 parent 8d62a99 commit 01e7f27

File tree

3 files changed

+37
-40
lines changed

3 files changed

+37
-40
lines changed

src/exercise.rs

+4-3
Original file line numberDiff line numberDiff line change
@@ -127,9 +127,10 @@ name = "{}"
127127
path = "{}.rs""#,
128128
self.name, self.name, self.name
129129
);
130-
let cargo_toml_error_msg = match env::var("NO_EMOJI").is_ok() {
131-
true => "Failed to write Clippy Cargo.toml file.",
132-
false => "Failed to write 📎 Clippy 📎 Cargo.toml file."
130+
let cargo_toml_error_msg = if env::var("NO_EMOJI").is_ok() {
131+
"Failed to write Clippy Cargo.toml file."
132+
} else {
133+
"Failed to write 📎 Clippy 📎 Cargo.toml file."
133134
};
134135
fs::write(CLIPPY_CARGO_TOML_PATH, cargo_toml)
135136
.expect(cargo_toml_error_msg);

src/ui.rs

+24-30
Original file line numberDiff line numberDiff line change
@@ -3,21 +3,18 @@ macro_rules! warn {
33
use std::env;
44
use console::{style, Emoji};
55
let formatstr = format!($fmt, $ex);
6-
match env::var("NO_EMOJI").is_ok() {
7-
true => {
8-
println!(
9-
"{} {}",
10-
style("!").red(),
11-
style(formatstr).red()
12-
);
13-
},
14-
false => {
15-
println!(
16-
"{} {}",
17-
style(Emoji("⚠️ ", "!")).red(),
18-
style(formatstr).red()
19-
);
20-
}
6+
if env::var("NO_EMOJI").is_ok() {
7+
println!(
8+
"{} {}",
9+
style("!").red(),
10+
style(formatstr).red()
11+
);
12+
} else {
13+
println!(
14+
"{} {}",
15+
style(Emoji("⚠️ ", "!")).red(),
16+
style(formatstr).red()
17+
);
2118
}
2219
}};
2320
}
@@ -27,21 +24,18 @@ macro_rules! success {
2724
use std::env;
2825
use console::{style, Emoji};
2926
let formatstr = format!($fmt, $ex);
30-
match env::var("NO_EMOJI").is_ok() {
31-
true => {
32-
println!(
33-
"{} {}",
34-
style("✓").green(),
35-
style(formatstr).green()
36-
);
37-
},
38-
false => {
39-
println!(
40-
"{} {}",
41-
style(Emoji("✅", "✓")).green(),
42-
style(formatstr).green()
43-
);
44-
}
27+
if env::var("NO_EMOJI").is_ok() {
28+
println!(
29+
"{} {}",
30+
style("✓").green(),
31+
style(formatstr).green()
32+
);
33+
} else {
34+
println!(
35+
"{} {}",
36+
style(Emoji("✅", "✓")).green(),
37+
style(formatstr).green()
38+
);
4539
}
4640
}};
4741
}

src/verify.rs

+9-7
Original file line numberDiff line numberDiff line change
@@ -140,9 +140,10 @@ fn prompt_for_completion(exercise: &Exercise, prompt_output: Option<String>) ->
140140

141141
let no_emoji = env::var("NO_EMOJI").is_ok();
142142

143-
let clippy_success_msg = match no_emoji {
144-
true => "The code is compiling, and Clippy is happy!",
145-
false => "The code is compiling, and 📎 Clippy 📎 is happy!"
143+
let clippy_success_msg = if no_emoji {
144+
"The code is compiling, and Clippy is happy!"
145+
} else {
146+
"The code is compiling, and 📎 Clippy 📎 is happy!"
146147
};
147148

148149
let success_msg = match exercise.mode {
@@ -152,10 +153,11 @@ fn prompt_for_completion(exercise: &Exercise, prompt_output: Option<String>) ->
152153
};
153154

154155
println!();
155-
match no_emoji {
156-
true => println!("~*~ {} ~*~", success_msg),
157-
false => println!("🎉 🎉 {} 🎉 🎉", success_msg)
158-
};
156+
if no_emoji {
157+
println!("~*~ {} ~*~", success_msg)
158+
} else {
159+
println!("🎉 🎉 {} 🎉 🎉", success_msg)
160+
}
159161
println!();
160162

161163
if let Some(output) = prompt_output {

0 commit comments

Comments
 (0)