Skip to content

Commit f600b6e

Browse files
Bump golangci-lint and (max) Go versions (#219)
Lint is failing with some inscrutable panic (on a commit with no code changes). Let's try bumping the version in case they fixed it. Additionally, the new version's github action uses Go 1.19, which means it pulls in gofmt updates to match the new [doc-comment formatting rules][1]. So I added Go 1.19 to our list of versions to test (fixes #216) and updated some of our doc-comments to format better in the new world (mostly using the new link syntax). [1]: https://go.dev/doc/comment Test plan: make lint
1 parent c0510ff commit f600b6e

File tree

16 files changed

+396
-196
lines changed

16 files changed

+396
-196
lines changed

.github/workflows/go.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ jobs:
1212
runs-on: ubuntu-latest
1313
strategy:
1414
matrix:
15-
go: [ '1.16', '1.17', '1.18' ]
15+
go: [ '1.16', '1.17', '1.18', '1.19' ]
1616

1717
steps:
1818
- name: Set up Go
@@ -42,4 +42,4 @@ jobs:
4242
- name: Run lint
4343
uses: golangci/golangci-lint-action@v2
4444
with:
45-
version: v1.45 # should match internal/lint/go.mod
45+
version: v1.48 # should match internal/lint/go.mod

generate/config.go

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,11 @@ var cfgFilenames = []string{".genqlient.yml", ".genqlient.yaml", "genqlient.yml"
1616
// Config represents genqlient's configuration, generally read from
1717
// genqlient.yaml.
1818
//
19-
// Callers must call ValidateAndFillDefaults before using the config.
19+
// Callers must call [Config.ValidateAndFillDefaults] before using the config.
2020
type Config struct {
21-
// The following fields are documented at:
22-
// https://github.com/Khan/genqlient/blob/main/docs/genqlient.yaml
21+
// The following fields are documented in the [genqlient.yaml docs].
22+
//
23+
// [genqlient.yaml docs]: https://github.com/Khan/genqlient/blob/main/docs/genqlient.yaml
2324
Schema StringList `yaml:"schema"`
2425
Operations StringList `yaml:"operations"`
2526
Generated string `yaml:"generated"`
@@ -46,8 +47,9 @@ type Config struct {
4647
}
4748

4849
// A TypeBinding represents a Go type to which genqlient will bind a particular
49-
// GraphQL type, and is documented further at:
50-
// https://github.com/Khan/genqlient/blob/main/docs/genqlient.yaml
50+
// GraphQL type, and is documented further in the [genqlient.yaml docs].
51+
//
52+
// [genqlient.yaml docs]: https://github.com/Khan/genqlient/blob/main/docs/genqlient.yaml
5153
type TypeBinding struct {
5254
Type string `yaml:"type"`
5355
ExpectExactFields string `yaml:"expect_exact_fields"`
@@ -56,8 +58,10 @@ type TypeBinding struct {
5658
}
5759

5860
// A PackageBinding represents a Go package for which genqlient will
59-
// automatically generate TypeBindings, and is documented further at:
60-
// https://github.com/Khan/genqlient/blob/main/docs/genqlient.yaml
61+
// automatically generate [TypeBinding] values, and is documented further in
62+
// the [genqlient.yaml docs].
63+
//
64+
// [genqlient.yaml docs]: https://github.com/Khan/genqlient/blob/main/docs/genqlient.yaml
6165
type PackageBinding struct {
6266
Package string `yaml:"package"`
6367
}

generate/convert.go

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -424,12 +424,12 @@ func (g *generator) convertDefinition(
424424
goName := upperFirst(field.Name)
425425
// Several of the arguments don't really make sense here:
426426
// (note field.Type is necessarily a scalar, input, or enum)
427-
// - namePrefix is ignored for input types and enums (see
428-
// names.go) and for scalars (they use client-specified
429-
// names)
430-
// - selectionSet is ignored for input types, because we
431-
// just use all fields of the type; and it's nonexistent
432-
// for scalars and enums, our only other possible types
427+
// - namePrefix is ignored for input types and enums (see
428+
// names.go) and for scalars (they use client-specified
429+
// names)
430+
// - selectionSet is ignored for input types, because we
431+
// just use all fields of the type; and it's nonexistent
432+
// for scalars and enums, our only other possible types
433433
// TODO(benkraft): Can we refactor to avoid passing the values that
434434
// will be ignored? We know field.Type is a scalar, enum, or input
435435
// type. But plumbing that is a bit tricky in practice.
@@ -650,23 +650,26 @@ func (g *generator) convertSelectionSet(
650650
// of the given type", which is true when the given type is or implements
651651
// the fragment's type. This is distinct from the rules for when a fragment
652652
// spread is legal, which is true when the fragment would be active for *any*
653-
// of the concrete types the spread-context could have (see
654-
// https://spec.graphql.org/draft/#sec-Fragment-Spreads or docs/DESIGN.md).
653+
// of the concrete types the spread-context could have (see the [GraphQL spec]
654+
// or docs/DESIGN.md).
655655
//
656656
// containingTypedef is as described in convertInlineFragment, below.
657657
// fragmentTypedef is the definition of the fragment's type-condition, i.e. the
658658
// definition of MyType in a fragment `on MyType`.
659+
//
660+
// [GraphQL spec]: https://spec.graphql.org/draft/#sec-Fragment-Spreads
659661
func fragmentMatches(containingTypedef, fragmentTypedef *ast.Definition) bool {
660662
if containingTypedef.Name == fragmentTypedef.Name {
661663
return true
662664
}
663665
for _, iface := range containingTypedef.Interfaces {
664666
// Note we don't need to recurse into the interfaces here, because in
665667
// GraphQL types must list all the interfaces they implement, including
666-
// all types those interfaces implement [1]. Actually, at present
668+
// all types those interfaces implement ([spec]). Actually, at present
667669
// gqlparser doesn't even support interfaces implementing other
668670
// interfaces, but our code would handle that too.
669-
// [1] https://spec.graphql.org/draft/#sec-Interfaces.Interfaces-Implementing-Interfaces
671+
//
672+
// [spec]: https://spec.graphql.org/draft/#sec-Interfaces.Interfaces-Implementing-Interfaces
670673
if iface == fragmentTypedef.Name {
671674
return true
672675
}

generate/generate.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -313,9 +313,9 @@ func (g *generator) addOperation(op *ast.OperationDefinition) error {
313313
// Generate is the main programmatic entrypoint to genqlient, and generates and
314314
// returns Go source code based on the given configuration.
315315
//
316-
// See Config for more on creating a configuration. The return value is a map
317-
// from filename to the generated file-content (e.g. Go source). Callers who
318-
// don't want to manage reading and writing the files should call Main.
316+
// See [Config] for more on creating a configuration. The return value is a
317+
// map from filename to the generated file-content (e.g. Go source). Callers
318+
// who don't want to manage reading and writing the files should call [Main].
319319
func Generate(config *Config) (map[string][]byte, error) {
320320
// Step 1: Read in the schema and operations from the files defined by the
321321
// config (and validate the operations against the schema). This is all

generate/genqlient_directive.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,8 +107,10 @@ func setString(optionName string, dst *string, v *ast.Value, pos *ast.Position)
107107
//
108108
// If there are multiple genqlient directives are applied to the same node,
109109
// e.g.
110+
//
110111
// # @genqlient(...)
111112
// # @genqlient(...)
113+
//
112114
// add will be called several times. In this case, conflicts between the
113115
// options are an error.
114116
func (dir *genqlientDirective) add(graphQLDirective *ast.Directive, pos *ast.Position) error {

generate/imports.go

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -29,20 +29,24 @@ var _sliceOrMapPrefixRegexp = regexp.MustCompile(`^(\*|\[\d*\]|map\[string\])*`)
2929
//
3030
// Ideally, we want to allow a reference to basically an arbitrary symbol.
3131
// But that's very hard, because it might be quite complicated, like
32+
//
3233
// struct{ F []map[mypkg.K]otherpkg.V }
34+
//
3335
// Now in practice, using an unnamed struct is not a great idea, but we do
3436
// want to allow as much as we can that encoding/json knows how to work
3537
// with, since you would reasonably expect us to accept, say,
3638
// map[string][]interface{}. So we allow:
37-
// - any named type (mypkg.T)
38-
// - any predeclared basic type (string, int, etc.)
39-
// - interface{}
40-
// - for any allowed type T, *T, []T, [N]T, and map[string]T
39+
// - any named type (mypkg.T)
40+
// - any predeclared basic type (string, int, etc.)
41+
// - interface{}
42+
// - for any allowed type T, *T, []T, [N]T, and map[string]T
43+
//
4144
// which effectively excludes:
42-
// - unnamed struct types
43-
// - map[K]V where K is a named type wrapping string
44-
// - any nonstandard spelling of those (interface {/* hi */},
45-
// map[ string ]T)
45+
// - unnamed struct types
46+
// - map[K]V where K is a named type wrapping string
47+
// - any nonstandard spelling of those (interface {/* hi */},
48+
// map[ string ]T)
49+
//
4650
// (This is documented in docs/genqlient.yaml)
4751
func (g *generator) ref(fullyQualifiedName string) (qualifiedName string, err error) {
4852
errorMsg := `invalid type-name "%v" (%v); expected a builtin, ` +

generate/main.go

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
// Package generate provides programmatic access to genqlient's functionality,
22
// and documentation of its configuration options. For general usage
3-
// documentation, see github.com/Khan/genqlient.
3+
// documentation, see the project [GitHub].
4+
//
5+
// [GitHub]: https://github.com/Khan/genqlient
46
package generate
57

68
import (
@@ -62,8 +64,10 @@ See https://github.com/Khan/genqlient for full documentation.
6264
}
6365

6466
// Main is the command-line entrypoint to genqlient; it's equivalent to calling
65-
// `go run github.com/Khan/genqlient`. For lower-level control over
66-
// genqlient's operation, see Generate.
67+
//
68+
// go run github.com/Khan/genqlient
69+
//
70+
// For lower-level control over genqlient's operation, see [Generate].
6771
func Main() {
6872
exitIfError := func(err error) {
6973
if err != nil {

generate/names.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,9 +81,11 @@ package generate
8181
// can collide.
8282
// All cases seem fairly rare in practice; eventually we'll likely allow users
8383
// the ability to specify their own names, which they could use to avoid this
84-
// (see https://github.com/Khan/genqlient/issues/12).
84+
// (see [issue #12]).
8585
// TODO(benkraft): We should probably at least try to detect it and bail.
8686
//
87+
// [issue #12]: https://github.com/Khan/genqlient/issues/12
88+
//
8789
// To implement all of the above, as we traverse the operation (and schema) in
8890
// convert.go, we keep track of a list of parts to prefix to our type-names.
8991
// The list always ends with a field, not a type; and we extend it when

generate/stringlist.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
package generate
22

33
// StringList provides yaml unmarshaler to accept both `string` and `[]string` as a valid type.
4-
// Sourced from:
5-
// https://github.com/99designs/gqlgen/blob/1a0b19feff6f02d2af6631c9d847bc243f8ede39/codegen/config/config.go#L302-L329
4+
// Sourced from [gqlgen].
5+
//
6+
// [gqlgen]: https://github.com/99designs/gqlgen/blob/1a0b19feff6f02d2af6631c9d847bc243f8ede39/codegen/config/config.go#L302-L329
67
type StringList []string
78

89
func (a *StringList) UnmarshalYAML(unmarshal func(interface{}) error) error {

generate/types.go

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -186,11 +186,11 @@ func (field *goStructField) Selector() string {
186186
}
187187

188188
// unmarshaler returns:
189-
// - the name of the function to use to unmarshal this field
190-
// - true if this is a fully-qualified name (false if it is a package-local
191-
// unqualified name)
192-
// - true if we need to generate an unmarshaler at all, false if the default
193-
// behavior will suffice
189+
// - the name of the function to use to unmarshal this field
190+
// - true if this is a fully-qualified name (false if it is a package-local
191+
// unqualified name)
192+
// - true if we need to generate an unmarshaler at all, false if the default
193+
// behavior will suffice
194194
func (field *goStructField) unmarshaler() (qualifiedName string, needsImport bool, needsUnmarshaler bool) {
195195
switch typ := field.GoType.Unwrap().(type) {
196196
case *goOpaqueType:
@@ -214,9 +214,9 @@ func (field *goStructField) Unmarshaler(g *generator) (string, error) {
214214
}
215215

216216
// marshaler returns:
217-
// - the fully-qualified name of the function to use to marshal this field
218-
// - true if we need to generate an marshaler at all, false if the default
219-
// behavior will suffice
217+
// - the fully-qualified name of the function to use to marshal this field
218+
// - true if we need to generate an marshaler at all, false if the default
219+
// behavior will suffice
220220
func (field *goStructField) marshaler() (qualifiedName string, needsImport bool, needsMarshaler bool) {
221221
switch typ := field.GoType.Unwrap().(type) {
222222
case *goOpaqueType:
@@ -273,17 +273,21 @@ type selector struct {
273273
// and the paths to reach them (via those embeds), but with different
274274
// visibility rules for conflicting fields than Go.
275275
//
276-
// (Before you read further, now's a good time to review Go's rules:
277-
// https://golang.org/ref/spec#Selectors. Done? Good.)
276+
// (Before you read further, now's a good time to review [Go's rules].
277+
// Done? Good.)
278278
//
279279
// To illustrate the need, consider the following query:
280+
//
280281
// fragment A on T { id }
281282
// fragment B on T { id }
282283
// query Q { t { ...A ...B } }
284+
//
283285
// We generate types:
286+
//
284287
// type A struct { Id string `json:"id"` }
285288
// type B struct { Id string `json:"id"` }
286289
// type QT struct { A; B }
290+
//
287291
// According to Go's embedding rules, QT has no field Id: since QT.A.Id and
288292
// QT.B.Id are at equal depth, neither wins and gets promoted. (Go's JSON
289293
// library uses similar logic to decide which field to write to JSON, except
@@ -307,7 +311,10 @@ type selector struct {
307311
// practice, hopefully, they all match, but validating that is even more work
308312
// for a fairly rare case.) This function returns, for each JSON-name, the Go
309313
// field we want to use. In the example above, it would return:
314+
//
310315
// []selector{{<goStructField for QT.A.Id>, "A.Id"}}
316+
//
317+
// [Go's rules]: https://golang.org/ref/spec#Selectors
311318
func (typ *goStructType) FlattenedFields() ([]*selector, error) {
312319
seenJSONNames := map[string]bool{}
313320
retval := make([]*selector, 0, len(typ.Fields))

0 commit comments

Comments
 (0)