diff --git a/cmd/api-linter/cli.go b/cmd/api-linter/cli.go index aa05e0bd..01d6524b 100644 --- a/cmd/api-linter/cli.go +++ b/cmd/api-linter/cli.go @@ -165,10 +165,21 @@ func (c *cli) lint(rules lint.RuleRegistry, configs lint.Configs) error { }, } // Resolve file absolute paths to relative ones. + // Using supplied import paths first. protoFiles, err := protoparse.ResolveFilenames(c.ProtoImportPaths, c.ProtoFiles...) if err != nil { return err } + // Then resolve again against ".", the local directory. + // This is necessary because ResolveFilenames won't resolve a path if it + // relative to *at least one* of the given import paths, which can result + // in duplicate file parsing and compilation errors, as seen in #1465 and + // #1471. So we resolve against local (default) and flag specified import + // paths separately. + protoFiles, err = protoparse.ResolveFilenames([]string{"."}, protoFiles...) + if err != nil { + return err + } fd, err := p.ParseFiles(protoFiles...) if err != nil { if err == protoparse.ErrInvalidSource {