Files
genqlient/.golangci.yml
T
Ben KraftandGitHub dc38360d9d Add a flag --init to write a default config (#81)
## Summary:
Steve pointed out (#73) that having genqlient with no arguments silently
use a default config file was a bit confusing, and changed it to use
`genqlient.yaml` by default (#74).  Mark pointed out (#76) that this
makes it a bit less convenient when you're starting from scratch; you
have to go create a config file.  In this commit I add a new init flag
that creates you a config file before using it.

Originally the suggestion was to use subcommands, e.g. we'd have
`genqlient init` and `genqlient generate` and so on.  But I couldn't
think of anything else we might want subcommands for in the future, and
it felt a little silly to make you type `generate` each time.  So
instead, I made it a flag, which has the nice property that you can do
`genqlient --init` and it will generate and then use a config file.  (I
mean, maybe it will immediately crash because you don't have a schema,
but hopefully that's still a useful clue as to what to do next!)  The
implmentation was fairly trivial.

Since we now have a nice way to generate a default config, I removed the
default values for most of the options; I've always felt they were
probably more confusing than helpful.  (And indeed, all the users I know
of (Khan/webapp, and the much smaller project Steve was working on, are
setting those options explicitly.)  This required a slight change to
the syntax to say "don't use context", which is probably also net clearer.

I decided this is also a good time to pull in a proper CLI parser (#31);
see ADR-504 for more on that choice.  This also adds some nice help
messages!

Fixes #76, #31.

Issue: https://github.com/Khan/genqlient/issues/76

## Test plan:
```
go run .
go run . --init
go run . --init example/genqlient.yaml     # refuses to clobber
go run . --init example/newgenqlient.yaml
```


Author: benjaminjkraft

Reviewers: dnerdy, aberkan, MiguelCastillo, StevenACoffman

Required Reviewers: 

Approved By: dnerdy

Checks:  Test (1.17),  Test (1.16),  Test (1.15),  Test (1.14),  Lint,  Test (1.17),  Test (1.16),  Test (1.15),  Test (1.14),  Lint

Pull Request URL: https://github.com/Khan/genqlient/pull/81
2021-09-10 15:49:54 -07:00

104 lines
2.6 KiB
YAML

# For the full list of configuration options, see
# https://github.com/golangci/golangci-lint#config-file
# See more about these linters at https://golangci-lint.run/usage/linters/
linters:
fast: false
disable-all: true
enable:
# golangci enables these by default.
- deadcode
- errcheck
- gofumpt # (replaces gofmt)
- gosimple
- govet
- ineffassign
- staticcheck
- structcheck
- typecheck
- unused
- varcheck
# golangci disables these by default, but we use them.
- bodyclose
- depguard
- durationcheck
- errorlint
- exportloopref
- gocritic
- nakedret
- stylecheck
- unconvert
- unparam
- whitespace
linters-settings:
errcheck:
check-type-assertions: true # check for a := b.(T)
errorlint:
errorf: false # it's valid to use %v instead of %w
govet:
check-shadowing: true
enable-all: true
# We have a ton of test-only packages; but make sure we keep prod deps small.
depguard:
list-type: whitelist
packages:
- github.com/Khan/genqlient
- github.com/vektah/gqlparser/v2
- golang.org/x/tools
- gopkg.in/yaml.v2
- github.com/alexflint/go-arg
gocritic:
# Which checks should be enabled:
# See https://go-critic.github.io/overview#checks-overview
# and https://github.com/go-critic/go-critic#usage -> section "Tags".
# To check which checks are enabled: `GL_DEBUG=gocritic golangci-lint run`
enabled-tags:
- diagnostic
- performance
- style
disabled-checks:
- builtinShadow
- commentedOutCode
- importShadow
- paramTypeCombine
- unnamedResult
- ifElseChain
- sloppyReassign
- typeDefFirst
settings: # settings passed to gocritic
captLocal: # must be valid enabled check name
paramsOnly: true
issues:
exclude-rules:
# Test-only deps are not restricted.
- linters:
- depguard
path: _test\.go$|internal/testutil/|internal/integration/
- linters:
- errcheck
path: _test\.go$
# Unchecked type-asserts are ok in tests -- a panic will be plenty clear.
# An error message with no function name means an unchecked type-assert.
text: "^Error return value is not checked$"
# Don't error if a test setup function always takes the same arguments.
- linters:
- unparam
path: _test\.go$
- linters:
- govet
# Only a big deal for runtime code.
path: ^generate/|^example/
text: "^fieldalignment: struct with \\d+ pointer bytes could be \\d+$"