refactor: deduplicate engine internals, replace bubble sorts, remove dead code

Extract shared code that was duplicated across functions:
- taskJSON struct (MarshalJSON/UnmarshalJSON) to package-level type
- scanTask(scanner) helper for GetTask/GetTasks (~70 identical lines)
- monthNames map for parseMonthName/parseDayAndMonth
- applyNonDateAttribute helper for Apply/ApplyToNew
- resolveDisplayID calls replace inline loops in FormatTaskListWithFormat

Replace O(n²) bubble sorts with sort.Slice in all four report sort
functions (sortByUrgency, NewestReport, NextReport, OldestReport).

Remove dead code: formatTimeWithColor (unused, also used time.Now()
instead of timeNow()), getCurrentTimestamp (unnecessary wrapper).

Remove ~20 comments that restated the next line of code.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-02-21 01:46:46 +01:00
parent a11f452d3b
commit 9973631df0
8 changed files with 122 additions and 288 deletions
+6 -29
View File
@@ -29,15 +29,9 @@ func FormatTaskListWithFormat(tasks []*Task, ws *WorkingSet, format string) stri
if format == "minimal" {
result := ""
for i, task := range tasks {
displayID := i + 1
if ws != nil {
// Use working set display ID if available
for id, uuid := range ws.byID {
if uuid == task.UUID {
displayID = id
break
}
}
displayID := resolveDisplayID(task, ws)
if displayID == 0 {
displayID = i + 1
}
urgency := task.CalculateUrgency(coeffs)
urgencyColor := getUrgencyColor(urgency)
@@ -71,15 +65,9 @@ func FormatTaskListWithFormat(tasks []*Task, ws *WorkingSet, format string) stri
// Add rows
for i, task := range tasks {
displayID := i + 1
if ws != nil {
// Use working set display ID if available
for id, uuid := range ws.byID {
if uuid == task.UUID {
displayID = id
break
}
}
displayID := resolveDisplayID(task, ws)
if displayID == 0 {
displayID = i + 1
}
urgency := task.CalculateUrgency(coeffs)
@@ -270,8 +258,6 @@ func FormatTagCounts(tagCounts map[string]int) string {
return t.Render()
}
// Helper functions
func formatStatus(status Status) string {
switch status {
case StatusPending:
@@ -322,7 +308,6 @@ func formatUrgency(urgency float64) string {
}
func getUrgencyColor(urgency float64) *color.Color {
// Returns color for minimal format
if urgency >= 10.0 {
return color.New(color.FgHiRed, color.Bold)
} else if urgency >= 5.0 {
@@ -362,14 +347,6 @@ func formatDue(due *time.Time) string {
return rel
}
func formatTimeWithColor(t time.Time) string {
now := time.Now()
if t.Before(now) {
return color.RedString(t.Format("2006-01-02 15:04"))
}
return t.Format("2006-01-02 15:04")
}
func formatTime(t time.Time) string {
return t.Format("2006-01-02 15:04")
}