Skip to content

Commit

Permalink
Update deps and CI action
Browse files Browse the repository at this point in the history
  • Loading branch information
tiendc committed Sep 11, 2024
1 parent 0a28963 commit 67c5ada
Show file tree
Hide file tree
Showing 12 changed files with 33 additions and 51 deletions.
3 changes: 0 additions & 3 deletions .codecov.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
codecov:
token: 25dd913a-2bf1-4be3-b13e-c06b079a4438

coverage:
range: 80..100
round: down
Expand Down
12 changes: 7 additions & 5 deletions .github/workflows/go.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Go
name: Tests

on:
push:
Expand All @@ -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:
Expand All @@ -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') }}
Expand All @@ -46,3 +46,5 @@ jobs:

- name: Upload coverage to codecov.io
uses: codecov/codecov-action@v4
with:
token: ${{ secrets.CODECOV_TOKEN }}
31 changes: 7 additions & 24 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
linters-settings:
funlen:
lines: 80
statements: 72
lines: 100
statements: 80
gci:
sections:
- standard
Expand All @@ -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:
Expand All @@ -33,7 +25,7 @@ linters:
- errname
- errorlint
- exhaustive
- exportloopref
- copyloopvar
- forbidigo
- forcetypeassert
- funlen
Expand All @@ -42,10 +34,10 @@ linters:
- goconst
- gocritic
- gocyclo
- goerr113
- err113
- gofmt
- goimports
- gomnd
- mnd
- gosec
- gosimple
- govet
Expand Down Expand Up @@ -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
6 changes: 3 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
@@ -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 ./...
Expand All @@ -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 ./...
Expand Down
4 changes: 2 additions & 2 deletions decode.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
8 changes: 4 additions & 4 deletions decoder.go
Original file line number Diff line number Diff line change
Expand Up @@ -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:]

Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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 {
Expand Down
4 changes: 2 additions & 2 deletions encode.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion encoder.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
6 changes: 3 additions & 3 deletions errors_render_as_csv.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ func defaultCSVRenderConfig() *CSVRenderConfig {
RenderHeader: true,
RenderRowNumberColumnIndex: 0,
RenderLineNumberColumnIndex: 1,
RenderCommonErrorColumnIndex: 2,
RenderCommonErrorColumnIndex: 2, //nolint:mnd

LocalizeCellFields: true,
LocalizeCellHeader: true,
Expand All @@ -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)
}
Expand Down Expand Up @@ -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

Check warning on line 354 in errors_render_as_csv.go

View check run for this annotation

Codecov / codecov/patch

errors_render_as_csv.go#L354

Added line #L354 was not covered by tests
}
row := data[1]
rowSz := 0
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand Down
2 changes: 1 addition & 1 deletion util.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 67c5ada

Please sign in to comment.