Skip to content

Commit

Permalink
Collapse if statements and rename interface in the fixtures.
Browse files Browse the repository at this point in the history
  • Loading branch information
Ilia Sevostianov authored and i-sevostyanov committed Apr 21, 2022
1 parent b8c62f7 commit 2e1360a
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@ package foo

import "github.com/vektra/mockery/v2/pkg/fixtures/example_project/bar/foo"

type Collision interface {
type PackageNameSameAsImport interface {
NewClient() foo.Client
}
12 changes: 4 additions & 8 deletions pkg/generator.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,11 +106,9 @@ func (g *Generator) addPackageImportWithName(ctx context.Context, path, name str
}

func (g *Generator) getNonConflictingName(path, name string) string {
if !g.importNameExists(name) {
if !g.importNameExists(name) && (!g.InPackage || g.iface.Pkg.Name() != name) {
// do not allow imports with the same name as the package when inPackage
if !g.InPackage || g.iface.Pkg.Name() != name {
return name
}
return name
}

// The path will always contain '/' because it is enforced in getLocalizedPath
Expand All @@ -126,11 +124,9 @@ func (g *Generator) getNonConflictingName(path, name string) string {
var prospectiveName string
for i := 1; i <= numDirectories; i++ {
prospectiveName = strings.Join(cleanedDirectories[numDirectories-i:], "")
if !g.importNameExists(prospectiveName) {
if !g.importNameExists(prospectiveName) && (!g.InPackage || g.iface.Pkg.Name() != prospectiveName) {
// do not allow imports with the same name as the package when inPackage
if !g.InPackage || g.iface.Pkg.Name() != prospectiveName {
return prospectiveName
}
return prospectiveName
}
}
// Try adding numbers to the given name
Expand Down

0 comments on commit 2e1360a

Please sign in to comment.