Skip to content

Commit

Permalink
Fixing linting strategy
Browse files Browse the repository at this point in the history
  • Loading branch information
samlown committed Sep 6, 2023
1 parent 16ff337 commit ed817e0
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 60 deletions.
71 changes: 23 additions & 48 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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"
17 changes: 8 additions & 9 deletions reflect.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
}
Expand Down
6 changes: 3 additions & 3 deletions reflect_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{}
Expand All @@ -49,7 +49,7 @@ type ArrayType []string

type nonExported struct {
PublicNonExported int
privateNonExported int
privateNonExported int // nolint:unused
}

type ProtoEnum int32
Expand Down

0 comments on commit ed817e0

Please sign in to comment.