Skip to content

Commit

Permalink
Add golangci-lint
Browse files Browse the repository at this point in the history
  • Loading branch information
lucacome committed Jul 19, 2024
1 parent 9a4cdc8 commit 2e53b4e
Show file tree
Hide file tree
Showing 28 changed files with 482 additions and 254 deletions.
31 changes: 29 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,42 @@ 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', 'stable']
steps:
- name: Checkout code
- name: Checkout Repository
uses: actions/checkout@v4

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

- name: Init Hermit
run: ./bin/hermit env -r >> $GITHUB_ENV

- 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

0 comments on commit 2e53b4e

Please sign in to comment.