Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ensure generated imports doesn't start with digit #806

Merged
merged 1 commit into from
Aug 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions pkg/fixtures/12345678/http/http.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
package http

type MyStruct struct{}
2 changes: 2 additions & 0 deletions pkg/fixtures/same_name_imports.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,13 @@ package test
import (
"net/http"

number_dir_http "github.com/vektra/mockery/v2/pkg/fixtures/12345678/http"
my_http "github.com/vektra/mockery/v2/pkg/fixtures/http"
)

// Example is an example
type Example interface {
A() http.Flusher
B(fixtureshttp string) my_http.MyStruct
C(fixtureshttp string) number_dir_http.MyStruct
}
2 changes: 1 addition & 1 deletion pkg/generator.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import (

const mockConstructorParamTypeNamePrefix = "mockConstructorTestingT"

var invalidIdentifierChar = regexp.MustCompile("[^[:digit:][:alpha:]_]")
var invalidIdentifierChar = regexp.MustCompile("^[[:digit:]]|[^[:digit:][:alpha:]_]")

func DetermineOutputPackageName(
interfaceFileName string,
Expand Down
1 change: 1 addition & 0 deletions pkg/generator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,7 @@ func (s *GeneratorSuite) TestGeneratorPrologueWithMultipleImportsSameName() {

expected := `package mocks

import _2345678http "github.com/vektra/mockery/v2/pkg/fixtures/12345678/http"
import fixtureshttp "github.com/vektra/mockery/v2/pkg/fixtures/http"
import http "net/http"
import mock "github.com/stretchr/testify/mock"
Expand Down
Loading