From ed817e0b2c7064a79035679e8936e689b49c3c34 Mon Sep 17 00:00:00 2001 From: Sam Lown Date: Wed, 6 Sep 2023 15:06:11 +0000 Subject: [PATCH] Fixing linting strategy --- .golangci.yml | 71 ++++++++++++++++--------------------------------- reflect.go | 17 ++++++------ reflect_test.go | 6 ++--- 3 files changed, 34 insertions(+), 60 deletions(-) diff --git a/.golangci.yml b/.golangci.yml index f1922d8..905f122 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -11,50 +11,26 @@ output: print-issued-lines: false linters: - enable-all: true - disable: - - maligned - - megacheck - - lll - - typecheck # `go build` catches this, and it doesn't currently work with Go 1.11 modules - - goimports # horrendously slow with go modules :( - - dupl # has never been actually useful - - gochecknoglobals - - gochecknoinits - - interfacer # author deprecated it because it provides bad suggestions - - funlen - - whitespace - - godox - - wsl - - dogsled - - gomnd - - gocognit + enable: - gocyclo - - scopelint - - godot - - nestif - - testpackage - - goerr113 - - gci - - gofumpt - - exhaustivestruct - - nlreturn - - forbidigo - - cyclop - - paralleltest - - ifshort # so annoying - - golint - - tagliatelle - - forcetypeassert - - wrapcheck + - gocritic + - goconst + - dupl + - unconvert + - goimports + - unused + - vetshadow + - nakedret + - errcheck - revive - - structcheck - - stylecheck - - exhaustive - - varnamelen + - ineffassign + - goconst + - vet + - unparam + - gofmt linters-settings: - govet: + vet: check-shadowing: true use-installed-packages: true dupl: @@ -68,22 +44,21 @@ linters-settings: disabled-checks: - ifElseChain - issues: max-per-linter: 0 max-same: 0 exclude-use-default: false exclude: # Captured by errcheck. - - '^(G104|G204):' + - "^(G104|G204):" # Very commonly not checked. - 'Error return value of .(.*\.Help|.*\.MarkFlagRequired|(os\.)?std(out|err)\..*|.*Close|.*Flush|os\.Remove(All)?|.*Print(f|ln|)|os\.(Un)?Setenv). is not checked' # Weird error only seen on Kochiku... - - 'internal error: no range for' + - "internal error: no range for" - 'exported method `.*\.(MarshalJSON|UnmarshalJSON|URN|Payload|GoString|Close|Provides|Requires|ExcludeFromHash|MarshalText|UnmarshalText|Description|Check|Poll|Severity)` should have comment or be unexported' - - 'composite literal uses unkeyed fields' + - "composite literal uses unkeyed fields" - 'declaration of "err" shadows declaration' - - 'by other packages, and that stutters' - - 'Potential file inclusion via variable' - - 'at least one file in a package should have a package comment' - - 'bad syntax for struct tag pair' + - "by other packages, and that stutters" + - "Potential file inclusion via variable" + - "at least one file in a package should have a package comment" + - "bad syntax for struct tag pair" diff --git a/reflect.go b/reflect.go index 19b82c9..4ee0b33 100644 --- a/reflect.go +++ b/reflect.go @@ -676,7 +676,7 @@ func (t *Schema) structKeywordsFromTags(f reflect.StructField, parent *Schema, p } // read struct tags for generic keyworks -func (t *Schema) genericKeywords(tags []string, parent *Schema, propertyName string) { +func (t *Schema) genericKeywords(tags []string, parent *Schema, propertyName string) { //nolint:gocyclo for _, tag := range tags { nameValue := strings.Split(tag, "=") if len(nameValue) == 2 { @@ -795,7 +795,6 @@ func (t *Schema) stringKeywords(tags []string) { switch val { case "date-time", "email", "hostname", "ipv4", "ipv6", "uri", "uuid": t.Format = val - break } case "readOnly": i, _ := strconv.ParseBool(val) @@ -1045,29 +1044,29 @@ func (t *Schema) UnmarshalJSON(data []byte) error { *t = *FalseSchema return nil } - type Schema_ Schema + type SchemaAlt Schema aux := &struct { - *Schema_ + *SchemaAlt }{ - Schema_: (*Schema_)(t), + SchemaAlt: (*SchemaAlt)(t), } return json.Unmarshal(data, aux) } +// MarshalJSON is used to serialize a schema object or boolean. func (t *Schema) MarshalJSON() ([]byte, error) { if t.boolean != nil { if *t.boolean { return []byte("true"), nil - } else { - return []byte("false"), nil } + return []byte("false"), nil } if reflect.DeepEqual(&Schema{}, t) { // Don't bother returning empty schemas return []byte("true"), nil } - type Schema_ Schema - b, err := json.Marshal((*Schema_)(t)) + type SchemaAlt Schema + b, err := json.Marshal((*SchemaAlt)(t)) if err != nil { return nil, err } diff --git a/reflect_test.go b/reflect_test.go index adceff9..804e9fa 100644 --- a/reflect_test.go +++ b/reflect_test.go @@ -34,13 +34,13 @@ type SomeBaseType struct { // The jsonschema required tag is nonsensical for private and ignored properties. // Their presence here tests that the fields *will not* be required in the output // schema, even if they are tagged required. - somePrivateBaseProperty string `jsonschema:"required"` + somePrivateBaseProperty string `jsonschema:"required"` //nolint:unused SomeIgnoredBaseProperty string `json:"-" jsonschema:"required"` SomeSchemaIgnoredProperty string `jsonschema:"-,required"` Grandfather GrandfatherType `json:"grand"` SomeUntaggedBaseProperty bool `jsonschema:"required"` - someUnexportedUntaggedBaseProperty bool + someUnexportedUntaggedBaseProperty bool //nolint:unused } type MapType map[string]interface{} @@ -49,7 +49,7 @@ type ArrayType []string type nonExported struct { PublicNonExported int - privateNonExported int + privateNonExported int // nolint:unused } type ProtoEnum int32