diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml new file mode 100644 index 0000000..0a950bd --- /dev/null +++ b/.github/workflows/main.yml @@ -0,0 +1,23 @@ +name: main +on: + pull_request: + push: + branches: + - master + tags: + - v* +jobs: + test: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 + - uses: actions/setup-go@93397bea11091df50f3d7e59dc26a7711a8bcfbe + - run: go test ./... + lint: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 + - uses: actions/setup-go@93397bea11091df50f3d7e59dc26a7711a8bcfbe + - uses: golangci/golangci-lint-action@3a919529898de77ec3da873e3063ca4b10e7f5cc + with: + version: v1.55.2 diff --git a/.golangci.yml b/.golangci.yml new file mode 100644 index 0000000..b996a3e --- /dev/null +++ b/.golangci.yml @@ -0,0 +1,140 @@ +linters: + enable: + - asasalint + - asciicheck + - bidichk + - bodyclose + - containedctx + - contextcheck + - decorder + - dogsled + - dupl + - dupword + - durationcheck + - errcheck + - errchkjson + - errname + - errorlint + - execinquery + - exhaustive + - exportloopref + - forbidigo + - forcetypeassert + - gci + - ginkgolinter + - gocheckcompilerdirectives + - gochecknoinits + - gochecksumtype + - gocognit + - goconst + - gocritic + - gocyclo + - godot + - goerr113 + - gofmt + - gofumpt + - goheader + - goimports + - gomoddirectives + - gomodguard + - goprintffuncname + - gosec + - gosimple + - gosmopolitan + - govet + - grouper + - importas + - inamedparam + - ineffassign + - interfacebloat + - ireturn + - lll + - loggercheck + - makezero + - mirror + - misspell + - musttag + - nakedret + - nestif + - nilerr + - nilnil + - noctx + - nolintlint + - nonamedreturns + - nosprintfhostport + - perfsprint + - prealloc + - predeclared + - promlinter + - protogetter + - reassign + - revive + - rowserrcheck + - sloglint + - sqlclosecheck + - staticcheck + - stylecheck + - tagalign + - tagliatelle + - tenv + - testableexamples + - testifylint + - thelper + - tparallel + - typecheck + - unconvert + - unparam + - unused + - usestdlibvars + - wastedassign + - whitespace + disable: + - cyclop + - depguard + - exhaustruct + - funlen + - gochecknoglobals + - godox + - gomnd + - maintidx + - nlreturn + - paralleltest + - testpackage + - varnamelen + - wrapcheck + - wsl + +linters-settings: + gci: + sections: + - standard + - default + - prefix(github.com/chezmoi/templatefuncs) + gofumpt: + extra-rules: true + goimports: + local-prefixes: github.com/chezmoi/templatefuncs + govet: + disable: + - fieldalignment + - shadow + enable-all: true + misspell: + locale: US + stylecheck: + checks: + - all + +issues: + exclude-rules: + - linters: + - dupl + - scopelint + path: "_test\\.go" + - linters: + - forbidigo + - gosec + path: "internal/" + - linters: + - goerr113 + text: do not define dynamic errors, use wrapped static errors instead diff --git a/go.mod b/go.mod index d395147..a0c7eba 100644 --- a/go.mod +++ b/go.mod @@ -2,10 +2,9 @@ module github.com/chezmoi/templatefuncs go 1.19 -require github.com/stretchr/testify v1.8.1 +require github.com/alecthomas/assert/v2 v2.4.0 require ( - github.com/davecgh/go-spew v1.1.1 // indirect - github.com/pmezard/go-difflib v1.0.0 // indirect - gopkg.in/yaml.v3 v3.0.1 // indirect + github.com/alecthomas/repr v0.3.0 // indirect + github.com/hexops/gotextdiff v1.0.3 // indirect ) diff --git a/go.sum b/go.sum index 2ec90f7..bb218ed 100644 --- a/go.sum +++ b/go.sum @@ -1,17 +1,6 @@ -github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= -github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= -github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= -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/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw= -github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo= -github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= -github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU= -github.com/stretchr/testify v1.8.1 h1:w7B6lhMri9wdJUVmEZPGGhZzrYTPvgJArz7wNPgYKsk= -github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4= -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.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= -gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= -gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= +github.com/alecthomas/assert/v2 v2.4.0 h1:/ZiZ0NnriAWPYYO+4eOjgzNELrFQLaHNr92mHSHFj9U= +github.com/alecthomas/assert/v2 v2.4.0/go.mod h1:fw5suVxB+wfYJ3291t0hRTqtGzFYdSwstnRQdaQx2DM= +github.com/alecthomas/repr v0.3.0 h1:NeYzUPfjjlqHY4KtzgKJiWd6sVq2eNUPTi34PiFGjY8= +github.com/alecthomas/repr v0.3.0/go.mod h1:Fr0507jx4eOXV7AlPV6AVZLYrLIuIeSOWtW57eE/O/4= +github.com/hexops/gotextdiff v1.0.3 h1:gitA9+qJrrTCsiCl7+kh75nPqQt1cx4ZkudSTLoUqJM= +github.com/hexops/gotextdiff v1.0.3/go.mod h1:pSWU5MAI3yDq+fZBTazCSJysOMbxWL1BSow5/V2vxeg= diff --git a/templatefuncs.go b/templatefuncs.go index b13f29e..f0fec16 100644 --- a/templatefuncs.go +++ b/templatefuncs.go @@ -166,7 +166,7 @@ func toStringTemplateFunc(arg any) string { case float32: return strconv.FormatFloat(float64(arg), 'f', -1, 32) case float64: - return strconv.FormatFloat(float64(arg), 'f', -1, 64) + return strconv.FormatFloat(arg, 'f', -1, 64) case int: return strconv.Itoa(arg) case int32: diff --git a/templatefuncs_test.go b/templatefuncs_test.go index ff77d8c..72029dd 100644 --- a/templatefuncs_test.go +++ b/templatefuncs_test.go @@ -6,8 +6,7 @@ import ( "testing" "text/template" - "github.com/stretchr/testify/assert" - "github.com/stretchr/testify/require" + "github.com/alecthomas/assert/v2" ) func TestEachString(t *testing.T) { @@ -138,11 +137,11 @@ func TestFuncMap(t *testing.T) { } { t.Run(strconv.Itoa(i), func(t *testing.T) { tmpl, err := template.New("").Funcs(funcMap).Parse(tc.template) - require.NoError(t, err) - require.NotNil(t, tmpl) + assert.NoError(t, err) + assert.NotZero(t, tmpl) var actual strings.Builder - require.NoError(t, tmpl.Execute(&actual, tc.data)) + assert.NoError(t, tmpl.Execute(&actual, tc.data)) assert.Equal(t, tc.expected, actual.String()) }) }