Skip to content

Commit 182ecc2

Browse files
Upgrade lint
1 parent 64238f4 commit 182ecc2

File tree

8 files changed

+66
-17
lines changed

8 files changed

+66
-17
lines changed

.github/workflows/lint.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,4 +40,4 @@ jobs:
4040
check-latest: true
4141
- uses: golangci/golangci-lint-action@v3
4242
with:
43-
version: v1.54.2
43+
version: v2.2.1

.golangci.yaml

Lines changed: 47 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,47 @@
1-
issues:
2-
exclude-rules:
3-
- linters:
4-
- staticcheck
5-
text: 'SA1019:'
1+
# yaml-language-server: $schema=https://golangci-lint.run/jsonschema/golangci.jsonschema.json
2+
3+
version: "2"
4+
run:
5+
concurrency: 2
6+
build-tags:
7+
- integration_tests
8+
tests: true
9+
allow-parallel-runners: true
10+
output:
11+
formats:
12+
text:
13+
path: stdout
14+
linters:
15+
enable:
16+
- errname
17+
- nlreturn
18+
- revive
19+
settings:
20+
revive:
21+
rules:
22+
- name: exported
23+
disabled: true
24+
exclusions:
25+
generated: strict
26+
rules:
27+
- linters:
28+
- staticcheck
29+
text: "SA1019:"
30+
- linters:
31+
- staticcheck
32+
text: "QF1008:"
33+
paths:
34+
- vendor
35+
- third_party$
36+
- builtin$
37+
- examples$
38+
formatters:
39+
enable:
40+
- gofumpt
41+
exclusions:
42+
generated: lax
43+
paths:
44+
- vendor
45+
- third_party$
46+
- builtin$
47+
- examples$

internal/generator/description.go

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,8 @@ import (
88
"google.golang.org/protobuf/compiler/protogen"
99
)
1010

11-
var (
12-
// exampleRegexp is for breaking apart a comment with an example.
13-
exampleRegexp = regexp.MustCompile(`(?is)(.*)Example:(.*)`)
14-
)
11+
// exampleRegexp is for breaking apart a comment with an example.
12+
var exampleRegexp = regexp.MustCompile(`(?is)(.*)Example:(.*)`)
1513

1614
// parsedComments holds the data parsed and extracted from a comment.
1715
type parsedComments struct {

internal/generator/generator.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@ func (g *Generator) Run() error {
100100
}
101101

102102
_, err = outFile.Write(patchedBytes)
103+
103104
return err
104105
}
105106

@@ -144,6 +145,7 @@ func (g *Generator) patchRemovedSecurity(fileBytes []byte) ([]byte, error) {
144145
for key := range obj {
145146
if key == "___remove" {
146147
m.Set(securityPath, make([]string, 0))
148+
147149
break outer
148150
}
149151
}
@@ -161,6 +163,7 @@ func (g *Generator) patchRemovedSecurity(fileBytes []byte) ([]byte, error) {
161163
encoder.SetIndent(2)
162164

163165
err = encoder.Encode(m)
166+
164167
return buffer.Bytes(), err
165168
}
166169

@@ -223,6 +226,7 @@ func (g *Generator) patchEmptySchemas(fileBytes []byte) ([]byte, error) {
223226
encoder.SetIndent(2)
224227

225228
err = encoder.Encode(m)
229+
226230
return buffer.Bytes(), err
227231
}
228232

internal/generator/message.go

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,15 @@
11
package generator
22

33
import (
4-
"github.com/technicallyjosh/protoc-gen-openapi/internal/generator/util"
54
"google.golang.org/protobuf/compiler/protogen"
6-
)
75

8-
var (
9-
// allMessages holds all messages with their full paths for reference whenever we need to look
10-
// for a message to build out.
11-
allMessages = make(messageMap)
6+
"github.com/technicallyjosh/protoc-gen-openapi/internal/generator/util"
127
)
138

9+
// allMessages holds all messages with their full paths for reference whenever we need to look
10+
// for a message to build out.
11+
var allMessages = make(messageMap)
12+
1413
type messageMap map[string]*protogen.Message
1514

1615
// Set adds the specified message to the map.

internal/generator/path.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,10 @@ import (
88
"strings"
99

1010
"github.com/getkin/kin-openapi/openapi3"
11-
oapiv1 "github.com/technicallyjosh/protoc-gen-openapi/api/oapi/v1"
1211
"google.golang.org/protobuf/compiler/protogen"
1312
"google.golang.org/protobuf/proto"
13+
14+
oapiv1 "github.com/technicallyjosh/protoc-gen-openapi/api/oapi/v1"
1415
)
1516

1617
func NewServer(host string) (*openapi3.Server, error) {
@@ -121,6 +122,7 @@ func (g *Generator) addPathsToDoc(doc *openapi3.T, services []*protogen.Service)
121122
// e.g. security: {}
122123
if s.Name == "" {
123124
security = make([]*oapiv1.Security, 0)
125+
124126
break
125127
}
126128

@@ -356,6 +358,7 @@ func (g *Generator) addOperation(p addOperationParams) error {
356358
Name: "___remove",
357359
},
358360
}
361+
359362
break
360363
}
361364

internal/generator/schema.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,7 @@ func addSchema(doc *openapi3.T, key string, value *openapi3.SchemaRef) {
193193
// schemaExists returns whether a schema exists or not on the doc.
194194
func schemaExists(doc *openapi3.T, name string) bool {
195195
_, ok := doc.Components.Schemas[name]
196+
196197
return ok
197198
}
198199

@@ -225,6 +226,7 @@ func newFieldSchema(field protoreflect.FieldDescriptor) *openapi3.Schema {
225226

226227
if field.IsList() {
227228
schema.Type = openapi3.TypeArray
229+
228230
return newArraySchema(kind)
229231
}
230232

main_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,5 +147,6 @@ func TestSuites(t *testing.T) {
147147

148148
func readFile(name string) string {
149149
data, _ := os.ReadFile("test/" + name)
150+
150151
return string(data)
151152
}

0 commit comments

Comments
 (0)