MCPcopy Create free account
hub / github.com/github/gh-aw / GetCodemods

Function GetCodemods

pkg/cli/fix_codemods.go:99–139  ·  view source on GitHub ↗

GetCodemods returns all codemods except any explicitly disabled by ID.

(disabledIDs []string)

Source from the content-addressed store, hash-verified

97
98// GetCodemods returns all codemods except any explicitly disabled by ID.
99func GetCodemods(disabledIDs []string) ([]Codemod, error) {
100 codemods := GetAllCodemods()
101 if len(disabledIDs) == 0 {
102 return codemods, nil
103 }
104
105 disabledSet := make(map[string]struct{}, len(disabledIDs))
106 for _, id := range disabledIDs {
107 if id == "" {
108 continue
109 }
110 disabledSet[id] = struct{}{}
111 }
112
113 if len(disabledSet) == 0 {
114 return codemods, nil
115 }
116
117 knownIDs := make([]string, 0, len(codemods))
118 filtered := make([]Codemod, 0, len(codemods))
119 for _, codemod := range codemods {
120 knownIDs = append(knownIDs, codemod.ID)
121 if _, disabled := disabledSet[codemod.ID]; disabled {
122 continue
123 }
124 filtered = append(filtered, codemod)
125 }
126
127 var unknown []string
128 for id := range disabledSet {
129 if !slices.Contains(knownIDs, id) {
130 unknown = append(unknown, id)
131 }
132 }
133 if len(unknown) > 0 {
134 slices.Sort(unknown)
135 return nil, fmt.Errorf("unknown codemod ID(s): %s", strings.Join(unknown, ", "))
136 }
137
138 return filtered, nil
139}

Calls 2

GetAllCodemodsFunction · 0.85
ErrorfMethod · 0.45