MCPcopy Create free account
hub / github.com/google/go-github / analyzeRepo

Function analyzeRepo

tools/check-structfield-settings/main.go:195–240  ·  view source on GitHub ↗
(repoRoot string, patterns []string, includeTests bool, allowedNames, allowedTypes map[string]bool)

Source from the content-addressed store, hash-verified

193}
194
195func analyzeRepo(repoRoot string, patterns []string, includeTests bool, allowedNames, allowedTypes map[string]bool) (map[string]bool, map[string]bool, error) {
196 plugin, err := structfield.New(nil)
197 if err != nil {
198 return nil, nil, err
199 }
200 created, err := plugin.BuildAnalyzers()
201 if err != nil {
202 return nil, nil, err
203 }
204 if len(created) == 0 {
205 return nil, nil, errors.New("no analyzers returned by structfield")
206 }
207 analyzer := created[0]
208
209 cfg := &packages.Config{
210 Mode: packages.LoadAllSyntax,
211 Dir: repoRoot,
212 Tests: includeTests,
213 }
214 pkgs, err := packages.Load(cfg, patterns...)
215 if err != nil {
216 return nil, nil, err
217 }
218 if packages.PrintErrors(pkgs) > 0 {
219 return nil, nil, errors.New("package load errors")
220 }
221
222 graph, err := checker.Analyze([]*analysis.Analyzer{analyzer}, pkgs, &checker.Options{Sequential: true})
223 if err != nil {
224 return nil, nil, err
225 }
226
227 usedNames := make(map[string]bool)
228 usedTypes := make(map[string]bool)
229
230 for act := range graph.All() {
231 if !act.IsRoot || act.Analyzer != analyzer {
232 continue
233 }
234 for _, diag := range act.Diagnostics {
235 markUsedException(diag.Message, allowedNames, allowedTypes, usedNames, usedTypes)
236 }
237 }
238
239 return usedNames, usedTypes, nil
240}
241
242var (
243 nameMismatchRE = regexp.MustCompile(`^change Go field name "([^"]+)" to ".*" for .* tag ".*" in struct "([^"]+)"$`)

Callers 1

mainFunction · 0.85

Calls 3

NewFunction · 0.92
markUsedExceptionFunction · 0.85
BuildAnalyzersMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…