Skip to content

Commit

Permalink
chore: update go, mods, workflow & linter
Browse files Browse the repository at this point in the history
  • Loading branch information
mloiseleur committed Aug 20, 2024
1 parent 368ce2e commit 162fac0
Show file tree
Hide file tree
Showing 39 changed files with 170 additions and 214 deletions.
53 changes: 0 additions & 53 deletions .github/workflows/go-cross.yml

This file was deleted.

39 changes: 39 additions & 0 deletions .github/workflows/lint.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
name: golangci

on:
pull_request:

jobs:

main:
name: lint
runs-on: ubuntu-latest
env:
GOLANGCI_LINT_VERSION: v1.60
CGO_ENABLED: 0

steps:
# https://github.com/marketplace/actions/checkout
- name: Check out code
uses: actions/checkout@v4
with:
fetch-depth: 0

# https://github.com/marketplace/actions/setup-go-environment
- name: Set up Go ${{ env.GO_VERSION }}
uses: actions/setup-go@v5
with:
go-version-file: 'go.mod'

- name: Check and get dependencies
run: |
go mod tidy
git diff --exit-code go.mod
git diff --exit-code go.sum
go mod download
# https://github.com/marketplace/actions/golangci-lint
- name: golangci-lint
uses: golangci/golangci-lint-action@v6
with:
version: ${GOLANGCI_LINT_VERSION}
54 changes: 0 additions & 54 deletions .github/workflows/main.yml

This file was deleted.

31 changes: 31 additions & 0 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
name: go

on:
pull_request:

jobs:

cross:
name: test
runs-on: ${{ matrix.os }}
env:
CGO_ENABLED: 0

strategy:
matrix:
os: [ubuntu-latest, macos-latest, windows-latest]

steps:
# https://github.com/marketplace/actions/checkout
- name: Checkout code
uses: actions/checkout@v4

# https://github.com/marketplace/actions/setup-go-environment
- name: Set up Go ${{ matrix.go-version }}
uses: actions/setup-go@v5
with:
go-version-file: 'go.mod'

- name: Test
run: go test -v -cover ./...

39 changes: 23 additions & 16 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
run:
timeout: 2m
skip-files:
- ^unsecured/

linters-settings:
depguard:
rules:
main:
deny:
- pkg: "github.com/pkg/errors"
desc: Should be replaced by standard lib errors package
govet:
check-shadowing: true
enable-all: true
disable:
- fieldalignment
Expand All @@ -15,8 +18,19 @@ linters-settings:
goconst:
min-len: 3
min-occurrences: 3
gomoddirectives:
replace-allow-list:
- github.com/imdario/mergo
misspell:
locale: US
mnd:
# List of enabled checks, see https://github.com/tommy-muehle/go-mnd/#checks for description.
checks:
- case
- condition
- operation
- return
- assign
funlen:
lines: -1
statements: 80 # default 40
Expand All @@ -31,24 +45,15 @@ linters-settings:
linters:
enable-all: true
disable:
- maligned # Deprecated
- scopelint # Deprecated
- golint # Deprecated
- interfacer # Deprecated
- exhaustivestruct # Deprecated
- ifshort # Deprecated
- varcheck # Deprecated
- deadcode # Deprecated
- structcheck # Deprecated
- nosnakecase # Deprecated
- execinquery # Deprecated
- gomnd # Deprecated
- cyclop # duplicate of gocyclo
- rowserrcheck # SQL
- sqlclosecheck # SQL
- dupl
- lll
- nestif
- gomnd
- goerr113
- err113
- wrapcheck
- nlreturn
- wsl
Expand All @@ -62,7 +67,6 @@ linters:

issues:
exclude-use-default: false
max-per-linter: 0
max-same-issues: 0
exclude:
- 'ST1000: at least one file in a package should have a package comment'
Expand All @@ -74,3 +78,6 @@ issues:
- goconst
- gosec
- maintidx
- path: 'parser/element_fill.go'
linters:
- mnd
4 changes: 1 addition & 3 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
.PHONY: clean lint lint-fix test

