From b7693d36755be53f3e84b2be0f1714953c00a673 Mon Sep 17 00:00:00 2001 From: Simon Sawert Date: Sun, 1 Oct 2023 22:44:39 +0200 Subject: [PATCH] Fix typos, add `golanci-lint` check and CI step --- .github/workflows/go.yaml | 6 +++ .golangci.yaml | 100 ++++++++++++++++++++++++++++++++++++++ README.md | 7 +-- hints.go | 5 +- inferred_number.go | 3 +- inferred_schema.go | 1 + inferrer.go | 2 +- 7 files changed, 117 insertions(+), 7 deletions(-) create mode 100644 .golangci.yaml diff --git a/.github/workflows/go.yaml b/.github/workflows/go.yaml index 17dfc1b..b0beda5 100644 --- a/.github/workflows/go.yaml +++ b/.github/workflows/go.yaml @@ -20,3 +20,9 @@ jobs: - name: Test run: go test -v ./ -race + + lint: + runs-on: ubuntu-latest + steps: + - name: "Run golangci-lint" + uses: golangci/golangci-lint-action@v3 diff --git a/.golangci.yaml b/.golangci.yaml new file mode 100644 index 0000000..71b0083 --- /dev/null +++ b/.golangci.yaml @@ -0,0 +1,100 @@ +--- +run: + deadline: 1m + issues-exit-code: 1 + tests: true + +output: + format: colored-line-number + print-issued-lines: false + +linters-settings: + misspell: + locale: US + +issues: + exclude-use-default: false + max-issues-per-linter: 0 + max-same-issues: 0 + exclude-rules: + - linters: revive + text: "^package-comments:" + +linters: + disable-all: true + enable: + - asasalint + - asciicheck + - bidichk + - containedctx + - contextcheck + - decorder + - dupl + - dupword + - durationcheck + - errcheck + - errchkjson + - errname + - errorlint + - exhaustive + - exportloopref + - forbidigo + - forcetypeassert + - gochecknoglobals + - gochecknoinits + - goconst + - gocritic + - godot + - godox + - goerr113 + - gofmt + - gofumpt + - goimports + - gomnd + - gomoddirectives + - gomodguard + - goprintffuncname + - gosec + - gosimple + - gosmopolitan + - govet + - grouper + - importas + - ineffassign + - interfacebloat + - ireturn + - lll + - loggercheck + - makezero + - mirror + - misspell + - musttag + - nakedret + - nilerr + - nilnil + - noctx + - nolintlint + - nonamedreturns + - nosprintfhostport + - prealloc + - predeclared + - promlinter + - reassign + - revive + - rowserrcheck + - sqlclosecheck + - staticcheck + - tagalign + - tagliatelle + - tenv + - testableexamples + - thelper + - typecheck + - unconvert + - unparam + - unused + - usestdlibvars + - wastedassign + - whitespace + - wrapcheck + - wsl diff --git a/README.md b/README.md index 557c98a..4f1a19c 100644 --- a/README.md +++ b/README.md @@ -3,11 +3,12 @@ [![Go Reference](https://pkg.go.dev/badge/github.com/bombsimon/jtd-infer-go.svg)](https://pkg.go.dev/github.com/bombsimon/jtd-infer-go) [![Build and test](https://github.com/bombsimon/jtd-infer-go/actions/workflows/go.yaml/badge.svg)](https://github.com/bombsimon/jtd-infer-go/actions/workflows/go.yaml) -This is a port of [`json-typedef-infer`][jtd-infer] Go. The reason for porting -this is that I was in need of JTD inference from code and not as a CLI tool. +This is a port of [`json-typedef-infer`][jtd-infer] for Go. The reason for +porting this is that I was in need of JTD inference from code and not as a CLI +tool. For more information about JSON Typedef and its RFC and how to use different -kind of hints see [`json-typedef-infer`][jtd-infer] +kind of hints see [`json-typedef-infer`][jtd-infer]. ## Usage diff --git a/hints.go b/hints.go index 40f98b4..b5d00c5 100644 --- a/hints.go +++ b/hints.go @@ -12,11 +12,12 @@ type Hints struct { Discriminator HintSet } +// WithoutHints is a shorthand to return empty hints. func WithoutHints() Hints { return Hints{} } -// SubHint will return the sub hints for all hint sets for the passed key. +// SubHints will return the sub hints for all hint sets for the passed key. func (h Hints) SubHints(key string) Hints { return Hints{ DefaultNumType: h.DefaultNumType, @@ -60,7 +61,7 @@ func (h HintSet) Add(v []string) HintSet { return h } -// SubHint will filter all the current sets and keep those who's first element +// SubHints will filter all the current sets and keep those who's first element // matches the passed key or wildcard. func (h HintSet) SubHints(key string) HintSet { filteredValues := [][]string{} diff --git a/inferred_number.go b/inferred_number.go index 37a2707..c408641 100644 --- a/inferred_number.go +++ b/inferred_number.go @@ -10,6 +10,7 @@ import ( // JTD. type NumType uint8 +// Available number types. const ( NumTypeUint8 NumType = iota NumTypeInt8 @@ -97,7 +98,7 @@ func (i *InferredNumber) Infer(n float64) *InferredNumber { } } -// InfoType will convert an `InferredNumber` to a `jtd.Type`. +// IntoType will convert an `InferredNumber` to a `jtd.Type`. func (i *InferredNumber) IntoType(defaultType NumType) jtd.Type { if i.ContainedBy(defaultType) { return defaultType.IntoType() diff --git a/inferred_schema.go b/inferred_schema.go index aa9d6bb..857b848 100644 --- a/inferred_schema.go +++ b/inferred_schema.go @@ -13,6 +13,7 @@ import ( // available types for JTD. type SchemaType int8 +// Available schema types. const ( SchemaTypeUnknown SchemaType = iota SchemaTypeAny diff --git a/inferrer.go b/inferrer.go index 20e98f7..2290d3f 100644 --- a/inferrer.go +++ b/inferrer.go @@ -11,7 +11,7 @@ type Inferrer struct { Hints Hints } -// NewInferred will create a new inferrer with a default `InferredSchema`. +// NewInferrer will create a new inferrer with a default `InferredSchema`. func NewInferrer(hints Hints) *Inferrer { return &Inferrer{ Inference: NewInferredSchema(),