Skip to content

Commit 8a7eb0d

Browse files
committed
refactor: Move Terraform comment to be adjacent to its code
Move the "# If the instance is managed by Terraform, warn user" comment from line 963 to line 981, placing it directly above the terraform_managed assignment it describes. The comment was previously orphaned from its relevant code by 20 lines of unrelated confirmation prompts. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
1 parent 895ae51 commit 8a7eb0d

File tree

2 files changed

+20
-2
lines changed

2 files changed

+20
-2
lines changed

progress.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -761,3 +761,22 @@ This created a misleading function signature - if a function's return value is n
761761

762762
---
763763

764+
## 2026-01-18: Move misplaced Terraform comment in `terminate()` function
765+
766+
**File:** `remote/instance.py`
767+
768+
**Issue:** The comment "# If the instance is managed by Terraform, warn user" on line 963 was separated from the code it described by 20 lines. The actual Terraform check (`terraform_managed = any(...)`) was on line 983, with the confirmation prompts and user input validation in between.
769+
770+
This is a code smell because:
771+
1. Orphaned comments reduce readability
772+
2. The comment implied the next line would be the Terraform check, but it wasn't
773+
3. Readers had to mentally reconnect the comment to its relevant code
774+
775+
**Changes:**
776+
- Removed the comment from line 963 (after the tag fetching try-except block)
777+
- Added the comment directly above line 981 where `terraform_managed` is assigned
778+
779+
This places the comment immediately before the code it documents, following the principle that comments should be adjacent to the code they describe.
780+
781+
---
782+

remote/instance.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -960,8 +960,6 @@ def terminate(instance_name: str | None = typer.Argument(None, help="Instance na
960960
typer.secho(f"Error accessing instance information: {e}", fg=typer.colors.RED)
961961
# Continue with empty tags
962962

963-
# If the instance is managed by Terraform, warn user
964-
965963
# Confirmation step
966964
typer.secho(
967965
f"WARNING: You are about to terminate instance {instance_name}. "
@@ -980,6 +978,7 @@ def terminate(instance_name: str | None = typer.Argument(None, help="Instance na
980978

981979
return
982980

981+
# If the instance is managed by Terraform, warn user
983982
terraform_managed = any("terraform" in tag["Value"].lower() for tag in tags)
984983

985984
if terraform_managed:

0 commit comments

Comments
 (0)