diff --git a/.circleci/config.yml b/.circleci/config.yml deleted file mode 100644 index 82ce2bc..0000000 --- a/.circleci/config.yml +++ /dev/null @@ -1,12 +0,0 @@ -version: 2 -jobs: - build: - docker: - - image: circleci/golang:1.11 - working_directory: /go/src/github.com/moznion/gowrtr - steps: - - checkout - - run: make bootstrap - - run: make ci-check - - run: bash <(curl -s https://codecov.io/bash) - diff --git a/.github/workflows/check.yml b/.github/workflows/check.yml new file mode 100644 index 0000000..9be9943 --- /dev/null +++ b/.github/workflows/check.yml @@ -0,0 +1,27 @@ +on: + push: + +jobs: + test: + name: Check + strategy: + matrix: + go-version: [1.18.x] + os: [ubuntu-latest] + runs-on: ${{ matrix.os }} + steps: + - name: Set up Go + uses: actions/setup-go@v2 + with: + go-version: ${{ matrix.go-version }} + - name: check out + uses: actions/checkout@v2 + - name: install tools + run: "go install golang.org/x/tools/cmd/goimports@latest && go install honnef.co/go/tools/cmd/staticcheck@latest && go install github.com/moznion/go-errgen/cmd/errgen@latest" + - name: check + run: make check + - name: upload coverage + uses: codecov/codecov-action@v2 + with: + token: ${{ secrets.CODECOV_TOKEN }} + diff --git a/.gitignore b/.gitignore index 72bb0fd..30d7e21 100644 --- a/.gitignore +++ b/.gitignore @@ -8,6 +8,7 @@ *.out cover.html +coverage.txt /vendor/ /Godeps/ diff --git a/Makefile b/Makefile index 2db6a3f..f0f1dba 100644 --- a/Makefile +++ b/Makefile @@ -3,12 +3,8 @@ PKGS := $(shell go list ./... | grep -v go-errgen) check: test lint vet fmt-check -ci-check: ci-test lint vet fmt-check test: errgen - go test -v -cover $(PKGS) - -ci-test: errgen go test -v -cover -race -coverprofile=coverage.txt -covermode=atomic $(PKGS) test-coverage: errgen @@ -16,7 +12,7 @@ test-coverage: errgen go tool cover -html=cover.out -o cover.html lint: - golint -set_exit_status $(PKGS) + staticcheck ./... vet: go vet $(PKGS) diff --git a/generator/else.go b/generator/else.go index 58cf125..447c0cc 100644 --- a/generator/else.go +++ b/generator/else.go @@ -32,7 +32,7 @@ func (e *Else) Statements(statements ...Statement) *Else { // Generate generates `else` block as golang code. func (e *Else) Generate(indentLevel int) (string, error) { - stmt := fmt.Sprintf(" else {\n") + stmt := " else {\n" indent := BuildIndent(indentLevel) nextIndentLevel := indentLevel + 1 diff --git a/generator/func_invocation.go b/generator/func_invocation.go index 5805652..0ad705e 100644 --- a/generator/func_invocation.go +++ b/generator/func_invocation.go @@ -7,6 +7,7 @@ import ( ) // FuncInvocation represents a code generator for func invocation. +// FIXME add function name and type-parameters, this would be a breaking change. type FuncInvocation struct { parameters []string callers []string diff --git a/generator/func_signature.go b/generator/func_signature.go index 4606898..cb493fc 100644 --- a/generator/func_signature.go +++ b/generator/func_signature.go @@ -40,6 +40,7 @@ type FuncSignature struct { paramCallers []string funcNameCaller string returnTypesCallers []string + typeParameters TypeParameters } // NewFuncParameter returns a new `FuncSignature`. @@ -81,6 +82,7 @@ func (f *FuncSignature) AddParameters(funcParameters ...*FuncParameter) *FuncSig paramCallers: append(f.paramCallers, fetchClientCallerLineAsSlice(len(funcParameters))...), funcNameCaller: f.funcNameCaller, returnTypesCallers: f.returnTypesCallers, + typeParameters: f.typeParameters, } } @@ -94,6 +96,7 @@ func (f *FuncSignature) Parameters(funcParameters ...*FuncParameter) *FuncSignat paramCallers: fetchClientCallerLineAsSlice(len(funcParameters)), funcNameCaller: f.funcNameCaller, returnTypesCallers: f.returnTypesCallers, + typeParameters: f.typeParameters, } } @@ -121,6 +124,7 @@ func (f *FuncSignature) AddReturnTypeStatements(returnTypes ...*FuncReturnType) paramCallers: f.paramCallers, funcNameCaller: f.funcNameCaller, returnTypesCallers: append(f.returnTypesCallers, fetchClientCallerLineAsSlice(len(returnTypes))...), + typeParameters: f.typeParameters, } } @@ -148,6 +152,20 @@ func (f *FuncSignature) ReturnTypeStatements(returnTypes ...*FuncReturnType) *Fu paramCallers: f.paramCallers, funcNameCaller: f.funcNameCaller, returnTypesCallers: fetchClientCallerLineAsSlice(len(returnTypes)), + typeParameters: f.typeParameters, + } +} + +// TypeParameters sets the TypeParameters onto the caller FuncSignature. +func (f *FuncSignature) TypeParameters(typeParameters TypeParameters) *FuncSignature { + return &FuncSignature{ + funcName: f.funcName, + funcParameters: f.funcParameters, + returnTypes: f.returnTypes, + paramCallers: f.paramCallers, + funcNameCaller: f.funcNameCaller, + returnTypesCallers: f.returnTypesCallers, + typeParameters: typeParameters, } } @@ -159,7 +177,15 @@ func (f *FuncSignature) Generate(indentLevel int) (string, error) { stmt := f.funcName - typeBoundaries := []int{} + if f.typeParameters != nil && len(f.typeParameters) > 0 { + typeParametersStmt, err := f.typeParameters.Generate(indentLevel) + if err != nil { + return "", err + } + stmt += typeParametersStmt + } + + var typeBoundaries []int typeExisted := true typeMissingCaller := "" for i, param := range f.funcParameters { diff --git a/generator/func_signature_doc_test.go b/generator/func_signature_doc_test.go index 9e46e93..36824a3 100644 --- a/generator/func_signature_doc_test.go +++ b/generator/func_signature_doc_test.go @@ -8,10 +8,12 @@ import ( func ExampleFuncSignature_Generate() { generator := NewFuncSignature( "myFunc", - ).AddParameters( - NewFuncParameter("foo", "string"), + ).TypeParameters([]*TypeParameter{ + NewTypeParameter("T", "string"), + }).AddParameters( + NewFuncParameter("foo", "T"), NewFuncParameter("bar", "int"), - ).AddReturnTypes("string", "error") + ).AddReturnTypes("T", "error") generated, err := generator.Generate(0) if err != nil { diff --git a/generator/func_signature_test.go b/generator/func_signature_test.go index 323f1d6..d2f5475 100644 --- a/generator/func_signature_test.go +++ b/generator/func_signature_test.go @@ -72,6 +72,15 @@ func TestShouldGeneratingFuncSignatureBeSuccessful(t *testing.T) { ).AddReturnTypes("string", "error"). Parameters(NewFuncParameter("buz", "error")). ReturnTypes("int64"), + + "myFunc[T string](\n\tfoo T,\n\tbar int,\n) (T, error)": NewFuncSignature( + "myFunc", + ).TypeParameters([]*TypeParameter{ + NewTypeParameter("T", "string"), + }).AddParameters( + NewFuncParameter("foo", "T"), + NewFuncParameter("bar", "int"), + ).AddReturnTypes("T", "error"), } for expected, signature := range dataset { @@ -198,3 +207,16 @@ func TestShouldGeneratingFuncSignatureRaisesUnnamedRetTypeIsAfterNamedRetType(t `^\`+strings.Split(errmsg.UnnamedReturnTypeAppearsAfterNamedReturnTypeError("").Error(), " ")[0], ), err.Error()) } + +func TestShouldGenerateFuncSignatureRaiseErrorWhenInvalidTypeParameterHasGiven(t *testing.T) { + _, err := NewFuncSignature( + "myFunc", + ).TypeParameters([]*TypeParameter{ + NewTypeParameter("T", ""), + }).AddParameters( + NewFuncParameter("foo", "T"), + ).AddReturnTypes("T", "error").Generate(0) + + assert.Error(t, err) + assert.Equal(t, errmsg.TypeParameterTypeIsEmptyErrType, errmsg.IdentifyErrs(err)) +} diff --git a/generator/struct.go b/generator/struct.go index f6e920c..cd1760c 100644 --- a/generator/struct.go +++ b/generator/struct.go @@ -15,10 +15,11 @@ type StructField struct { // Struct represents a code generator for `struct` notation. type Struct struct { - name string - fields []*StructField - nameCaller string - fieldsCallers []string + name string + fields []*StructField + nameCaller string + fieldsCallers []string + typeParameters TypeParameters } // NewStruct returns a new `Struct`. @@ -45,8 +46,20 @@ func (sg *Struct) AddField(name string, typ string, tag ...string) *Struct { typ: typ, tag: t, }), - nameCaller: sg.nameCaller, - fieldsCallers: append(sg.fieldsCallers, fetchClientCallerLine()), + nameCaller: sg.nameCaller, + fieldsCallers: append(sg.fieldsCallers, fetchClientCallerLine()), + typeParameters: sg.typeParameters, + } +} + +// TypeParameters sets the TypeParameters onto the current caller Struct. +func (sg *Struct) TypeParameters(typeParameters TypeParameters) *Struct { + return &Struct{ + name: sg.name, + fields: sg.fields, + nameCaller: sg.nameCaller, + fieldsCallers: sg.fieldsCallers, + typeParameters: typeParameters, } } @@ -57,7 +70,17 @@ func (sg *Struct) Generate(indentLevel int) (string, error) { } indent := BuildIndent(indentLevel) - stmt := fmt.Sprintf("%stype %s struct {\n", indent, sg.name) + + typeParametersStmt := "" + if sg.typeParameters != nil && len(sg.typeParameters) > 0 { + var err error + typeParametersStmt, err = sg.typeParameters.Generate(indentLevel) + if err != nil { + return "", err + } + } + + stmt := fmt.Sprintf("%stype %s%s struct {\n", indent, sg.name, typeParametersStmt) for i, field := range sg.fields { if field.name == "" { diff --git a/generator/struct_doc_test.go b/generator/struct_doc_test.go index 2b677e5..2d8baaa 100644 --- a/generator/struct_doc_test.go +++ b/generator/struct_doc_test.go @@ -8,7 +8,8 @@ import ( func ExampleStruct_Generate() { generator := NewStruct("MyStruct") generator = generator. - AddField("foo", "string"). + TypeParameters(TypeParameters{NewTypeParameter("T", "string")}). + AddField("foo", "T"). AddField("bar", "int64", `custom:"tag"`) generated, err := generator.Generate(0) diff --git a/generator/struct_test.go b/generator/struct_test.go index 2ac4f98..6a31b3d 100644 --- a/generator/struct_test.go +++ b/generator/struct_test.go @@ -41,6 +41,22 @@ func TestShouldGenerateStructStatementBeSucceeded(t *testing.T) { } } +func TestShouldGenerateStructStatementWithTypeParametersSuccessfully(t *testing.T) { + generator := NewStruct("TestStruct") + generator = generator. + TypeParameters(TypeParameters{NewTypeParameter("T", "string")}). + AddField("Foo", "T"). + AddField("Bar", "int64", `json:"bar"`) + + gen, err := generator.Generate(0) + expected := "type TestStruct[T string] struct {\n" + + " Foo T\n" + + " Bar int64 `json:\"bar\"`\n" + + "}\n" + assert.NoError(t, err) + assert.Equal(t, expected, gen) +} + func TestShouldRaiseErrorWhenStructNameIsEmpty(t *testing.T) { structGenerator := NewStruct("") @@ -65,3 +81,13 @@ func TestShouldRaiseErrorWhenFieldTypeIsEmpty(t *testing.T) { `^\`+strings.Split(errmsg.StructFieldTypeIsEmptyErr("").Error(), " ")[0], ), err.Error()) } + +func TestShouldRaiseErrorWhenInvalidTypeParameterHasGiven(t *testing.T) { + generator := NewStruct("TestStruct") + generator = generator. + TypeParameters(TypeParameters{NewTypeParameter("", "string")}). + AddField("Foo", "T") + _, err := generator.Generate(0) + assert.Error(t, err) + assert.Equal(t, errmsg.TypeParameterParameterIsEmptyErrType, errmsg.IdentifyErrs(err)) +} diff --git a/generator/type_parameters.go b/generator/type_parameters.go new file mode 100644 index 0000000..301773f --- /dev/null +++ b/generator/type_parameters.go @@ -0,0 +1,52 @@ +package generator + +import ( + "strings" + + "github.com/moznion/gowrtr/internal/errmsg" +) + +// TypeParameter is a "generic" type parameter. e,g. `T string`; T is a parameter and int is type. +type TypeParameter struct { + parameter string + typ string + caller string +} + +// NewTypeParameter returns a new TypeParameter. +func NewTypeParameter(parameter string, typ string) *TypeParameter { + return &TypeParameter{ + parameter: parameter, + typ: typ, + caller: fetchClientCallerLine(), + } +} + +// TypeParameters is an array of TypeParameter pointers for go generics. +type TypeParameters []*TypeParameter + +// Generate generates the type-parameters as golang code. +func (tps TypeParameters) Generate(indentLevel int) (string, error) { + typeParameterStmts := make([]string, len(tps)) + for i, tp := range tps { + if tp.parameter == "" { + return "", errmsg.TypeParameterParameterIsEmptyErr(tp.caller) + } + + if tp.typ == "" { + return "", errmsg.TypeParameterTypeIsEmptyErr(tp.caller) + } + + typeParameterStmts[i] = tp.parameter + " " + tp.typ + } + + return "[" + strings.Join(typeParameterStmts, ", ") + "]", nil +} + +// TypeArguments is an array of type argument for go generics. +type TypeArguments []string + +// Generate generates the type-arguments as golang code. +func (tas TypeArguments) Generate(indentLevel int) (string, error) { + return "[" + strings.Join(tas, ", ") + "]", nil +} diff --git a/generator/type_parameters_doc_test.go b/generator/type_parameters_doc_test.go new file mode 100644 index 0000000..0ee966c --- /dev/null +++ b/generator/type_parameters_doc_test.go @@ -0,0 +1,15 @@ +package generator + +import ( + "fmt" + "log" +) + +func ExampleTypeArguments_Generate() { + generated, err := TypeArguments{"int", "string"}.Generate(0) + if err != nil { + log.Fatal(err) + } + fmt.Println("// example: f(T, U)") + fmt.Printf("f%s(intVar, strVar)\n", generated) +} diff --git a/generator/type_parameters_test.go b/generator/type_parameters_test.go new file mode 100644 index 0000000..18ec89c --- /dev/null +++ b/generator/type_parameters_test.go @@ -0,0 +1,41 @@ +package generator + +import ( + "testing" + + "github.com/moznion/gowrtr/internal/errmsg" + + "github.com/stretchr/testify/assert" +) + +func TestShouldGenerateTypeParametersSuccessfully(t *testing.T) { + stmt, err := TypeParameters{NewTypeParameter("T", "string")}.Generate(0) + assert.NoError(t, err) + assert.Equal(t, "[T string]", stmt) + + stmt, err = TypeParameters{NewTypeParameter("T", "string"), NewTypeParameter("U", "int")}.Generate(0) + assert.NoError(t, err) + assert.Equal(t, "[T string, U int]", stmt) +} + +func TestShouldFailToGenerateTypeParametersWhenParameterIsEmpty(t *testing.T) { + _, err := TypeParameters{NewTypeParameter("", "string")}.Generate(0) + assert.Error(t, err) + assert.Equal(t, errmsg.TypeParameterParameterIsEmptyErrType, errmsg.IdentifyErrs(err)) +} + +func TestShouldFailToGenerateTypeParametersWhenTypeIsEmpty(t *testing.T) { + _, err := TypeParameters{NewTypeParameter("T", "")}.Generate(0) + assert.Error(t, err) + assert.Equal(t, errmsg.TypeParameterTypeIsEmptyErrType, errmsg.IdentifyErrs(err)) +} + +func TestShouldGenerateTypeArgumentsSuccessfully(t *testing.T) { + stmt, err := TypeArguments{"string"}.Generate(0) + assert.NoError(t, err) + assert.Equal(t, "[string]", stmt) + + stmt, err = TypeArguments{"string", "int"}.Generate(0) + assert.NoError(t, err) + assert.Equal(t, "[string, int]", stmt) +} diff --git a/go.mod b/go.mod index ccdb786..2ee81bb 100644 --- a/go.mod +++ b/go.mod @@ -1,11 +1,18 @@ module github.com/moznion/gowrtr -go 1.14 +go 1.18 require ( - github.com/iancoleman/strcase v0.1.3 // indirect github.com/moznion/go-errgen v1.8.1 github.com/pkg/errors v0.9.1 github.com/stretchr/testify v1.6.0 golang.org/x/lint v0.0.0-20200302205851-738671d3881b ) + +require ( + github.com/davecgh/go-spew v1.1.0 // indirect + github.com/iancoleman/strcase v0.1.3 // indirect + github.com/pmezard/go-difflib v1.0.0 // indirect + golang.org/x/tools v0.0.0-20200130002326-2f3ba24bd6e7 // indirect + gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c // indirect +) diff --git a/go.sum b/go.sum index 61e6049..49361d5 100644 --- a/go.sum +++ b/go.sum @@ -1,6 +1,5 @@ github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= -github.com/iancoleman/strcase v0.0.0-20180726023541-3605ed457bf7 h1:ux/56T2xqZO/3cP1I2F86qpeoYPCOzk+KF/UH/Ar+lk= github.com/iancoleman/strcase v0.0.0-20180726023541-3605ed457bf7/go.mod h1:SK73tn/9oHe+/Y0h39VT4UCxmurVJkR5NA7kMEAOgSE= github.com/iancoleman/strcase v0.1.3 h1:dJBk1m2/qjL1twPLf68JND55vvivMupZ4wIzE8CTdBw= github.com/iancoleman/strcase v0.1.3/go.mod h1:SK73tn/9oHe+/Y0h39VT4UCxmurVJkR5NA7kMEAOgSE= @@ -14,13 +13,11 @@ github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINE github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= -github.com/stretchr/testify v1.3.0 h1:TivCn/peBQ7UY8ooIcPgZFpTNSz0Q2U6UrFlUfqbe0Q= github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= github.com/stretchr/testify v1.6.0 h1:jlIyCplCJFULU/01vCkhKuTyc3OorI3bJFuw6obfgho= github.com/stretchr/testify v1.6.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= -golang.org/x/lint v0.0.0-20181217174547-8f45f776aaf1 h1:rJm0LuqUjoDhSk2zO9ISMSToQxGz7Os2jRiOL8AWu4c= golang.org/x/lint v0.0.0-20181217174547-8f45f776aaf1/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE= golang.org/x/lint v0.0.0-20200302205851-738671d3881b h1:Wh+f8QHJXR411sJR8/vRBTZ7YapZaRvUcLFFJhusH0k= golang.org/x/lint v0.0.0-20200302205851-738671d3881b/go.mod h1:3xt1FjdF8hUf6vQPIChWIBhFzV8gjjsPE/fR3IyQdNY= diff --git a/internal/errmsg/errmsg.go b/internal/errmsg/errmsg.go index c9064d5..5e4c357 100644 --- a/internal/errmsg/errmsg.go +++ b/internal/errmsg/errmsg.go @@ -1,7 +1,7 @@ package errmsg //go:generate errgen -type=errs -prefix=GOWRTR- -type errs struct { +type Errs struct { StructNameIsNilErr error `errmsg:"struct name must not be empty, but it gets empty (caused at %s)" vars:"caller string"` StructFieldNameIsEmptyErr error `errmsg:"field name must not be empty, but it gets empty (caused at %s)" vars:"caller string"` StructFieldTypeIsEmptyErr error `errmsg:"field type must not be empty, but it gets empty (caused at %s)" vars:"caller string"` @@ -19,4 +19,6 @@ type errs struct { IfConditionIsEmptyError error `errmsg:"condition of if must not be empty, but it gets empty (caused at %s)" vars:"caller string"` UnnamedReturnTypeAppearsAfterNamedReturnTypeError error `errmsg:"unnamed return type appears after named return type (caused at %s)" vars:"caller string"` ValueOfCompositeLiteralIsEmptyError error `errmsg:"a value of composite literal must not be empty, but it gets empty (caused at %s)" vars:"caller string"` + TypeParameterParameterIsEmptyErr error `errmsg:"type-parameter's parameter must not be empty, but it gets empty (caused at %s)" vars:"caller string"` + TypeParameterTypeIsEmptyErr error `errmsg:"type-parameter's type must not be empty, but it gets empty (caused at %s)" vars:"caller string"` } diff --git a/internal/errmsg/errs_errmsg_gen.go b/internal/errmsg/errs_errmsg_gen.go index 9b7d831..2818bad 100644 --- a/internal/errmsg/errs_errmsg_gen.go +++ b/internal/errmsg/errs_errmsg_gen.go @@ -180,6 +180,26 @@ func ValueOfCompositeLiteralIsEmptyErrorWrap(caller string, err error) error { return errors.Wrap(err, "[GOWRTR-17] a value of composite literal must not be empty, but it gets empty (caused at %s)") } +// TypeParameterParameterIsEmptyErr returns the error. +func TypeParameterParameterIsEmptyErr(caller string) error { + return fmt.Errorf(`[GOWRTR-18] type-parameter's parameter must not be empty, but it gets empty (caused at %s)`, caller) +} + +// TypeParameterParameterIsEmptyErrWrap wraps the error. +func TypeParameterParameterIsEmptyErrWrap(caller string, err error) error { + return errors.Wrap(err, "[GOWRTR-18] type-parameter's parameter must not be empty, but it gets empty (caused at %s)") +} + +// TypeParameterTypeIsEmptyErr returns the error. +func TypeParameterTypeIsEmptyErr(caller string) error { + return fmt.Errorf(`[GOWRTR-19] type-parameter's type must not be empty, but it gets empty (caused at %s)`, caller) +} + +// TypeParameterTypeIsEmptyErrWrap wraps the error. +func TypeParameterTypeIsEmptyErrWrap(caller string, err error) error { + return errors.Wrap(err, "[GOWRTR-19] type-parameter's type must not be empty, but it gets empty (caused at %s)") +} + // ErrsType represents the error type. type ErrsType int @@ -219,13 +239,17 @@ const ( UnnamedReturnTypeAppearsAfterNamedReturnTypeErrorType // ValueOfCompositeLiteralIsEmptyErrorType represents the error type for ValueOfCompositeLiteralIsEmptyError. ValueOfCompositeLiteralIsEmptyErrorType + // TypeParameterParameterIsEmptyErrType represents the error type for TypeParameterParameterIsEmptyErr. + TypeParameterParameterIsEmptyErrType + // TypeParameterTypeIsEmptyErrType represents the error type for TypeParameterTypeIsEmptyErr. + TypeParameterTypeIsEmptyErrType // ErrsUnknownType represents unknown type for Errs ErrsUnknownType ) // ListErrs returns the list of errors. func ListErrs() []string { - return []string{"[GOWRTR-1] struct name must not be empty, but it gets empty (caused at %s)", "[GOWRTR-2] field name must not be empty, but it gets empty (caused at %s)", "[GOWRTR-3] field type must not be empty, but it gets empty (caused at %s)", "[GOWRTR-4] func parameter name must not be empty, but it gets empty (caused at %s)", "[GOWRTR-5] the last func parameter type must not be empty, but it gets empty (caused at %s)", "[GOWRTR-6] name of func must not be empty, but it gets empty (caused at %s)", "[GOWRTR-7] name of interface must not be empty, but it gets empty (caused at %s)", "[GOWRTR-8] name of func receiver must not be empty, but it gets empty (caused at %s)", "[GOWRTR-9] type of func receiver must not be empty, but it gets empty (caused at %s)", "[GOWRTR-10] func signature must not be nil, bit it gets nil (caused at %s)", "[GOWRTR-11] anonymous func signature must not be nil, bit it gets nil (caused at %s)", "[GOWRTR-12] a parameter of function invocation must not be nil, but it gets nil (caused at %s)", "[GOWRTR-13] code formatter raises error: command='%s', err='%s', msg='%s'", "[GOWRTR-14] condition of case must not be empty, but it gets empty (caused at %s)", "[GOWRTR-15] condition of if must not be empty, but it gets empty (caused at %s)", "[GOWRTR-16] unnamed return type appears after named return type (caused at %s)", "[GOWRTR-17] a value of composite literal must not be empty, but it gets empty (caused at %s)"} + return []string{"[GOWRTR-1] struct name must not be empty, but it gets empty (caused at %s)", "[GOWRTR-2] field name must not be empty, but it gets empty (caused at %s)", "[GOWRTR-3] field type must not be empty, but it gets empty (caused at %s)", "[GOWRTR-4] func parameter name must not be empty, but it gets empty (caused at %s)", "[GOWRTR-5] the last func parameter type must not be empty, but it gets empty (caused at %s)", "[GOWRTR-6] name of func must not be empty, but it gets empty (caused at %s)", "[GOWRTR-7] name of interface must not be empty, but it gets empty (caused at %s)", "[GOWRTR-8] name of func receiver must not be empty, but it gets empty (caused at %s)", "[GOWRTR-9] type of func receiver must not be empty, but it gets empty (caused at %s)", "[GOWRTR-10] func signature must not be nil, bit it gets nil (caused at %s)", "[GOWRTR-11] anonymous func signature must not be nil, bit it gets nil (caused at %s)", "[GOWRTR-12] a parameter of function invocation must not be nil, but it gets nil (caused at %s)", "[GOWRTR-13] code formatter raises error: command='%s', err='%s', msg='%s'", "[GOWRTR-14] condition of case must not be empty, but it gets empty (caused at %s)", "[GOWRTR-15] condition of if must not be empty, but it gets empty (caused at %s)", "[GOWRTR-16] unnamed return type appears after named return type (caused at %s)", "[GOWRTR-17] a value of composite literal must not be empty, but it gets empty (caused at %s)", "[GOWRTR-18] type-parameter's parameter must not be empty, but it gets empty (caused at %s)", "[GOWRTR-19] type-parameter's type must not be empty, but it gets empty (caused at %s)"} } // IdentifyErrs checks the identity of an error @@ -266,6 +290,10 @@ func IdentifyErrs(err error) ErrsType { return UnnamedReturnTypeAppearsAfterNamedReturnTypeErrorType case strings.HasPrefix(errStr, "[GOWRTR-17]"): return ValueOfCompositeLiteralIsEmptyErrorType + case strings.HasPrefix(errStr, "[GOWRTR-18]"): + return TypeParameterParameterIsEmptyErrType + case strings.HasPrefix(errStr, "[GOWRTR-19]"): + return TypeParameterTypeIsEmptyErrType default: return ErrsUnknownType }