diff --git a/go/tools/builders/nogo_main.go b/go/tools/builders/nogo_main.go index e33b490277..15f1573700 100644 --- a/go/tools/builders/nogo_main.go +++ b/go/tools/builders/nogo_main.go @@ -43,6 +43,8 @@ import ( "golang.org/x/tools/go/gcexportdata" ) +const nogoDefaultConfigName = "_default" + func init() { if err := analysis.Validate(analyzers); err != nil { log.Fatal(err) @@ -89,7 +91,7 @@ func run(args []string) error { return fmt.Errorf("errors found by nogo during build-time code analysis:\n%s\n", diagnostics) } if *xPath != "" { - if err := ioutil.WriteFile(abs(*xPath), facts, 0666); err != nil { + if err := ioutil.WriteFile(abs(*xPath), facts, 0o666); err != nil { return fmt.Errorf("error writing facts: %v", err) } } @@ -380,6 +382,16 @@ func (g *goPackage) String() string { return g.types.Path() } +func mergeMap(a, b map[string]string) (out map[string]string) { + for k, v := range a { + out[k] = v + } + for k, v := range b { + out[k] = v + } + return out +} + // checkAnalysisResults checks the analysis diagnostics in the given actions // and returns a string containing all the diagnostics that should be printed // to the build log. @@ -390,6 +402,10 @@ func checkAnalysisResults(actions []*action, pkg *goPackage) string { } var diagnostics []entry var errs []error + var defaultConfig *config + if dc, ok := configs[nogoDefaultConfigName]; ok { + defaultConfig = &dc + } for _, act := range actions { if act.err != nil { // Analyzer failed. @@ -401,12 +417,17 @@ func checkAnalysisResults(actions []*action, pkg *goPackage) string { } config, ok := configs[act.a.Name] if !ok { - // If the analyzer is not explicitly configured, it emits diagnostics for - // all files. - for _, diag := range act.diagnostics { - diagnostics = append(diagnostics, entry{Diagnostic: diag, Analyzer: act.a}) + if defaultConfig != nil { + config = *defaultConfig + // Continue processing using the defaultConfig as config. + } else { + // If the analyzer is not explicitly configured, it emits diagnostics for + // all files. + for _, diag := range act.diagnostics { + diagnostics = append(diagnostics, entry{Diagnostic: diag, Analyzer: act.a}) + } + continue } - continue } // Discard diagnostics based on the analyzer configuration. for _, d := range act.diagnostics {