Skip to content

build: bump dependencies#581

Closed
faukah wants to merge 1 commit intomasterfrom
update
Closed

build: bump dependencies#581
faukah wants to merge 1 commit intomasterfrom
update

Conversation

@faukah
Copy link
Contributor

@faukah faukah commented Mar 1, 2026

Automated changes by create-pull-request GitHub action

Summary by CodeRabbit

Release Notes

  • Refactor
    • Streamlined internal conditional logic across multiple modules for improved code maintainability.
    • Updated documentation formatting for clarity.

Co-authored-by: viperML <viperML@users.noreply.github.com>
@coderabbitai
Copy link

coderabbitai bot commented Mar 1, 2026

Walkthrough

This PR systematically refactors conditional logic across the codebase by flattening nested if/if-let structures into single, chained conditions using pattern guards and combined operators. All behavioral changes are preserved while reducing nesting depth and improving readability.

Changes

Cohort / File(s) Summary
Conditional Flattening - Pattern Matching & Guards
src/checks.rs, src/darwin.rs, src/nixos.rs
Replaced nested pattern-matching and guards with combined conditions in pattern guards (e.g., if let Flake { ... } && attribute.is_empty()). Semantically equivalent with reduced nesting.
Conditional Flattening - Multi-step Checks
src/clean.rs, src/logging.rs, src/search.rs
Merged sequential conditional checks into single if statements by chaining conditions with && operators. Logic and control flow remain unchanged.
Conditional Flattening - Complex Logic
src/commands.rs, src/main.rs, src/remote.rs
Simplified multiple nested conditionals into flattened chains, including HOME propagation, environment variable checks (NH_SUDO_ASKPASS, NH_ELEVATION_PROGRAM), exit status checks, and SSH socket cleanup logic.
Documentation Updates
src/installable.rs
Updated code documentation to use backticks for environment variable names (NH_OS_FLAKE instead of plain text). Also refactored nested canonicalize logic into single chained condition.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

Possibly related PRs

  • nixos: cleanup #436: Modifies src/nixos.rs list_generations generation-handling code; this PR simplifies the nested if-let structure in the same function.

Suggested reviewers

  • NotAShelf
🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Title check ⚠️ Warning The title 'build: bump dependencies' is misleading - the PR contains extensive code refactoring that simplifies conditionals and control flow across 10 source files, not just dependency updates. Revise the title to accurately reflect the primary changes, such as 'refactor: simplify nested conditionals across codebase' or 'refactor: flatten conditional chains for improved readability'.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
  • 📝 Generate docstrings (stacked PR)
  • 📝 Generate docstrings (commit on current branch)
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch update

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Nitpick comments (1)
src/commands.rs (1)

548-552: Unused variable binding _askpass - consider simplifying.

The let Ok(_askpass) = std::env::var("NH_SUDO_ASKPASS") binds a variable that's never used. This works, but could be cleaner with std::env::var("NH_SUDO_ASKPASS").is_ok() instead.

However, this is inconsistent with other usages in this file. Looking at Line 500, the askpass variable is actually used to set SUDO_ASKPASS. But at Line 608, you use askpass again. Here, the underscore prefix suggests intentional discard. The code is correct, just noting the stylistic inconsistency.

💡 Optional: Use is_ok() for consistency with intent
     if program_name == "sudo"
-      && let Ok(_askpass) = std::env::var("NH_SUDO_ASKPASS")
+      && std::env::var("NH_SUDO_ASKPASS").is_ok()
     {
       parts.push("-A".to_string());
     }
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/commands.rs` around lines 548 - 552, The conditional uses an unused
binding `_askpass`; replace `let Ok(_askpass) =
std::env::var("NH_SUDO_ASKPASS")` with a plain existence check like
`std::env::var("NH_SUDO_ASKPASS").is_ok()` so the `if program_name == "sudo" &&
...` test expresses intent without an unused variable; ensure this change
remains consistent with other `askpass` usage in the file (the `askpass`
variable set earlier and referenced later).
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@src/commands.rs`:
- Around line 607-611: The code indexes sudo_parts[1] without ensuring
sudo_parts has at least two elements; update the check in the block that sets
SUDO_ASKPASS (inside the logic that uses build_sudo_parts and std_cmd.env) to
first verify sudo_parts.len() > 1 (or use sudo_parts.get(1).map_or(false, |s| s
== "-A")) before comparing to "-A" and reading NH_SUDO_ASKPASS, so the indexing
cannot panic if build_sudo_parts changes.

---

Nitpick comments:
In `@src/commands.rs`:
- Around line 548-552: The conditional uses an unused binding `_askpass`;
replace `let Ok(_askpass) = std::env::var("NH_SUDO_ASKPASS")` with a plain
existence check like `std::env::var("NH_SUDO_ASKPASS").is_ok()` so the `if
program_name == "sudo" && ...` test expresses intent without an unused variable;
ensure this change remains consistent with other `askpass` usage in the file
(the `askpass` variable set earlier and referenced later).

ℹ️ Review info

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between dd40357 and 2f39dce.

⛔ Files ignored due to path filters (2)
  • Cargo.lock is excluded by !**/*.lock
  • flake.lock is excluded by !**/*.lock
📒 Files selected for processing (10)
  • src/checks.rs
  • src/clean.rs
  • src/commands.rs
  • src/darwin.rs
  • src/installable.rs
  • src/logging.rs
  • src/main.rs
  • src/nixos.rs
  • src/remote.rs
  • src/search.rs

Comment on lines +607 to 611
if sudo_parts[1] == "-A"
&& let Ok(askpass) = std::env::var("NH_SUDO_ASKPASS")
{
std_cmd.env("SUDO_ASKPASS", askpass);
}
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor

Potential out-of-bounds access when checking sudo_parts[1].

The condition sudo_parts[1] == "-A" does not guard against the case where sudo_parts has only one element. While build_sudo_parts() always adds at least the elevation program and "env", there's a fragile coupling here.

If build_sudo_parts() were to change and return only one element, this would panic.

🛡️ Defensive check to avoid potential panic
     // check if using SUDO_ASKPASS
-    if sudo_parts[1] == "-A"
+    if sudo_parts.get(1).is_some_and(|arg| arg == "-A")
       && let Ok(askpass) = std::env::var("NH_SUDO_ASKPASS")
     {
       std_cmd.env("SUDO_ASKPASS", askpass);
     }
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
if sudo_parts[1] == "-A"
&& let Ok(askpass) = std::env::var("NH_SUDO_ASKPASS")
{
std_cmd.env("SUDO_ASKPASS", askpass);
}
if sudo_parts.get(1).is_some_and(|arg| arg == "-A")
&& let Ok(askpass) = std::env::var("NH_SUDO_ASKPASS")
{
std_cmd.env("SUDO_ASKPASS", askpass);
}
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/commands.rs` around lines 607 - 611, The code indexes sudo_parts[1]
without ensuring sudo_parts has at least two elements; update the check in the
block that sets SUDO_ASKPASS (inside the logic that uses build_sudo_parts and
std_cmd.env) to first verify sudo_parts.len() > 1 (or use
sudo_parts.get(1).map_or(false, |s| s == "-A")) before comparing to "-A" and
reading NH_SUDO_ASKPASS, so the indexing cannot panic if build_sudo_parts
changes.

@faukah
Copy link
Contributor Author

faukah commented Mar 2, 2026

I'm doing this in #580 to prevent giant merge conflicts.

@faukah faukah closed this Mar 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants