Skip to content

Commit 4faf546

Browse files
committed
fix collapsible_if
1 parent 5b54e08 commit 4faf546

6 files changed

Lines changed: 81 additions & 89 deletions

File tree

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/uucore/build.rs

Lines changed: 38 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -84,18 +84,18 @@ fn detect_target_utility() -> Option<String> {
8484
println!("cargo:rerun-if-env-changed=UUCORE_TARGET_UTIL");
8585

8686
// First check if an explicit environment variable was set
87-
if let Ok(target_util) = env::var("UUCORE_TARGET_UTIL") {
88-
if !target_util.is_empty() {
89-
return Some(target_util);
90-
}
87+
if let Ok(target_util) = env::var("UUCORE_TARGET_UTIL")
88+
&& !target_util.is_empty()
89+
{
90+
return Some(target_util);
9191
}
9292

9393
// Auto-detect utility name from CARGO_PKG_NAME if it's a uu_* package
94-
if let Ok(pkg_name) = env::var("CARGO_PKG_NAME") {
95-
if let Some(util_name) = pkg_name.strip_prefix("uu_") {
96-
println!("cargo:warning=Auto-detected utility name: {util_name}");
97-
return Some(util_name.to_string());
98-
}
94+
if let Ok(pkg_name) = env::var("CARGO_PKG_NAME")
95+
&& let Some(util_name) = pkg_name.strip_prefix("uu_")
96+
{
97+
println!("cargo:warning=Auto-detected utility name: {util_name}");
98+
return Some(util_name.to_string());
9999
}
100100

101101
// Check for a build configuration file in the target directory
@@ -186,10 +186,10 @@ fn embed_all_utility_locales(
186186
let mut util_dirs = Vec::new();
187187
for entry in fs::read_dir(&src_uu_dir)? {
188188
let entry = entry?;
189-
if entry.file_type()?.is_dir() {
190-
if let Some(dir_name) = entry.file_name().to_str() {
191-
util_dirs.push(dir_name.to_string());
192-
}
189+
if entry.file_type()?.is_dir()
190+
&& let Some(dir_name) = entry.file_name().to_str()
191+
{
192+
util_dirs.push(dir_name.to_string());
193193
}
194194
}
195195
util_dirs.sort();
@@ -247,18 +247,14 @@ fn embed_static_utility_locales(
247247

248248
for entry in entries {
249249
let file_name = entry.file_name();
250-
if let Some(dir_name) = file_name.to_str() {
251-
// Match uu_<util>-<version>
252-
if let Some((util_part, _)) = dir_name.split_once('-') {
253-
if let Some(util_name) = util_part.strip_prefix("uu_") {
254-
embed_component_locales(
255-
embedded_file,
256-
locales_to_embed,
257-
util_name,
258-
|locale| entry.path().join(format!("locales/{locale}.ftl")),
259-
)?;
260-
}
261-
}
250+
// Match uu_<util>-<version>
251+
if let Some(dir_name) = file_name.to_str()
252+
&& let Some((util_part, _)) = dir_name.split_once('-')
253+
&& let Some(util_name) = util_part.strip_prefix("uu_")
254+
{
255+
embed_component_locales(embedded_file, locales_to_embed, util_name, |locale| {
256+
entry.path().join(format!("locales/{locale}.ftl"))
257+
})?;
262258
}
263259
}
264260

@@ -366,25 +362,26 @@ where
366362
F: Fn(&str) -> PathBuf,
367363
{
368364
let en_path = path_builder("en-US");
369-
if let Some(locale_dir) = en_path.parent() {
370-
if locale_dir.exists() {
371-
for entry in std::fs::read_dir(locale_dir)? {
372-
let entry = entry?;
373-
let path = entry.path();
374-
if path.extension().is_some_and(|e| e == "ftl") {
375-
if let Some(locale) = path.file_stem().and_then(|s| s.to_str()) {
376-
embed_locale_file(
377-
embedded_file,
378-
&path,
379-
&format!("{component_name}/{locale}.ftl"),
380-
locale,
381-
component_name,
382-
)?;
383-
}
384-
}
365+
if let Some(locale_dir) = en_path.parent()
366+
&& locale_dir.exists()
367+
{
368+
for entry in std::fs::read_dir(locale_dir)? {
369+
let entry = entry?;
370+
let path = entry.path();
371+
if path.extension().is_some_and(|e| e == "ftl")
372+
&& let Some(locale) = path.file_stem().and_then(|s| s.to_str())
373+
{
374+
embed_locale_file(
375+
embedded_file,
376+
&path,
377+
&format!("{component_name}/{locale}.ftl"),
378+
locale,
379+
component_name,
380+
)?;
385381
}
386382
}
387383
}
384+
388385
Ok(())
389386
}
390387

src/uucore/src/lib/mods/clap_localization.rs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -219,17 +219,17 @@ impl<'a> ErrorFormatter<'a> {
219219
}
220220

221221
// Show possible values for InvalidValue errors
222-
if matches!(err.kind(), ErrorKind::InvalidValue) {
223-
if let Some(valid_values) = err.get(ContextKind::ValidValue) {
224-
if !valid_values.to_string().is_empty() {
225-
let _ = writeln!(
226-
stderr(),
227-
"\n [{}: {valid_values}]",
228-
translate!("clap-error-possible-values")
229-
);
230-
}
231-
}
222+
if matches!(err.kind(), ErrorKind::InvalidValue)
223+
&& let Some(valid_values) = err.get(ContextKind::ValidValue)
224+
&& !valid_values.to_string().is_empty()
225+
{
226+
let _ = writeln!(
227+
stderr(),
228+
"\n [{}: {valid_values}]",
229+
translate!("clap-error-possible-values")
230+
);
232231
}
232+
233233
let _ = writeln!(stderr(), "\n{}", translate!("common-help-suggestion"));
234234
} else {
235235
self.print_simple_error_msg(&err.render().to_string());

src/uucore/src/lib/mods/locale.rs

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -93,13 +93,13 @@ impl Localizer {
9393
}
9494

9595
// Fall back to English bundle if available
96-
if let Some(ref fallback) = self.fallback_bundle {
97-
if let Some(message) = fallback.get_message(id).and_then(|m| m.value()) {
98-
let mut errs = Vec::new();
99-
return fallback
100-
.format_pattern(message, args, &mut errs)
101-
.to_string();
102-
}
96+
if let Some(ref fallback) = self.fallback_bundle
97+
&& let Some(message) = fallback.get_message(id).and_then(|m| m.value())
98+
{
99+
let mut errs = Vec::new();
100+
return fallback
101+
.format_pattern(message, args, &mut errs)
102+
.to_string();
103103
}
104104

105105
// Return the key ID if not found anywhere
@@ -230,10 +230,9 @@ fn parse_fluent_resource(
230230
cache: &'static OnceLock<FluentResource>,
231231
) -> Result<&'static FluentResource, LocalizationError> {
232232
// global cache breaks unit tests
233-
if cfg!(not(test)) {
234-
if let Some(res) = cache.get() {
235-
return Ok(res);
236-
}
233+
#[cfgnot(test)]
234+
if let Some(res) = cache.get() {
235+
return Ok(res);
237236
}
238237

239238
let resource = FluentResource::try_new(content.to_string()).map_err(
@@ -284,11 +283,12 @@ fn create_english_bundle_from_embedded(
284283
}
285284

286285
// Checksum algorithms need locale messages from checksum_common
287-
if util_name.ends_with("sum") {
288-
if let Some(uucore_content) = get_embedded_locale("checksum_common/en-US.ftl") {
289-
let uucore_resource = parse_fluent_resource(uucore_content, &CHECKSUM_FLUENT)?;
290-
bundle.add_resource_overriding(uucore_resource);
291-
}
286+
// todo: sum is not checksum_common family. Should we avoid the case?
287+
if util_name.ends_with("sum")
288+
&& let Some(uucore_content) = get_embedded_locale("checksum_common/en-US.ftl")
289+
{
290+
let uucore_resource = parse_fluent_resource(uucore_content, &CHECKSUM_FLUENT)?;
291+
bundle.add_resource_overriding(uucore_resource);
292292
}
293293

294294
// Then, try to load utility-specific strings

src/uucore/src/lib/mods/os.rs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,11 @@ pub fn is_wsl_1() -> bool {
1414
if is_wsl_2() {
1515
return false;
1616
}
17-
if let Ok(b) = std::fs::read("/proc/sys/kernel/osrelease") {
18-
if let Ok(s) = std::str::from_utf8(&b) {
19-
let a = s.to_ascii_lowercase();
20-
return a.contains("microsoft") || a.contains("wsl");
21-
}
17+
if let Ok(b) = std::fs::read("/proc/sys/kernel/osrelease")
18+
&& let Ok(s) = std::str::from_utf8(&b)
19+
{
20+
let a = s.to_ascii_lowercase();
21+
return a.contains("microsoft") || a.contains("wsl");
2222
}
2323
}
2424
false
@@ -28,11 +28,11 @@ pub fn is_wsl_1() -> bool {
2828
pub fn is_wsl_2() -> bool {
2929
#[cfg(target_os = "linux")]
3030
{
31-
if let Ok(b) = std::fs::read("/proc/sys/kernel/osrelease") {
32-
if let Ok(s) = std::str::from_utf8(&b) {
33-
let a = s.to_ascii_lowercase();
34-
return a.contains("wsl2");
35-
}
31+
if let Ok(b) = std::fs::read("/proc/sys/kernel/osrelease")
32+
&& let Ok(s) = std::str::from_utf8(&b)
33+
{
34+
let a = s.to_ascii_lowercase();
35+
return a.contains("wsl2");
3636
}
3737
}
3838
false

src/uucore/src/lib/mods/panic.rs

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,7 @@ use std::panic::{self, PanicHookInfo};
1818
/// Decide whether a panic was caused by a broken pipe (SIGPIPE) error.
1919
fn is_broken_pipe(info: &PanicHookInfo) -> bool {
2020
if let Some(res) = info.payload().downcast_ref::<String>() {
21-
if res.contains("BrokenPipe") || res.contains("Broken pipe") {
22-
return true;
23-
}
21+
return res.contains("BrokenPipe") || res.contains("Broken pipe");
2422
}
2523
false
2624
}
@@ -55,14 +53,12 @@ pub fn preserve_inherited_sigpipe() {
5553
use nix::libc;
5654

5755
// Check if parent specified that SIGPIPE should be default
58-
if let Ok(val) = std::env::var("RUST_SIGPIPE") {
59-
if val == "default" {
60-
unsafe {
61-
libc::signal(libc::SIGPIPE, libc::SIG_DFL);
62-
// Remove the environment variable so child processes don't inherit it incorrectly
63-
std::env::remove_var("RUST_SIGPIPE");
64-
}
65-
}
56+
if let Ok(val) = std::env::var("RUST_SIGPIPE")
57+
&& val == "default"
58+
{
59+
unsafe { libc::signal(libc::SIGPIPE, libc::SIG_DFL) };
60+
// Remove the environment variable so child processes don't inherit it incorrectly
61+
unsafe { std::env::remove_var("RUST_SIGPIPE") };
6662
}
6763
}
6864

0 commit comments

Comments
 (0)