resolve/index.go
func (ix *RuleIndex) AddRule(c *config.Config, r *rule.Rule, f *rule.File) {
	var imps []ImportSpec
	if rslv := ix.mrslv(r, f.Pkg); rslv != nil {
		imps = rslv.Imports(c, r, f)
	}
	// If imps == nil, the rule is not importable. If imps is the empty slice,
	// it may still be importable if it embeds importable libraries.
	if imps == nil {
		return
	}

	record := &ruleRecord{
		rule:       r,
		label:      label.New(c.RepoName, f.Pkg, r.Name()),
		file:       f,
		importedAs: imps,
	}
	if _, ok := ix.labelMap[record.label]; ok {
		log.Printf("multiple rules found with label %s", record.label)
		return
	}
	ix.rules = append(ix.rules, record)
	ix.labelMap[record.label] = record
}
func (ix *RuleIndex) AddRule(c *config.Config, r *rule.Rule, f *rule.File) {
	var imps []ImportSpec
	if rslv := ix.mrslv(r, f.Pkg); rslv != nil {
		imps = rslv.Imports(c, r, f)
	}
	// If imps == nil, the rule is not importable. If imps is the empty slice,
	// it may still be importable if it embeds importable libraries.
	if imps == nil {
		return
	}

	record := &ruleRecord{
		rule:       r,
		label:      label.New(c.RepoName, f.Pkg, r.Name()),
		file:       f,
		importedAs: imps,
	}
	if _, ok := ix.labelMap[record.label]; ok {
		log.Printf("multiple rules found with label %s", record.label)
		return
	}
	ix.rules = append(ix.rules, record)
	ix.labelMap[record.label] = record
}
// AddRule adds a rule r to the index. The rule will only be indexed if there
// is a known resolver for the rule's kind and Resolver.Imports returns a
// non-nil slice.
//
// AddRule may only be called before Finish.