export GO111MODULE=on

default: lint test

test:
Expand All @@ -11,4 +9,4 @@ lint:
golangci-lint run

lint-fix:
golangci-lint run --fix
golangci-lint run --fix
10 changes: 4 additions & 6 deletions cli/commands_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ func TestCommand_AddCommand(t *testing.T) {
}

for _, test := range testCases {
test := test
t.Run(test.desc, func(t *testing.T) {
t.Parallel()

Expand Down Expand Up @@ -80,7 +79,7 @@ func TestCommand_PrintHelp(t *testing.T) {
Field string
}
}{},
Run: func(args []string) error {
Run: func(_ []string) error {
return nil
},
CustomHelpFunc: func(w io.Writer, _ *Command) error {
Expand All @@ -102,7 +101,6 @@ func TestCommand_PrintHelp(t *testing.T) {
}

for _, test := range testCases {
test := test
t.Run(test.desc, func(t *testing.T) {
t.Parallel()

Expand Down Expand Up @@ -740,7 +738,7 @@ func Test_execute_configuration(t *testing.T) {
Description: "sub1",
Configuration: element,
Resources: []ResourceLoader{&FlagLoader{}},
Run: func(args []string) error {
Run: func(_ []string) error {
return nil
},
}
Expand Down Expand Up @@ -804,7 +802,7 @@ func Test_execute_configuration_file(t *testing.T) {
Description: "sub1",
Configuration: element,
Resources: []ResourceLoader{fileLoader, &FlagLoader{}},
Run: func(args []string) error {
Run: func(_ []string) error {
return nil
},
}
Expand Down Expand Up @@ -837,7 +835,7 @@ func Test_execute_help(t *testing.T) {
Name: "root",
Description: "Description for root",
Configuration: element,
Run: func(args []string) error {
Run: func(_ []string) error {
return nil
},
}
Expand Down
1 change: 0 additions & 1 deletion cli/file_finder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,6 @@ func TestFinder_getPaths(t *testing.T) {
}

for _, test := range testCases {
test := test
t.Run(test.desc, func(t *testing.T) {
t.Parallel()

Expand Down
2 changes: 1 addition & 1 deletion cli/fixtures_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ type Yo struct {
Foo string `description:"Foo description"`
Fii string `description:"Fii description"`
Fuu string `description:"Fuu description"`
Yi *Yi `label:"allowEmpty" file:"allowEmpty"`
Yi *Yi `file:"allowEmpty" label:"allowEmpty"`
Yu *Yi
}

Expand Down
11 changes: 5 additions & 6 deletions cli/help_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ func TestPrintHelp(t *testing.T) {
Name: "root",
Description: "Description for root",
Configuration: element,
Run: func(args []string) error {
Run: func(_ []string) error {
return nil
},
}
Expand Down Expand Up @@ -85,7 +85,7 @@ Flags:
Name: "sub1",
Description: "Description for sub1",
Configuration: element,
Run: func(args []string) error {
Run: func(_ []string) error {
return nil
},
})
Expand All @@ -95,7 +95,7 @@ Flags:
Name: "sub2",
Description: "Description for sub2",
Configuration: element,
Run: func(args []string) error {
Run: func(_ []string) error {
return nil
},
})
Expand Down Expand Up @@ -149,7 +149,7 @@ Flags:
Name: "root",
Description: "Description for root",
Configuration: nil,
Run: func(args []string) error {
Run: func(_ []string) error {
return nil
},
}
Expand All @@ -173,7 +173,7 @@ Use "root [command] --help" for help on any command.
Field string
}
}{},
Run: func(args []string) error {
Run: func(_ []string) error {
return nil
},
}
Expand All @@ -197,7 +197,6 @@ Flags:
}

for _, test := range testCases {
test := test
t.Run(test.desc, func(t *testing.T) {
t.Parallel()

Expand Down
Loading

0 comments on commit 162fac0

Please sign in to comment.