Enable golangci-lint (#49)
## Summary: It would be nice to have some linting beyond `go vet`! Now we do. I started by copying the config from Khan/webapp. I did remove a couple of staticcheck checks that I didn't feel were useful. (Note also that exportloopref is the replacement for scopelint in newer golangci-lint.) Included are all the needed lint fixes; most are stylistic but the changes in the example are a (minor) bugfix. Fixes #22. Issue: https://github.com/Khan/genqlient/issues/22 ## Test plan: make check Author: benjaminjkraft Reviewers: aberkan, dnerdy, benjaminjkraft, csilvers, MiguelCastillo Required Reviewers: Approved by: aberkan, dnerdy Checks: ✅ Test (1.17), ✅ Test (1.16), ✅ Test (1.15), ✅ Test (1.14), ✅ Test (1.13), ✅ Lint, ✅ Test (1.17), ✅ Test (1.16), ✅ Test (1.15), ✅ Test (1.14), ✅ Test (1.13), ✅ Lint Pull request URL: https://github.com/Khan/genqlient/pull/49
This commit is contained in:
@@ -65,8 +65,8 @@ type GenqlientDirective struct {
|
||||
Pointer *bool
|
||||
}
|
||||
|
||||
func (g *GenqlientDirective) GetOmitempty() bool { return g.Omitempty != nil && *g.Omitempty }
|
||||
func (g *GenqlientDirective) GetPointer() bool { return g.Pointer != nil && *g.Pointer }
|
||||
func (dir *GenqlientDirective) GetOmitempty() bool { return dir.Omitempty != nil && *dir.Omitempty }
|
||||
func (dir *GenqlientDirective) GetPointer() bool { return dir.Pointer != nil && *dir.Pointer }
|
||||
|
||||
func setBool(dst **bool, v *ast.Value) error {
|
||||
ei, err := v.Value(nil) // no vars allowed
|
||||
|
||||
@@ -21,7 +21,7 @@ func getRepoRoot(t *testing.T) string {
|
||||
}
|
||||
|
||||
func TestGenerateExample(t *testing.T) {
|
||||
configFilename := filepath.Join(getRepoRoot(t), "example/genqlient.yaml")
|
||||
configFilename := filepath.Join(getRepoRoot(t), "example", "genqlient.yaml")
|
||||
config, err := ReadAndValidateConfig(configFilename)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
|
||||
@@ -152,7 +152,6 @@ func (g *generator) addOperation(op *ast.OperationDefinition) error {
|
||||
|
||||
args := make([]argument, len(op.VariableDefinitions))
|
||||
for i, arg := range op.VariableDefinitions {
|
||||
var err error
|
||||
args[i], err = g.getArgument(op.Name, arg, directive)
|
||||
if err != nil {
|
||||
return err
|
||||
|
||||
@@ -68,7 +68,6 @@ func TestGenerate(t *testing.T) {
|
||||
t.Run(filename, func(t *testing.T) {
|
||||
testutil.Cupaloy.SnapshotT(t, string(content))
|
||||
})
|
||||
// TODO(benkraft): Also check that the code at least builds!
|
||||
}
|
||||
|
||||
t.Run("Build", func(t *testing.T) {
|
||||
|
||||
+2
-2
@@ -9,8 +9,8 @@ import (
|
||||
)
|
||||
|
||||
func (g *generator) addImportFor(pkgPath string) (alias string) {
|
||||
if alias, ok := g.imports[pkgPath]; ok {
|
||||
return alias
|
||||
if existingAlias, ok := g.imports[pkgPath]; ok {
|
||||
return existingAlias
|
||||
}
|
||||
|
||||
pkgName := pkgPath[strings.LastIndex(pkgPath, "/")+1:]
|
||||
|
||||
+1
-2
@@ -4,7 +4,6 @@ import (
|
||||
"fmt"
|
||||
goAst "go/ast"
|
||||
goParser "go/parser"
|
||||
"go/token"
|
||||
goToken "go/token"
|
||||
"io/ioutil"
|
||||
"path/filepath"
|
||||
@@ -134,7 +133,7 @@ func getQueriesFromGo(text string, basedir, filename string) ([]*ast.QueryDocume
|
||||
}
|
||||
|
||||
basicLit, ok := node.(*goAst.BasicLit)
|
||||
if !ok || basicLit.Kind != token.STRING {
|
||||
if !ok || basicLit.Kind != goToken.STRING {
|
||||
return true // recurse
|
||||
}
|
||||
|
||||
|
||||
+3
-3
@@ -281,8 +281,8 @@ func (builder *typeBuilder) writeType(name, namePrefix string, typ *ast.Type, fi
|
||||
def := builder.schema.Types[typ.Name()]
|
||||
goName, ok := builder.Config.Scalars[def.Name]
|
||||
if ok {
|
||||
name, err := builder.addRef(goName)
|
||||
builder.WriteString(name)
|
||||
newName, err := builder.addRef(goName)
|
||||
builder.WriteString(newName)
|
||||
return err
|
||||
}
|
||||
goName, ok = builtinTypes[def.Name]
|
||||
@@ -303,7 +303,7 @@ func (builder *typeBuilder) writeTypedef(
|
||||
typedef *ast.Definition,
|
||||
pos *ast.Position,
|
||||
fields []field,
|
||||
options *GenqlientDirective,
|
||||
options *GenqlientDirective, //nolint:unparam // it is used!
|
||||
description string, // defaults to typedef.Description
|
||||
) (err error) {
|
||||
defer func() {
|
||||
|
||||
Reference in New Issue
Block a user