Skip to content

Commit e56aebe

Browse files
committed
Partial relinting.
Fixed linter config that made CI unworkable. Signed-off-by: Frederic BIDON <[email protected]>
1 parent be60b0a commit e56aebe

File tree

7 files changed

+66
-53
lines changed

7 files changed

+66
-53
lines changed

.golangci.yml

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,9 @@
11
linters-settings:
22
govet:
3-
check-shadowing: true
43
golint:
54
min-confidence: 0
65
gocyclo:
76
min-complexity: 45
8-
maligned:
9-
suggest-new: true
107
dupl:
118
threshold: 200
129
goconst:
@@ -16,7 +13,6 @@ linters-settings:
1613
linters:
1714
enable-all: true
1815
disable:
19-
- maligned
2016
- unparam
2117
- lll
2218
- gochecknoinits
@@ -29,17 +25,13 @@ linters:
2925
- wrapcheck
3026
- testpackage
3127
- nlreturn
32-
- gomnd
33-
- exhaustivestruct
34-
- goerr113
3528
- errorlint
3629
- nestif
3730
- godot
3831
- gofumpt
3932
- paralleltest
4033
- tparallel
4134
- thelper
42-
- ifshort
4335
- exhaustruct
4436
- varnamelen
4537
- gci
@@ -52,10 +44,15 @@ linters:
5244
- forcetypeassert
5345
- cyclop
5446
# deprecated linters
55-
- deadcode
56-
- interfacer
57-
- scopelint
58-
- varcheck
59-
- structcheck
60-
- golint
61-
- nosnakecase
47+
#- deadcode
48+
#- interfacer
49+
#- scopelint
50+
#- varcheck
51+
#- structcheck
52+
#- golint
53+
#- nosnakecase
54+
#- maligned
55+
#- goerr113
56+
#- ifshort
57+
#- gomnd
58+
#- exhaustivestruct

analyzer.go

Lines changed: 30 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,12 @@ import (
2525
"github.com/go-openapi/swag"
2626
)
2727

28+
const (
29+
allocLargeMap = 150
30+
allocMediumMap = 64
31+
allocSmallMap = 10
32+
)
33+
2834
type referenceAnalysis struct {
2935
schemas map[string]spec.Ref
3036
responses map[string]spec.Ref
@@ -169,30 +175,30 @@ type Spec struct {
169175
}
170176

171177
func (s *Spec) reset() {
172-
s.consumes = make(map[string]struct{}, 150)
173-
s.produces = make(map[string]struct{}, 150)
174-
s.authSchemes = make(map[string]struct{}, 150)
175-
s.operations = make(map[string]map[string]*spec.Operation, 150)
176-
s.allSchemas = make(map[string]SchemaRef, 150)
177-
s.allOfs = make(map[string]SchemaRef, 150)
178-
s.references.schemas = make(map[string]spec.Ref, 150)
179-
s.references.pathItems = make(map[string]spec.Ref, 150)
180-
s.references.responses = make(map[string]spec.Ref, 150)
181-
s.references.parameters = make(map[string]spec.Ref, 150)
182-
s.references.items = make(map[string]spec.Ref, 150)
183-
s.references.headerItems = make(map[string]spec.Ref, 150)
184-
s.references.parameterItems = make(map[string]spec.Ref, 150)
185-
s.references.allRefs = make(map[string]spec.Ref, 150)
186-
s.patterns.parameters = make(map[string]string, 150)
187-
s.patterns.headers = make(map[string]string, 150)
188-
s.patterns.items = make(map[string]string, 150)
189-
s.patterns.schemas = make(map[string]string, 150)
190-
s.patterns.allPatterns = make(map[string]string, 150)
191-
s.enums.parameters = make(map[string][]interface{}, 150)
192-
s.enums.headers = make(map[string][]interface{}, 150)
193-
s.enums.items = make(map[string][]interface{}, 150)
194-
s.enums.schemas = make(map[string][]interface{}, 150)
195-
s.enums.allEnums = make(map[string][]interface{}, 150)
178+
s.consumes = make(map[string]struct{}, allocLargeMap)
179+
s.produces = make(map[string]struct{}, allocLargeMap)
180+
s.authSchemes = make(map[string]struct{}, allocLargeMap)
181+
s.operations = make(map[string]map[string]*spec.Operation, allocLargeMap)
182+
s.allSchemas = make(map[string]SchemaRef, allocLargeMap)
183+
s.allOfs = make(map[string]SchemaRef, allocLargeMap)
184+
s.references.schemas = make(map[string]spec.Ref, allocLargeMap)
185+
s.references.pathItems = make(map[string]spec.Ref, allocLargeMap)
186+
s.references.responses = make(map[string]spec.Ref, allocLargeMap)
187+
s.references.parameters = make(map[string]spec.Ref, allocLargeMap)
188+
s.references.items = make(map[string]spec.Ref, allocLargeMap)
189+
s.references.headerItems = make(map[string]spec.Ref, allocLargeMap)
190+
s.references.parameterItems = make(map[string]spec.Ref, allocLargeMap)
191+
s.references.allRefs = make(map[string]spec.Ref, allocLargeMap)
192+
s.patterns.parameters = make(map[string]string, allocLargeMap)
193+
s.patterns.headers = make(map[string]string, allocLargeMap)
194+
s.patterns.items = make(map[string]string, allocLargeMap)
195+
s.patterns.schemas = make(map[string]string, allocLargeMap)
196+
s.patterns.allPatterns = make(map[string]string, allocLargeMap)
197+
s.enums.parameters = make(map[string][]interface{}, allocLargeMap)
198+
s.enums.headers = make(map[string][]interface{}, allocLargeMap)
199+
s.enums.items = make(map[string][]interface{}, allocLargeMap)
200+
s.enums.schemas = make(map[string][]interface{}, allocLargeMap)
201+
s.enums.allEnums = make(map[string][]interface{}, allocLargeMap)
196202
}
197203

198204
func (s *Spec) reload() {

flatten.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,9 +52,9 @@ type context struct {
5252

5353
func newContext() *context {
5454
return &context{
55-
newRefs: make(map[string]*newRef, 150),
55+
newRefs: make(map[string]*newRef, allocMediumMap),
5656
warnings: make([]string, 0),
57-
resolved: make(map[string]string, 50),
57+
resolved: make(map[string]string, allocMediumMap),
5858
}
5959
}
6060

@@ -745,7 +745,7 @@ func flattenAnonPointer(key string, v SchemaRef, refsToReplace map[string]Schema
745745
if ers != nil {
746746
return fmt.Errorf("schema analysis [%s]: %w", key, ers)
747747
}
748-
callers := make([]string, 0, 64)
748+
callers := make([]string, 0, allocMediumMap)
749749

750750
debugLog("looking for callers")
751751

flatten_name.go

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -227,10 +227,15 @@ func namesForOperation(parts sortref.SplitKey, operations map[string]operations.
227227
return baseNames, startIndex
228228
}
229229

230+
const (
231+
minStartIndex = 2
232+
minSegments = 2
233+
)
234+
230235
func namesForDefinition(parts sortref.SplitKey) ([][]string, int) {
231236
nm := parts.DefinitionName()
232237
if nm != "" {
233-
return [][]string{{parts.DefinitionName()}}, 2
238+
return [][]string{{parts.DefinitionName()}}, minStartIndex
234239
}
235240

236241
return [][]string{}, 0
@@ -239,7 +244,7 @@ func namesForDefinition(parts sortref.SplitKey) ([][]string, int) {
239244
// partAdder knows how to interpret a schema when it comes to build a name from parts
240245
func partAdder(aschema *AnalyzedSchema) sortref.PartAdder {
241246
return func(part string) []string {
242-
segments := make([]string, 0, 2)
247+
segments := make([]string, 0, minSegments)
243248

244249
if part == "items" || part == "additionalItems" {
245250
if aschema.IsTuple || aschema.IsTupleWithExtra {

internal/flatten/replace/replace.go

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,10 @@ import (
1313
"github.com/go-openapi/spec"
1414
)
1515

16-
const definitionsPath = "#/definitions"
16+
const (
17+
definitionsPath = "#/definitions"
18+
allocMediumMap = 64
19+
)
1720

1821
var debugLog = debug.GetLogger("analysis/flatten/replace", os.Getenv("SWAGGER_DEBUG") != "")
1922

@@ -336,8 +339,8 @@ func DeepestRef(sp *spec.Swagger, opts *spec.ExpandOptions, ref spec.Ref) (*Deep
336339
}
337340

338341
currentRef := ref
339-
visited := make(map[string]bool, 64)
340-
warnings := make([]string, 0, 2)
342+
visited := make(map[string]bool, allocMediumMap)
343+
warnings := make([]string, 0)
341344

342345
DOWNREF:
343346
for currentRef.String() != "" {

internal/flatten/schutils/flatten_schema.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,16 @@ import (
77
"github.com/go-openapi/swag"
88
)
99

10+
const allocLargeMap = 150
11+
1012
// Save registers a schema as an entry in spec #/definitions
1113
func Save(sp *spec.Swagger, name string, schema *spec.Schema) {
1214
if schema == nil {
1315
return
1416
}
1517

1618
if sp.Definitions == nil {
17-
sp.Definitions = make(map[string]spec.Schema, 150)
19+
sp.Definitions = make(map[string]spec.Schema, allocLargeMap)
1820
}
1921

2022
sp.Definitions[name] = *schema

mixin.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -474,23 +474,23 @@ func initPrimary(primary *spec.Swagger) {
474474
}
475475

476476
if primary.Security == nil {
477-
primary.Security = make([]map[string][]string, 0, 10)
477+
primary.Security = make([]map[string][]string, 0, allocSmallMap)
478478
}
479479

480480
if primary.Produces == nil {
481-
primary.Produces = make([]string, 0, 10)
481+
primary.Produces = make([]string, 0, allocSmallMap)
482482
}
483483

484484
if primary.Consumes == nil {
485-
primary.Consumes = make([]string, 0, 10)
485+
primary.Consumes = make([]string, 0, allocSmallMap)
486486
}
487487

488488
if primary.Tags == nil {
489-
primary.Tags = make([]spec.Tag, 0, 10)
489+
primary.Tags = make([]spec.Tag, 0, allocSmallMap)
490490
}
491491

492492
if primary.Schemes == nil {
493-
primary.Schemes = make([]string, 0, 10)
493+
primary.Schemes = make([]string, 0, allocSmallMap)
494494
}
495495

496496
if primary.Paths == nil {

0 commit comments

Comments
 (0)