Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add golangci-lint #354

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 28 additions & 4 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,39 @@ on:
branches:
- master
pull_request:

name: CI
jobs:
test:
name: Test
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
go-version: ["1.17", "1.18", "1.19", "1.20", "1.21", "1.22", "stable"]
steps:
- name: Checkout code
- name: Checkout Repository
uses: actions/checkout@v4
- name: Init Hermit
run: ./bin/hermit env -r >> $GITHUB_ENV

- name: Setup Golang Environment
uses: actions/setup-go@v5
with:
go-version: ${{ matrix.go-version }}

- name: Test
run: go test ./...
run: go test ./... -race -shuffle=on -v

lint:
name: Go Lint
runs-on: ubuntu-latest
steps:
- name: Checkout Repository
uses: actions/checkout@v4

- name: Setup Golang Environment
uses: actions/setup-go@v5
with:
go-version: stable

- name: Lint Go
uses: golangci/golangci-lint-action@v6
56 changes: 56 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
linters-settings:
misspell:
locale: US
govet:
enable-all: true
linters:
enable:
- asasalint
- asciicheck
- bidichk
- contextcheck
- dupword
- durationcheck
- errchkjson
- errname
- exportloopref
- fatcontext
- gocheckcompilerdirectives
- gochecksumtype
- gocritic
- godot
- gofmt
- gofumpt
- goimports
- gosec
- gosimple
- gosmopolitan
- govet
- ineffassign
- makezero
- misspell
- musttag
- nilerr
- noctx
- nolintlint
- paralleltest
- prealloc
- predeclared
- reassign
- staticcheck
- tagalign
- tenv
- thelper
- tparallel
- typecheck
- unparam
- unused
- usestdlibvars
- wastedassign
- whitespace
disable-all: true
issues:
max-issues-per-linter: 0
max-same-issues: 0
run:
timeout: 5m
50 changes: 20 additions & 30 deletions app.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,41 +11,32 @@ import (

var (
ErrCommandNotSpecified = fmt.Errorf("command not specified")
)

var (
envarTransformRegexp = regexp.MustCompile(`[^a-zA-Z0-9_]+`)
envarTransformRegexp = regexp.MustCompile(`[^a-zA-Z0-9_]+`)
)

type ApplicationValidator func(*Application) error

// An Application contains the definitions of flags, arguments and commands
// for an application.
type Application struct {
errorWriter io.Writer
usageWriter io.Writer
usageFuncs template.FuncMap
VersionFlag *FlagClause
HelpCommand *CmdClause
HelpFlag *FlagClause
terminate func(status int)
validator ApplicationValidator
usageTemplate string
version string
author string
Help string
Name string
cmdMixin
initialized bool

Name string
Help string

author string
version string
errorWriter io.Writer // Destination for errors.
usageWriter io.Writer // Destination for usage
usageTemplate string
usageFuncs template.FuncMap
validator ApplicationValidator
terminate func(status int) // See Terminate()
noInterspersed bool // can flags be interspersed with args (or must they come first)
noInterspersed bool
defaultEnvars bool
completion bool

// Help flag. Exposed for user customisation.
HelpFlag *FlagClause
// Help command. Exposed for user customisation. May be nil.
HelpCommand *CmdClause
// Version flag. Exposed for user customisation. May be nil.
VersionFlag *FlagClause
initialized bool
}

// New creates a new Kingpin application instance.
Expand Down Expand Up @@ -129,7 +120,7 @@ func (a *Application) Terminate(terminate func(int)) *Application {
}

// Writer specifies the writer to use for usage and errors. Defaults to os.Stderr.
// DEPRECATED: See ErrorWriter and UsageWriter.
// Deprecated: See ErrorWriter and UsageWriter.
func (a *Application) Writer(w io.Writer) *Application {
a.errorWriter = w
a.usageWriter = w
Expand Down Expand Up @@ -189,9 +180,8 @@ func (a *Application) parseContext(ignoreDefault bool, args []string) (*ParseCon
// This will populate all flag and argument values, call all callbacks, and so
// on.
func (a *Application) Parse(args []string) (command string, err error) {

context, parseErr := a.ParseContext(args)
selected := []string{}
var selected []string
var setValuesErr error

if context == nil {
Expand Down Expand Up @@ -239,8 +229,8 @@ func (a *Application) writeUsage(context *ParseContext, err error) {
if err != nil {
a.Errorf("%s", err)
}
if err := a.UsageForContext(context); err != nil {
panic(err)
if errUsage := a.UsageForContext(context); errUsage != nil {
panic(errUsage)
}
if err != nil {
a.terminate(1)
Expand Down
Loading
Loading