Skip to content

Commit f116f57

Browse files
refactor(clippy): collapse nested if blocks across multiple files (#711)
1 parent 64b8d35 commit f116f57

6 files changed

Lines changed: 76 additions & 77 deletions

File tree

src/compile/filter_ir.rs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -632,17 +632,17 @@ pub fn validate_pr_filters(filters: &super::types::PrFilters) -> Vec<Diagnostic>
632632
let mut diags = Vec::new();
633633

634634
// min_changes > max_changes
635-
if let (Some(min), Some(max)) = (filters.min_changes, filters.max_changes) {
636-
if min > max {
637-
diags.push(Diagnostic {
638-
severity: Severity::Error,
639-
filter: "min-changes / max-changes".into(),
640-
message: format!(
641-
"min-changes ({}) is greater than max-changes ({}) — no PR can satisfy both",
642-
min, max
643-
),
644-
});
645-
}
635+
if let (Some(min), Some(max)) = (filters.min_changes, filters.max_changes)
636+
&& min > max
637+
{
638+
diags.push(Diagnostic {
639+
severity: Severity::Error,
640+
filter: "min-changes / max-changes".into(),
641+
message: format!(
642+
"min-changes ({}) is greater than max-changes ({}) — no PR can satisfy both",
643+
min, max
644+
),
645+
});
646646
}
647647

648648
// Time window validation

src/compile/pr_filters.rs

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -30,38 +30,38 @@ pub(super) fn generate_native_pr_trigger(pr: &PrTriggerConfig) -> String {
3030

3131
let mut yaml = String::from("pr:\n");
3232

33-
if let Some(branches) = &pr.branches {
34-
if !branches.include.is_empty() || !branches.exclude.is_empty() {
35-
yaml.push_str(" branches:\n");
36-
if !branches.include.is_empty() {
37-
yaml.push_str(" include:\n");
38-
for b in &branches.include {
39-
yaml.push_str(&format!(" - '{}'\n", b.replace('\'', "''")));
40-
}
33+
if let Some(branches) = &pr.branches
34+
&& (!branches.include.is_empty() || !branches.exclude.is_empty())
35+
{
36+
yaml.push_str(" branches:\n");
37+
if !branches.include.is_empty() {
38+
yaml.push_str(" include:\n");
39+
for b in &branches.include {
40+
yaml.push_str(&format!(" - '{}'\n", b.replace('\'', "''")));
4141
}
42-
if !branches.exclude.is_empty() {
43-
yaml.push_str(" exclude:\n");
44-
for b in &branches.exclude {
45-
yaml.push_str(&format!(" - '{}'\n", b.replace('\'', "''")));
46-
}
42+
}
43+
if !branches.exclude.is_empty() {
44+
yaml.push_str(" exclude:\n");
45+
for b in &branches.exclude {
46+
yaml.push_str(&format!(" - '{}'\n", b.replace('\'', "''")));
4747
}
4848
}
4949
}
5050

51-
if let Some(paths) = &pr.paths {
52-
if !paths.include.is_empty() || !paths.exclude.is_empty() {
53-
yaml.push_str(" paths:\n");
54-
if !paths.include.is_empty() {
55-
yaml.push_str(" include:\n");
56-
for p in &paths.include {
57-
yaml.push_str(&format!(" - '{}'\n", p.replace('\'', "''")));
58-
}
51+
if let Some(paths) = &pr.paths
52+
&& (!paths.include.is_empty() || !paths.exclude.is_empty())
53+
{
54+
yaml.push_str(" paths:\n");
55+
if !paths.include.is_empty() {
56+
yaml.push_str(" include:\n");
57+
for p in &paths.include {
58+
yaml.push_str(&format!(" - '{}'\n", p.replace('\'', "''")));
5959
}
60-
if !paths.exclude.is_empty() {
61-
yaml.push_str(" exclude:\n");
62-
for p in &paths.exclude {
63-
yaml.push_str(&format!(" - '{}'\n", p.replace('\'', "''")));
64-
}
60+
}
61+
if !paths.exclude.is_empty() {
62+
yaml.push_str(" exclude:\n");
63+
for p in &paths.exclude {
64+
yaml.push_str(&format!(" - '{}'\n", p.replace('\'', "''")));
6565
}
6666
}
6767
}

src/logging.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -98,11 +98,11 @@ impl log::Log for FileLogger {
9898
);
9999

100100
// Write to file (always capture debug+)
101-
if record.level() <= self.file_level {
102-
if let Ok(mut file) = self.file.lock() {
103-
let _ = file.write_all(message.as_bytes());
104-
let _ = file.flush();
105-
}
101+
if record.level() <= self.file_level
102+
&& let Ok(mut file) = self.file.lock()
103+
{
104+
let _ = file.write_all(message.as_bytes());
105+
let _ = file.flush();
106106
}
107107

108108
// Write to stderr according to selected runtime verbosity

src/mcp.rs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1525,17 +1525,17 @@ pub async fn run_http(
15251525
// Constant-time comparison to prevent timing side-channels.
15261526
// Length check is non-constant-time but leaking length doesn't
15271527
// help brute-force a high-entropy token.
1528-
if let Some(auth) = req.headers().get("authorization") {
1529-
if let Ok(auth_str) = auth.to_str() {
1530-
let expected_header = format!("Bearer {}", expected);
1531-
use subtle::ConstantTimeEq;
1532-
let expected_bytes = expected_header.as_bytes();
1533-
let provided_bytes = auth_str.as_bytes();
1534-
if expected_bytes.len() == provided_bytes.len()
1535-
&& expected_bytes.ct_eq(provided_bytes).into()
1536-
{
1537-
return next.run(req).await;
1538-
}
1528+
if let Some(auth) = req.headers().get("authorization")
1529+
&& let Ok(auth_str) = auth.to_str()
1530+
{
1531+
let expected_header = format!("Bearer {}", expected);
1532+
use subtle::ConstantTimeEq;
1533+
let expected_bytes = expected_header.as_bytes();
1534+
let provided_bytes = auth_str.as_bytes();
1535+
if expected_bytes.len() == provided_bytes.len()
1536+
&& expected_bytes.ct_eq(provided_bytes).into()
1537+
{
1538+
return next.run(req).await;
15391539
}
15401540
}
15411541

src/runtimes/dotnet/extension.rs

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -110,29 +110,28 @@ in the repository.\n"
110110

111111
// Validate version string. Skip the injection check for the
112112
// `global.json` sentinel — it's a literal keyword, not a version.
113-
if let Some(version) = self.config.version() {
114-
if !version.eq_ignore_ascii_case(GLOBAL_JSON_SENTINEL) {
115-
validate::reject_pipeline_injection(version, "runtimes.dotnet.version")?;
116-
}
113+
if let Some(version) = self.config.version()
114+
&& !version.eq_ignore_ascii_case(GLOBAL_JSON_SENTINEL)
115+
{
116+
validate::reject_pipeline_injection(version, "runtimes.dotnet.version")?;
117117
}
118118

119119
// global.json conflict detection: if the agent's compile directory
120120
// contains a `global.json`, the SDK version is already pinned by
121121
// that file and the front matter must not also specify an explicit
122122
// version. Either drop the version or set `version: "global.json"`.
123-
if let Some(compile_dir) = ctx.compile_dir {
124-
if compile_dir.join("global.json").exists()
125-
&& self.config.version().is_some()
126-
&& !self.config.use_global_json()
127-
{
128-
anyhow::bail!(
129-
"runtimes.dotnet.version: a 'global.json' file exists at '{}', \
130-
which already pins the .NET SDK version. Either remove \
131-
'runtimes.dotnet.version' or set it to the literal string \
132-
'global.json' to use UseDotNet@2's useGlobalJson mode.",
133-
compile_dir.display()
134-
);
135-
}
123+
if let Some(compile_dir) = ctx.compile_dir
124+
&& compile_dir.join("global.json").exists()
125+
&& self.config.version().is_some()
126+
&& !self.config.use_global_json()
127+
{
128+
anyhow::bail!(
129+
"runtimes.dotnet.version: a 'global.json' file exists at '{}', \
130+
which already pins the .NET SDK version. Either remove \
131+
'runtimes.dotnet.version' or set it to the literal string \
132+
'global.json' to use UseDotNet@2's useGlobalJson mode.",
133+
compile_dir.display()
134+
);
136135
}
137136

138137
// Validate config path (defend against pipeline injection). The value

src/update_check.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,13 @@ pub async fn check_for_update() {
2626
// Only print if the version parses to a valid semver triple so we
2727
// never forward raw API content (e.g. ANSI escape sequences) to
2828
// the terminal. Use the reconstructed string, not `latest`.
29-
if let Some((maj, min, pat)) = parse_version(latest) {
30-
if (maj, min, pat) > parse_version(CURRENT_VERSION).unwrap_or((0, 0, 0)) {
31-
eprintln!(
32-
"A newer version of ado-aw is available: v{maj}.{min}.{pat} (you have v{CURRENT_VERSION}).\n\
33-
Update at: https://github.com/githubnext/ado-aw/releases/latest"
34-
);
35-
}
29+
if let Some((maj, min, pat)) = parse_version(latest)
30+
&& (maj, min, pat) > parse_version(CURRENT_VERSION).unwrap_or((0, 0, 0))
31+
{
32+
eprintln!(
33+
"A newer version of ado-aw is available: v{maj}.{min}.{pat} (you have v{CURRENT_VERSION}).\n\
34+
Update at: https://github.com/githubnext/ado-aw/releases/latest"
35+
);
3636
}
3737
}
3838
Err(e) => {

0 commit comments

Comments
 (0)