You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Multiple codemod detector functions duplicate the same defensive cascade to navigate nested frontmatter maps (frontmatter["tools"] -> map[string]any -> ["github"] -> map[string]any -> field). Each repeats the value, ok := x.(map[string]any); if !ok { return false } pattern 2-3 levels deep. No shared accessor exists in pkg/cli/yaml_frontmatter_utils.go for this.
Maintainability: Any change to how nested tool config is accessed (e.g. supporting a string shorthand) must touch 8 sites.
Bug Risk: Subtle divergences already exist (some return the map, some only check existence).
Code Bloat: ~10 lines of boilerplate per detector.
Refactoring Recommendations
Add a generic nested-map accessor to pkg/cli/yaml_frontmatter_utils.go, e.g. nestedMap(frontmatter map[string]any, keys ...string) (map[string]any, bool) returning the leaf map, so each detector becomes m, ok := nestedMap(fm, "tools", "github"); if !ok { return false }.
Estimated effort: low (2-3h)
Benefits: eliminates repeated type-assertion ladders; consistent nil/absent handling.
Optionally add nestedValue for leaf scalar lookups used by the same detectors.
Activity