(repoRoot string, patterns []string, includeTests bool, allowedNames, allowedTypes map[string]bool)
| 193 | } |
| 194 | |
| 195 | func 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 | |
| 242 | var ( |
| 243 | nameMismatchRE = regexp.MustCompile(`^change Go field name "([^"]+)" to ".*" for .* tag ".*" in struct "([^"]+)"$`) |
no test coverage detected
searching dependent graphs…