From 9bdc720ef078d85afe947ee65e5e00df78feec46 Mon Sep 17 00:00:00 2001 From: tiendc Date: Wed, 11 Sep 2024 17:44:23 +0700 Subject: [PATCH] Update deps and CI action --- .codecov.yml | 3 --- .github/workflows/go.yml | 12 +++++++----- .golangci.yml | 31 +++++++------------------------ Makefile | 6 +++--- decode.go | 4 ++-- decoder.go | 8 ++++---- encode.go | 4 ++-- encoder.go | 2 +- errors_render_as_csv.go | 6 +++--- go.mod | 2 +- go.sum | 4 ++-- util.go | 2 +- 12 files changed, 33 insertions(+), 51 deletions(-) diff --git a/.codecov.yml b/.codecov.yml index 911526f..f355ea5 100644 --- a/.codecov.yml +++ b/.codecov.yml @@ -1,6 +1,3 @@ -codecov: - token: 25dd913a-2bf1-4be3-b13e-c06b079a4438 - coverage: range: 80..100 round: down diff --git a/.github/workflows/go.yml b/.github/workflows/go.yml index fdf2c32..f2f2b51 100644 --- a/.github/workflows/go.yml +++ b/.github/workflows/go.yml @@ -1,4 +1,4 @@ -name: Go +name: Tests on: push: @@ -13,9 +13,9 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - go: ["1.18.x", "1.22.x"] + go: ["1.18.x", "1.22.x", "1.23.x"] include: - - go: 1.22.x + - go: 1.23.x latest: true steps: @@ -25,10 +25,10 @@ jobs: go-version: ${{ matrix.go }} - name: Checkout code - uses: actions/checkout@v4 + uses: actions/checkout@v3 - name: Load cached dependencies - uses: actions/cache@v4 + uses: actions/cache@v3 with: path: ~/go/pkg/mod key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }} @@ -46,3 +46,5 @@ jobs: - name: Upload coverage to codecov.io uses: codecov/codecov-action@v4 + with: + token: ${{ secrets.CODECOV_TOKEN }} diff --git a/.golangci.yml b/.golangci.yml index 6c75b92..21083eb 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -1,7 +1,7 @@ linters-settings: funlen: - lines: 80 - statements: 72 + lines: 100 + statements: 80 gci: sections: - standard @@ -11,14 +11,6 @@ linters-settings: min-complexity: 20 goimports: local-prefixes: github.com/golangci/golangci-lint - gomnd: - settings: - mnd: - checks: # don't include the "operation" and "assign" - - argument - - case - - condition - - return lll: line-length: 120 misspell: @@ -33,7 +25,7 @@ linters: - errname - errorlint - exhaustive - - exportloopref + - copyloopvar - forbidigo - forcetypeassert - funlen @@ -42,10 +34,10 @@ linters: - goconst - gocritic - gocyclo - - goerr113 + - err113 - gofmt - goimports - - gomnd + - mnd - gosec - gosimple - govet @@ -73,18 +65,9 @@ issues: - staticcheck - gocyclo - gocognit - - goerr113 + - err113 - forcetypeassert - wrapcheck - gomnd - errorlint - -run: - skip-dirs: - - scripts - - test-results - -# golangci configuration -# https://github.com/golangci/golangci/wiki/Configuration -service: - golangci-lint-version: 1.50.x + - unused \ No newline at end of file diff --git a/Makefile b/Makefile index d7e5850..b81dafa 100644 --- a/Makefile +++ b/Makefile @@ -1,7 +1,7 @@ all: lint test prepare: - @curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(shell go env GOPATH)/bin v1.54.2 + @curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(shell go env GOPATH)/bin v1.60.3 build: @go build -v ./... @@ -10,8 +10,8 @@ test: @go test -cover -v ./... cover: - @go test -race -coverprofile=cover.out -coverpkg=./... ./... - @go tool cover -html=cover.out -o cover.html + @go test -race -coverprofile=coverage.txt -coverpkg=./... ./... + @go tool cover -html=coverage.txt -o coverage.html lint: golangci-lint --timeout=5m0s run -v ./... diff --git a/decode.go b/decode.go index ea07e41..c49ef9b 100644 --- a/decode.go +++ b/decode.go @@ -16,13 +16,13 @@ func getDecodeFunc(typ reflect.Type) (DecodeFunc, error) { if typ.Implements(csvUnmarshaler) { return decodeCSVUnmarshaler, nil } - if reflect.PtrTo(typ).Implements(csvUnmarshaler) { + if reflect.PointerTo(typ).Implements(csvUnmarshaler) { return decodePtrCSVUnmarshaler, nil } if typ.Implements(textUnmarshaler) { return decodeTextUnmarshaler, nil } - if reflect.PtrTo(typ).Implements(textUnmarshaler) { + if reflect.PointerTo(typ).Implements(textUnmarshaler) { return decodePtrTextUnmarshaler, nil } return getDecodeFuncBaseType(typ) diff --git a/decoder.go b/decoder.go index 8d06fea..6b4407a 100644 --- a/decoder.go +++ b/decoder.go @@ -195,7 +195,7 @@ func (d *Decoder) Decode(v any) (*DecodeResult, error) { for !d.shouldStop && len(d.rowsData) > 0 { // Reduce memory consumption by splitting the source data into chunks (10000 items each) // After each chunk is processed, resize the slice to allow Go to free the memory when necessary - chunkSz := gofn.Min(10000, len(d.rowsData)) // nolint: gomnd + chunkSz := gofn.Min(10000, len(d.rowsData)) //nolint:mnd chunk := d.rowsData[0:chunkSz] d.rowsData = d.rowsData[chunkSz:] @@ -470,7 +470,7 @@ func (d *Decoder) readRowData() error { ableToGetLine = false getLine = nil } - rowDataItems := make([]*rowData, 0, 10000) // nolint: gomnd + rowDataItems := make([]*rowData, 0, 10000) //nolint:mnd for ; ; row++ { records, err := r.Read() @@ -590,7 +590,7 @@ func (d *Decoder) validateColumnsMeta(colsMeta, colsMetaFromStruct []*decodeColu cfg := d.cfg // Make sure all column options valid for colKey := range cfg.columnConfigMap { - if !gofn.ContainPred(colsMetaFromStruct, func(colMeta *decodeColumnMeta) bool { + if !gofn.ContainBy(colsMetaFromStruct, func(colMeta *decodeColumnMeta) bool { return colMeta.headerKey == colKey || colMeta.parentKey == colKey }) { return fmt.Errorf("%w: column \"%s\" not found", ErrConfigOptionInvalid, colKey) @@ -789,7 +789,7 @@ func (d *Decoder) parseInlineColumnDynamicType(typ reflect.Type, parent *decodeC func (d *Decoder) parseDynamicInlineColumns(colsMetaFromStruct []*decodeColumnMeta, fileHeader []string) ( []*decodeColumnMeta, error) { - newColsMetaFromStruct := make([]*decodeColumnMeta, 0, len(colsMetaFromStruct)*2) // nolint: gomnd + newColsMetaFromStruct := make([]*decodeColumnMeta, 0, len(colsMetaFromStruct)*2) //nolint:mnd fileHeaderIndex := 0 for i, colMetaFromStruct := range colsMetaFromStruct { if colMetaFromStruct.inlineColumnMeta == nil { diff --git a/encode.go b/encode.go index be7dc92..199dd2c 100644 --- a/encode.go +++ b/encode.go @@ -16,13 +16,13 @@ func getEncodeFunc(typ reflect.Type) (EncodeFunc, error) { if typ.Implements(csvMarshaler) { return encodeCSVMarshaler, nil } - if reflect.PtrTo(typ).Implements(csvMarshaler) { + if reflect.PointerTo(typ).Implements(csvMarshaler) { return encodePtrCSVMarshaler, nil } if typ.Implements(textMarshaler) { return encodeTextMarshaler, nil } - if reflect.PtrTo(typ).Implements(textMarshaler) { + if reflect.PointerTo(typ).Implements(textMarshaler) { return encodePtrTextMarshaler, nil } return getEncodeFuncBaseType(typ) diff --git a/encoder.go b/encoder.go index 8c397e4..06c580f 100644 --- a/encoder.go +++ b/encoder.go @@ -304,7 +304,7 @@ func (e *Encoder) validateColumnsMeta(colsMeta []*encodeColumnMeta) error { cfg := e.cfg // Make sure all column options valid for colKey := range cfg.columnConfigMap { - if !gofn.ContainPred(colsMeta, func(colMeta *encodeColumnMeta) bool { + if !gofn.ContainBy(colsMeta, func(colMeta *encodeColumnMeta) bool { return colMeta.headerKey == colKey || colMeta.parentKey == colKey }) { return fmt.Errorf("%w: column \"%s\" not found", ErrConfigOptionInvalid, colKey) diff --git a/errors_render_as_csv.go b/errors_render_as_csv.go index b99c19d..092f8f1 100644 --- a/errors_render_as_csv.go +++ b/errors_render_as_csv.go @@ -71,7 +71,7 @@ func defaultCSVRenderConfig() *CSVRenderConfig { RenderHeader: true, RenderRowNumberColumnIndex: 0, RenderLineNumberColumnIndex: 1, - RenderCommonErrorColumnIndex: 2, + RenderCommonErrorColumnIndex: 2, //nolint:mnd LocalizeCellFields: true, LocalizeCellHeader: true, @@ -96,7 +96,7 @@ func NewCSVRenderer(err *Errors, options ...func(*CSVRenderConfig)) (*CSVRendere opt(cfg) } // Validate/Correct the base columns to render - baseColumns := make([]*int, 0, 3) // nolint: gomnd + baseColumns := make([]*int, 0, 3) //nolint:mnd if cfg.RenderRowNumberColumnIndex >= 0 { baseColumns = append(baseColumns, &cfg.RenderRowNumberColumnIndex) } @@ -351,7 +351,7 @@ func (r *CSVRenderer) localizeKeySkipError(key string, params ParameterMap) stri func (r *CSVRenderer) estimateCSVBuffer(data [][]string) int { if len(data) <= 1 { - return 512 // nolint: gomnd + return 512 //nolint:mnd } row := data[1] rowSz := 0 diff --git a/go.mod b/go.mod index 66d2e3b..9aa7475 100644 --- a/go.mod +++ b/go.mod @@ -5,7 +5,7 @@ go 1.18 require ( github.com/hashicorp/go-multierror v1.1.1 github.com/stretchr/testify v1.9.0 - github.com/tiendc/gofn v1.8.0 + github.com/tiendc/gofn v1.11.0 ) require ( diff --git a/go.sum b/go.sum index 997229f..0d8b460 100644 --- a/go.sum +++ b/go.sum @@ -11,8 +11,8 @@ github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsT github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY= github.com/tiendc/go-rflutil v0.0.0-20231112145832-693b7b74d697 h1:BYWZUvxBkpnlC4MywWhO1bEch5L6cCc0t5FNVSUjZps= github.com/tiendc/go-rflutil v0.0.0-20231112145832-693b7b74d697/go.mod h1:nSMBac9C+G4b8nvxSgPZ0rmhrLonJ5ZdknynSKxQhL8= -github.com/tiendc/gofn v1.8.0 h1:ivD6twigyA3lpXnkC2cVgN2LWUmyisSV6MmYf1f3fUQ= -github.com/tiendc/gofn v1.8.0/go.mod h1:uevHlES37QrasSvoZxBUcooejk7QfvBCfrJ809b+giA= +github.com/tiendc/gofn v1.11.0 h1:rjXJ2tZ6L96ICwBkbVv0ubDOvrGRo1QMXhhq90xZTBw= +github.com/tiendc/gofn v1.11.0/go.mod h1:uevHlES37QrasSvoZxBUcooejk7QfvBCfrJ809b+giA= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= diff --git a/util.go b/util.go index f28f310..dbd7170 100644 --- a/util.go +++ b/util.go @@ -32,7 +32,7 @@ func processTemplate(templ string, params ParameterMap) (detail string, retErr e return } - buf := bytes.NewBuffer(make([]byte, 0, 100)) // nolint: gomnd + buf := bytes.NewBuffer(make([]byte, 0, 100)) //nolint:mnd err = t.Execute(buf, params) if err != nil { retErr = multierror.Append(retErr, err)