Skip to content

Commit

Permalink
lint: fix lint errors in generated models
Browse files Browse the repository at this point in the history
  • Loading branch information
Antoine Mercadal committed Mar 22, 2023
1 parent 837c82a commit 833012e
Show file tree
Hide file tree
Showing 14 changed files with 64 additions and 42 deletions.
3 changes: 0 additions & 3 deletions .codecov.yml

This file was deleted.

1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ lint:
--skip-files data_test.go \
--exclude-use-default=false \
--exclude=package-comments \
--exclude=unused-parameter \
--enable=errcheck \
--enable=goimports \
--enable=ineffassign \
Expand Down
4 changes: 2 additions & 2 deletions cmd/elegen/templates/model.gotpl
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@ func (o {{ .Spec.Model.EntityNamePlural }}List) Identity() elemental.Identity {
// Copy returns a pointer to a copy the {{ .Spec.Model.EntityNamePlural }}List.
func (o {{ .Spec.Model.EntityNamePlural }}List) Copy() elemental.Identifiables {

copy := append({{ .Spec.Model.EntityNamePlural }}List{}, o...)
return &copy
out := append({{ .Spec.Model.EntityNamePlural }}List{}, o...)
return &out
}

// Append appends the objects to the a new copy of the {{ .Spec.Model.EntityNamePlural }}List.
Expand Down
23 changes: 13 additions & 10 deletions data_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
)

//lint:file-ignore U1000 auto generated code.

// ListIdentity represents the Identity of the object.
var ListIdentity = Identity{
Name: "list",
Expand All @@ -29,8 +30,8 @@ func (o ListsList) Identity() Identity {
// Copy returns a pointer to a copy the ListsList.
func (o ListsList) Copy() Identifiables {

copy := append(ListsList{}, o...)
return &copy
out := append(ListsList{}, o...)
return &out
}

// Append appends the objects to the a new copy of the ListsList.
Expand Down Expand Up @@ -1069,6 +1070,7 @@ type mongoAttributesSparseList struct {
Slice *[]string `bson:"slice,omitempty"`
Unexposed *string `bson:"unexposed,omitempty"`
}

// TaskStatusValue represents the possible values for attribute "status".
type TaskStatusValue string

Expand Down Expand Up @@ -1103,8 +1105,8 @@ func (o TasksList) Identity() Identity {
// Copy returns a pointer to a copy the TasksList.
func (o TasksList) Copy() Identifiables {

copy := append(TasksList{}, o...)
return &copy
out := append(TasksList{}, o...)
return &out
}

// Append appends the objects to the a new copy of the TasksList.
Expand Down Expand Up @@ -1888,8 +1890,6 @@ type mongoAttributesSparseTask struct {
ParentType *string `bson:"parenttype,omitempty"`
Status *TaskStatusValue `bson:"status,omitempty"`
}

// UnmarshalableListIdentity represents the Identity of the object.
var UnmarshalableListIdentity = Identity{Name: "list", Category: "lists"}

// UnmarshalableListsList represents a list of UnmarshalableLists
Expand All @@ -1904,8 +1904,8 @@ func (o UnmarshalableListsList) Identity() Identity {
// Copy returns a pointer to a copy the UnmarshalableListsList.
func (o UnmarshalableListsList) Copy() Identifiables {

copy := append(UnmarshalableListsList{}, o...)
return &copy
out := append(UnmarshalableListsList{}, o...)
return &out
}

// Append appends the objects to the a new copy of the UnmarshalableListsList.
Expand Down Expand Up @@ -2004,6 +2004,7 @@ func (o *UnmarshalableError) UnmarshalMsgpack([]byte) error {
func (o *UnmarshalableError) MarshalMsgpack() ([]byte, error) {
return nil, fmt.Errorf("error marshalling")
}

// UserIdentity represents the Identity of the object.
var UserIdentity = Identity{
Name: "user",
Expand All @@ -2024,8 +2025,8 @@ func (o UsersList) Identity() Identity {
// Copy returns a pointer to a copy the UsersList.
func (o UsersList) Copy() Identifiables {

copy := append(UsersList{}, o...)
return &copy
out := append(UsersList{}, o...)
return &out
}

// Append appends the objects to the a new copy of the UsersList.
Expand Down Expand Up @@ -2863,6 +2864,7 @@ type mongoAttributesSparseUser struct {
ParentType *string `bson:"parenttype,omitempty"`
UserName *string `bson:"username,omitempty"`
}

// Root represents the model of a root
type Root struct {
ModelVersion int `json:"-" msgpack:"-" bson:"_modelversion"`
Expand Down Expand Up @@ -3028,6 +3030,7 @@ var RootLowerCaseAttributesMap = map[string]AttributeSpecification{}

type mongoAttributesRoot struct {
}

var (
identityNamesMap = map[string]Identity{
"list": ListIdentity,
Expand Down
16 changes: 8 additions & 8 deletions encoding_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -152,8 +152,8 @@ func TestMakeStreamEncoderDecoder(t *testing.T) {
Convey("Given I have a bunch of json lines and a stream decoder", t, func() {

data := bytes.NewBuffer(nil)
encoder, eclose := MakeStreamEncoder(EncodingTypeJSON, data)
defer eclose()
encoder, closeFunc1 := MakeStreamEncoder(EncodingTypeJSON, data)
defer closeFunc1()

if err := encoder(&List{Name: "1"}); err != nil {
panic(err)
Expand All @@ -162,8 +162,8 @@ func TestMakeStreamEncoderDecoder(t *testing.T) {
panic(err)
}

decoder, close := MakeStreamDecoder(EncodingTypeJSON, data)
defer close()
decoder, closeFunc2 := MakeStreamDecoder(EncodingTypeJSON, data)
defer closeFunc2()

Convey("Decoding once should work", func() {

Expand Down Expand Up @@ -202,8 +202,8 @@ func TestMakeStreamEncoderDecoder(t *testing.T) {
Convey("Given I have a bunch of msgpack lines and a stream decoder", t, func() {

data := bytes.NewBuffer(nil)
encoder, eclose := MakeStreamEncoder(EncodingTypeMSGPACK, data)
defer eclose()
encoder, closeFunc1 := MakeStreamEncoder(EncodingTypeMSGPACK, data)
defer closeFunc1()

if err := encoder(&List{Name: "1"}); err != nil {
panic(err)
Expand All @@ -212,8 +212,8 @@ func TestMakeStreamEncoderDecoder(t *testing.T) {
panic(err)
}

decoder, close := MakeStreamDecoder(EncodingTypeMSGPACK, data)
defer close()
decoder, closeFunc2 := MakeStreamDecoder(EncodingTypeMSGPACK, data)
defer closeFunc2()

Convey("Decoding once should work", func() {

Expand Down
24 changes: 13 additions & 11 deletions test/gen.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/bin/bash

cd "$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" || exit 1
cd "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" || exit 1

elegen folder -d ../../regolithe/spec/tests || exit 1

Expand All @@ -22,13 +22,15 @@ import (
//lint:file-ignore U1000 auto generated code.
EOF
{
tail -n +12 model/list.go;
tail -n +11 model/task.go;
tail -n +19 model/unmarshalable.go;
tail -n +11 model/user.go;
tail -n +19 model/root.go;
tail -n +5 model/identities_registry.go;
tail -n +4 model/relationships_registry.go;
}>> ../data_test.go

sed -i '' 's/elemental\.//g' ../data_test.go
tail -n +14 model/list.go
tail -n +13 model/task.go
tail -n +21 model/unmarshalable.go
tail -n +13 model/user.go
tail -n +21 model/root.go
tail -n +7 model/identities_registry.go
tail -n +7 model/relationships_registry.go
} >>../data_test.go

sed 's/elemental\.//g' ../data_test.go >../data_test.go.new
mv ../data_test.go.new ../data_test.go
rm -f ../data_test.go.new
3 changes: 3 additions & 0 deletions test/model/identities_registry.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 5 additions & 2 deletions test/model/list.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions test/model/relationships_registry.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions test/model/root.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 5 additions & 2 deletions test/model/task.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions test/model/unmarshalable.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ func (o UnmarshalableListsList) Identity() elemental.Identity {
// Copy returns a pointer to a copy the UnmarshalableListsList.
func (o UnmarshalableListsList) Copy() elemental.Identifiables {

copy := append(UnmarshalableListsList{}, o...)
return &copy
out := append(UnmarshalableListsList{}, o...)
return &out
}

// Append appends the objects to the a new copy of the UnmarshalableListsList.
Expand Down
7 changes: 5 additions & 2 deletions test/model/user.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions verify.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ func ResetMaps(v reflect.Value) {

indirect := func(vv reflect.Value) reflect.Value {
for ; vv.Kind() == reflect.Ptr; vv = vv.Elem() {
_ = vv // this makes the linter happy as the loop is not empty
}
return vv
}
Expand Down

0 comments on commit 833012e

Please sign in to comment.