refactor: extract magic numbers to named constants#276
Open
ishaan812 wants to merge 3 commits intoentireio:mainfrom
Open
refactor: extract magic numbers to named constants#276ishaan812 wants to merge 3 commits intoentireio:mainfrom
ishaan812 wants to merge 3 commits intoentireio:mainfrom
Conversation
Improves code maintainability by replacing hardcoded numeric literals
and strings with named constants:
- Add MaxCommitTraversalDepth (1000) for git history traversal safety limit
- Replaces bare 1000 in strategy/common.go, auto_commit.go, rewind.go, explain.go
- Also standardizes auto_commit.go to use errStop sentinel instead of ad-hoc error
- Add maxPromptPreviewLen (100) in hooks_geminicli_handlers.go for log truncation
- Add maxDisplayPromptLen (500) in manual_commit_condensation.go for display truncation
- Add RedactedPlaceholder constant ("REDACTED") to redact package
- Replaces bare string literal in String() function
All tests pass (23 packages), build succeeds, formatting verified.
Co-authored-by: Cursor <cursoragent@cursor.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This PR improves code maintainability by replacing hardcoded numeric literals and strings with named constants. This makes the code more self-documenting and easier to maintain.
Changes
1. MaxCommitTraversalDepth constant (1000)
MaxCommitTraversalDepthconstant tostrategy/common.go1000literals in 4 files:strategy/common.go-IsAncestorOf()functionstrategy/auto_commit.go-findReferencedCheckpoints()function (also standardized to useerrStopsentinel)rewind.go-countCommitsBetween()functionexplain.go-computeReachableFromMain()function2. Prompt truncation constants
maxPromptPreviewLen = 100inhooks_geminicli_handlers.gofor log preview truncationmaxDisplayPromptLen = 500inmanual_commit_condensation.gofor display truncation3. RedactedPlaceholder constant
RedactedPlaceholder = "REDACTED"(exported) toredact/redact.goString()functionTesting
go build ./...)gofmtFiles Changed
cmd/entire/cli/explain.gocmd/entire/cli/hooks_geminicli_handlers.gocmd/entire/cli/rewind.gocmd/entire/cli/strategy/auto_commit.gocmd/entire/cli/strategy/common.gocmd/entire/cli/strategy/manual_commit_condensation.goredact/redact.goTotal: 7 files, +20 insertions, -11 deletions
Motivation
This addresses code quality improvements identified during codebase analysis: