Skip to content

Commit d2ac273

Browse files
Bump golangci/golangci-lint-action from 6 to 7 (#23)
Bumps golangci/golangci-lint-action from 6 to 7. This moves the repo to golangci-lint v2. Signed-off-by: dependabot[bot] <[email protected]> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: Andrew Kroh <[email protected]>
1 parent 7349569 commit d2ac273

File tree

5 files changed

+67
-48
lines changed

5 files changed

+67
-48
lines changed

.github/workflows/lint.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,12 @@ jobs:
2222
cache: false
2323

2424
- name: golangci-lint
25-
uses: golangci/golangci-lint-action@v6
25+
uses: golangci/golangci-lint-action@v7
2626
with:
2727
version: latest
2828

2929
- name: golangci-lint
30-
uses: golangci/golangci-lint-action@v6
30+
uses: golangci/golangci-lint-action@v7
3131
with:
3232
version: latest
3333
working-directory: ./internal/generator

.golangci.yml

Lines changed: 41 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,45 +1,52 @@
1-
---
2-
1+
version: "2"
32
run:
4-
issues-exit-code: 1
53
modules-download-mode: readonly
6-
4+
issues-exit-code: 1
75
linters:
8-
disable-all: true
6+
default: none
97
enable:
108
- errcheck
11-
- gosimple
9+
- errorlint
1210
- govet
1311
- ineffassign
14-
- staticcheck
15-
- stylecheck
16-
- typecheck
17-
- unused
18-
- errorlint
19-
- gofumpt
20-
- goimports
2112
- misspell
2213
- prealloc
14+
- revive
15+
- staticcheck
2316
- unconvert
2417
- unused
25-
- revive
26-
fast: false
27-
28-
linters-settings:
29-
goimports:
30-
local-prefixes: github.com/andrewkroh/go-ingest-node
31-
gofumpt:
32-
extra-rules: true
33-
stylecheck:
34-
checks:
35-
- all
36-
staticcheck:
37-
checks:
38-
- '-SA1019' # strings.Title is deprecated.
39-
40-
issues:
41-
include:
42-
# If you're going to write a comment, follow the conventions.
43-
# https://go.dev/doc/effective_go#commentary.
44-
# comment on exported (.+) should be of the form "(.+)..."
45-
- EXC0014
18+
settings:
19+
staticcheck:
20+
checks:
21+
- all
22+
exclusions:
23+
generated: lax
24+
presets:
25+
- common-false-positives
26+
- legacy
27+
- std-error-handling
28+
paths:
29+
- third_party$
30+
- builtin$
31+
- examples$
32+
rules:
33+
- path: internal/generator/internal/spec/types.go
34+
linters:
35+
- revive
36+
text: "should have comment or be unexported"
37+
formatters:
38+
enable:
39+
- gofumpt
40+
- goimports
41+
settings:
42+
gofumpt:
43+
extra-rules: true
44+
goimports:
45+
local-prefixes:
46+
- github.com/andrewkroh/go-ingest-node
47+
exclusions:
48+
generated: lax
49+
paths:
50+
- third_party$
51+
- builtin$
52+
- examples$

internal/generator/internal/codegen/generator.go

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
// specific language governing permissions and limitations
1616
// under the License.
1717

18+
// Package codegen generates Go code from the elasticsearch-specification.
19+
// It is used to generate the data model for the Ingest Node pipelines.
1820
package codegen
1921

2022
import (
@@ -96,10 +98,12 @@ func init() {
9698
licenseHeader = sb.String()
9799
}
98100

101+
// Generator generates Go code from the elasticsearch-specification.
99102
type Generator struct {
100103
allTypes map[spec.TypeName]*spec.TypeDefinition
101104
}
102105

106+
// New creates a new code generator.
103107
func New(model *spec.Model) *Generator {
104108
b := &Generator{
105109
allTypes: map[spec.TypeName]*spec.TypeDefinition{},
@@ -117,6 +121,10 @@ func New(model *spec.Model) *Generator {
117121
return b
118122
}
119123

124+
// BuildCode generates Go code based on the provided typeSelector.
125+
// The typeSelector function is used to filter the types that will be
126+
// included in the generated code. The output is written to the provided
127+
// io.Writer.
120128
func (b *Generator) BuildCode(w io.Writer, typeSelector func(name, inherits spec.TypeName) bool) error {
121129
// Mark the overrides as visited dependencies so that those types and
122130
// their dependencies are not included in the generated code.
@@ -327,8 +335,8 @@ func (b *Generator) goStruct(ifc *spec.Interface, f *jen.File) error {
327335

328336
var err error
329337
f.Type().Id(ifc.TypeName.Name).StructFunc(func(g *jen.Group) {
330-
if ifc.Inherits.TypeName.Name != "" {
331-
g.Id(ifc.Inherits.TypeName.Name)
338+
if ifc.Inherits.Name != "" {
339+
g.Id(ifc.Inherits.Name)
332340
}
333341
b.addProperties(g, ifc.Properties)
334342
})
@@ -343,7 +351,7 @@ func (b *Generator) depsOfType(t *spec.TypeDefinition, deps map[spec.TypeName]bo
343351

344352
switch v := t.Value.(type) {
345353
case spec.Interface:
346-
if v.Inherits.TypeName.Name != "" {
354+
if v.Inherits.Name != "" {
347355
deps[v.Inherits.TypeName] = true
348356
if parent, found := b.allTypes[v.Inherits.TypeName]; found {
349357
b.depsOfType(parent, deps)
@@ -361,17 +369,17 @@ func (b *Generator) depsOfType(t *spec.TypeDefinition, deps map[spec.TypeName]bo
361369
func (b *Generator) depsOfValue(v *spec.ValueOf, deps map[spec.TypeName]bool) {
362370
switch {
363371
case v.InstanceOf != nil:
364-
if _, visited := deps[v.InstanceOf.TypeName]; !visited {
365-
deps[v.InstanceOf.TypeName] = true
366-
b.depsOfType(b.allTypes[v.InstanceOf.TypeName], deps)
372+
if _, visited := deps[v.TypeName]; !visited {
373+
deps[v.TypeName] = true
374+
b.depsOfType(b.allTypes[v.TypeName], deps)
367375
}
368376
case v.ArrayOf != nil:
369377
b.depsOfValue(v.ArrayOf.Value, deps)
370378
case v.DictionaryOf != nil:
371-
b.depsOfValue(v.DictionaryOf.Key, deps)
379+
b.depsOfValue(v.Key, deps)
372380
b.depsOfValue(v.DictionaryOf.Value, deps)
373381
case v.UnionOf != nil:
374-
for _, item := range v.UnionOf.Items {
382+
for _, item := range v.Items {
375383
b.depsOfValue(item, deps)
376384
}
377385
}
@@ -380,10 +388,10 @@ func (b *Generator) depsOfValue(v *spec.ValueOf, deps map[spec.TypeName]bool) {
380388
func identifier(v *spec.ValueOf) string {
381389
switch {
382390
case v.InstanceOf != nil:
383-
if o := overrides[qualifiedName(v.InstanceOf.Namespace, v.InstanceOf.TypeName.Name)]; o != "" {
391+
if o := overrides[qualifiedName(v.Namespace, v.Name)]; o != "" {
384392
return o
385393
}
386-
return v.InstanceOf.TypeName.Name
394+
return v.Name
387395
case v.ArrayOf != nil:
388396
return identifier(v.ArrayOf.Value)
389397
case v.UnionOf != nil:
@@ -395,7 +403,7 @@ func identifier(v *spec.ValueOf) string {
395403
case v.LiteralValue != nil:
396404
return fmt.Sprintf("%s", v.LiteralValue.Value)
397405
case v.DictionaryOf != nil:
398-
return fmt.Sprintf("map[%s]%s", identifier(v.DictionaryOf.Key), identifier(v.DictionaryOf.Value))
406+
return fmt.Sprintf("map[%s]%s", identifier(v.Key), identifier(v.DictionaryOf.Value))
399407
}
400408
return ""
401409
}
@@ -421,7 +429,7 @@ func goIDName(name string) string {
421429
continue
422430
}
423431

424-
allParts[i] = strings.Title(p)
432+
allParts[i] = strings.Title(p) //nolint:staticcheck // strings.Title seems sufficient for capitalizing identifiers.
425433
}
426434

427435
return strings.Join(allParts, "")

internal/generator/internal/spec/types.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import (
2525
"reflect"
2626
)
2727

28+
// Model represents the top-level structure of the elasticsearch-specification schema.
2829
type Model struct {
2930
Types []TypeDefinition `json:"types,omitempty"`
3031
}

internal/generator/main.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@
1515
// specific language governing permissions and limitations
1616
// under the License.
1717

18+
// The generator command line tool generates Go code for representing
19+
// Elasticsearch Ingest Node data types. It generates code based on the
20+
// elasticsearch-specification.
1821
package main
1922

2023
import (

0 commit comments

Comments
 (0)