go/analysis: remove requirement for unique Analyzer names

It's hard to prevent two independent analysis writers from
using the same name so enforcing this requiremnet just
causes trouble for analysis writers. Remove the requirement.

It would be nice to guarantee that two packages don't introduce
analyses with the same name, but because analyses are values
and not types, they don't have a logical package.

Change-Id: Iad3493e02ceae04ba3e9015c3e9c68ed9fa4b5a2
Reviewed-on: https://go-review.googlesource.com/c/tools/+/201218
Run-TryBot: Michael Matloob <matloob@golang.org>
Reviewed-by: Dominik Honnef <dominik@honnef.co>
This commit is contained in:
Michael Matloob 2019-10-15 13:44:37 -04:00
parent 89dd9f8220
commit ba31bb9056

View File

@ -9,13 +9,10 @@ import (
// Validate reports an error if any of the analyzers are misconfigured.
// Checks include:
// that the name is a valid identifier;
// that analyzer names are unique;
// that the Requires graph is acyclic;
// that analyzer fact types are unique;
// that each fact type is a pointer.
func Validate(analyzers []*Analyzer) error {
names := make(map[string]bool)
// Map each fact type to its sole generating analyzer.
factTypes := make(map[reflect.Type]*Analyzer)
@ -39,10 +36,6 @@ func Validate(analyzers []*Analyzer) error {
if !validIdent(a.Name) {
return fmt.Errorf("invalid analyzer name %q", a)
}
if names[a.Name] {
return fmt.Errorf("duplicate analyzer name %q", a)
}
names[a.Name] = true
if a.Doc == "" {
return fmt.Errorf("analyzer %q is undocumented", a)