Skip to content

refactor: consolidate task search logic into generic function #9

@LudoLoops

Description

@LudoLoops

Issue

Multiple functions perform nearly identical task lookups across the entire task directory:

Duplicate Functions:

  • MarkTaskDone (task.go:106)
  • MarkTaskInProgress (task.go:169)
  • MarkTaskInProgressByTitle (task.go:233)
  • IncrementPomodoroCountForActiveTask (task.go:297)

Each implements the same filepath.Walk logic with different predicates.

Refactor Opportunity

Create a generic search function:

func findTaskByPredicate(cfg config.Config, predicate func(*config.Task) bool) (*config.Task, string, error) {
    // Common walk logic
    // Call predicate(task) to check condition
}

Then simplify existing functions:

func MarkTaskDone(cfg config.Config, taskTitle string) {
    task, path, _ := findTaskByPredicate(cfg, func(t *config.Task) bool {
        return strings.EqualFold(t.Title, taskTitle)
    })
    // ...
}

Benefits

  • Eliminates ~200 lines of duplicate code
  • Single place to optimize search logic
  • Easier maintenance

Impact

🟢 Low - Improvement only, no bug fix

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions