Skip to content

Commit

Permalink
fix lint
Browse files Browse the repository at this point in the history
  • Loading branch information
vincentysc committed Dec 1, 2024
1 parent 4d43ac5 commit b776ec2
Show file tree
Hide file tree
Showing 11 changed files with 30 additions and 28 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/golangci-lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ jobs:
uses: golangci/golangci-lint-action@v3
with:
# Optional: version of golangci-lint to use in form of v1.2 or v1.2.3 or `latest` to use the latest version
version: v1.62.0
version: v1.49

# Optional: working directory, useful for monorepos
# working-directory: somedir
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
.PHONY: has_docker has_docker_compose lint build_ginkgo_image test test_watch ginkgo

GOLANGCI_LINT_VERSION := "v1.62.0"
GOLANGCI_LINT_VERSION := "v1.49"

# Use lazy assignment(`=`) such that command existence are evaluated when used
GO = $(shell command -v go)
Expand Down
4 changes: 2 additions & 2 deletions external/json/numeric_string.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,11 @@ func NewNumericStringFromBigInt(v *big.Int) *NumericString {
return &NumericString{v: v.String()}
}

func (u *NumericString) String() string {
func (u NumericString) String() string {
return u.v
}

func (u *NumericString) MarshalJSON() ([]byte, error) {
func (u NumericString) MarshalJSON() ([]byte, error) {
return []byte(fmt.Sprintf("\"%s\"", u.String())), nil
}

Expand Down
6 changes: 3 additions & 3 deletions external/json/uint16.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,15 @@ func NewUint16(v uint16) Uint16 {
return Uint16{v: v}
}

func (u *Uint16) Uint16() uint16 {
func (u Uint16) Uint16() uint16 {
return u.v
}

func (u *Uint16) String() string {
func (u Uint16) String() string {
return strconv.Itoa(int(u.v))
}

func (u *Uint16) MarshalJSON() ([]byte, error) {
func (u Uint16) MarshalJSON() ([]byte, error) {
// uint16 number can be handled by all languages as number
return []byte(u.String()), nil
}
Expand Down
7 changes: 3 additions & 4 deletions external/json/uint16_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,7 @@ var _ = Describe("Uint16", func() {

It("should encode to the number representation", func() {
v := json.NewUint16(65535)

actual, err := v.MarshalJSON()
actual, err := jsoniter.Marshal(v)

Expect(err).To(BeNil())
Expect(actual).To(Equal([]byte("65535")))
Expand Down Expand Up @@ -84,10 +83,10 @@ var _ = Describe("Uint16", func() {

It("should be able to encode and decode to/from json", func() {
expected := json.NewUint16(65535)
encoded, _ := expected.MarshalJSON()
encoded, _ := jsoniter.Marshal(expected)

var actual json.Uint16
err := actual.UnmarshalJSON(encoded)
err := jsoniter.Unmarshal(encoded, &actual)

Expect(err).To(BeNil())
Expect(actual.String()).To(Equal(expected.String()))
Expand Down
6 changes: 3 additions & 3 deletions external/json/uint32.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,15 @@ func NewUint32(v uint32) Uint32 {
return Uint32{v: v}
}

func (u *Uint32) Uint32() uint32 {
func (u Uint32) Uint32() uint32 {
return u.v
}

func (u *Uint32) String() string {
func (u Uint32) String() string {
return strconv.Itoa(int(u.v))
}

func (u *Uint32) MarshalJSON() ([]byte, error) {
func (u Uint32) MarshalJSON() ([]byte, error) {
return []byte(u.String()), nil
}

Expand Down
6 changes: 3 additions & 3 deletions external/json/uint32_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ var _ = Describe("Uint32", func() {

It("should encode to the number representation", func() {
v := json.NewUint32(65535)
actual, err := v.MarshalJSON()
actual, err := jsoniter.Marshal(v)

Expect(err).To(BeNil())
Expect(actual).To(Equal([]byte("65535")))
Expand Down Expand Up @@ -83,10 +83,10 @@ var _ = Describe("Uint32", func() {

It("should be able to encode and decode to/from json", func() {
expected := json.NewUint32(65535)
encoded, _ := expected.MarshalJSON()
encoded, _ := jsoniter.Marshal(expected)

var actual json.Uint32
err := actual.UnmarshalJSON(encoded)
err := jsoniter.Unmarshal(encoded, &actual)

Expect(err).To(BeNil())
Expect(actual.String()).To(Equal(expected.String()))
Expand Down
6 changes: 3 additions & 3 deletions external/json/uint64.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,15 @@ func NewUint64FromString(v string) (*Uint64, error) {
return &Uint64{v: typedVal}, nil
}

func (u *Uint64) Uint64() uint64 {
func (u Uint64) Uint64() uint64 {
return u.v
}

func (u *Uint64) String() string {
func (u Uint64) String() string {
return strconv.FormatUint(u.v, 10)
}

func (u *Uint64) MarshalJSON() ([]byte, error) {
func (u Uint64) MarshalJSON() ([]byte, error) {
return []byte(fmt.Sprintf("\"%s\"", u.String())), nil
}

Expand Down
6 changes: 3 additions & 3 deletions external/json/uint64_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ var _ = Describe("Uint64", func() {

It("should encode to the string representation", func() {
v := json.NewUint64(18446744073709551615)
actual, err := v.MarshalJSON()
actual, err := jsoniter.Marshal(v)

Expect(err).To(BeNil())
Expect(actual).To(Equal([]byte("\"18446744073709551615\"")))
Expand Down Expand Up @@ -83,10 +83,10 @@ var _ = Describe("Uint64", func() {

It("should be able to encode and decode to/from json", func() {
expected := json.NewUint64(18446744073709551615)
encoded, _ := expected.MarshalJSON()
encoded, _ := jsoniter.Marshal(expected)

var actual json.Uint64
err := actual.UnmarshalJSON(encoded)
err := jsoniter.Unmarshal(encoded, &actual)

Expect(err).To(BeNil())
Expect(actual.String()).To(Equal(expected.String()))
Expand Down
7 changes: 4 additions & 3 deletions external/utctime/utctime.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,13 +128,14 @@ func (t UTCTime) MarshalJSON() ([]byte, error) {
return result, nil
}

func UnmarshalJSON(data []byte) (gotime.Time, error) {
func (t *UTCTime) UnmarshalJSON(data []byte) error {
var timeVal gotime.Time
if err := jsoniter.Unmarshal(data, &timeVal); err != nil {
return gotime.Time{}, err
return err
}
t.unixNano = timeVal.UTC().UnixNano()

return timeVal.UTC(), nil
return nil
}

// A Month specifies a month of the year (January = 1, ...).
Expand Down
6 changes: 4 additions & 2 deletions external/utctime/utctime_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ var _ = Describe("UTCTime", func() {
var err error
t, _ := jsoniter.Marshal(time.Unix(0, 1000000).UTC())

actual, err := utctime.UnmarshalJSON(t)
var actual utctime.UTCTime
err = jsoniter.Unmarshal(t, &actual)
Expect(err).To(BeNil())
Expect(actual.UnixNano()).To(Equal(int64(1000000)))
})
Expand All @@ -41,7 +42,8 @@ var _ = Describe("UTCTime", func() {
expected := utctime.FromUnixNano(1000000)
encoded, _ := jsoniter.Marshal(expected)

actual, err := utctime.UnmarshalJSON(encoded)
var actual utctime.UTCTime
err := jsoniter.Unmarshal(encoded, &actual)

Expect(err).To(BeNil())
Expect(actual.UnixNano()).To(Equal(expected.UnixNano()))
Expand Down

0 comments on commit b776ec2

Please sign in to comment.