From eaad6116e549dc29ab302b4b3ef967812021026f Mon Sep 17 00:00:00 2001 From: Josh Komoroske Date: Sun, 14 Nov 2021 18:27:59 -0800 Subject: [PATCH] ci: lint code with golangci-lint (#11) --- .github/workflows/main.yml | 5 +++++ .golangci.yml | 8 ++++++++ main.go | 14 ++++++++------ 3 files changed, 21 insertions(+), 6 deletions(-) create mode 100644 .golangci.yml diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index a0b17c0..4d56c16 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -15,6 +15,11 @@ jobs: - name: Run commitlint uses: wagoid/commitlint-github-action@v4 + - name: Run golangci-lint + uses: golangci/golangci-lint-action@v2 + with: + version: v1.42.0 + docker: name: Docker runs-on: ubuntu-latest diff --git a/.golangci.yml b/.golangci.yml new file mode 100644 index 000000000..0548964 --- /dev/null +++ b/.golangci.yml @@ -0,0 +1,8 @@ +linters: + enable-all: true + disable: + - goerr113 + - wrapcheck + +issues: + exclude-use-default: false diff --git a/main.go b/main.go index f97f269..deae7e8 100644 --- a/main.go +++ b/main.go @@ -30,9 +30,10 @@ const exitCodeDroneSkipPipeline = 78 var errDroneSkipPipeline = errors.New("skipping pipeline") func main() { - switch err := mainCmd(); err { + switch err := mainCmd(); err { // nolint:errorlint case nil: log.Println("continuing pipeline") + return case errDroneSkipPipeline: log.Println("skipping pipeline") @@ -58,10 +59,11 @@ func mainCmd() error { if cfg.GithubToken != "" { httpClient = oauth2.NewClient(ctx, oauth2.StaticTokenSource( - &oauth2.Token{AccessToken: cfg.GithubToken}, + &oauth2.Token{AccessToken: cfg.GithubToken}, // nolint:exhaustivestruct ), ) } + client := github.NewClient(httpClient) // Get a list of all files (added, deleted, modified) that are a part of @@ -73,15 +75,15 @@ func mainCmd() error { matcher := ignore.CompileIgnoreLines(cfg.Rules...) + skip := true // Examine every file in the current pull request, and try to match it // against the set of configured plugin rules. - skip := true for _, commitFile := range commitFiles { filename := commitFile.GetFilename() - if matched, how := matcher.MatchesPathHow(filename); matched { + if matched, how := matcher.MatchesPathHow(filename); matched { // nolint:gocritic + skip = false // File was matched by a rule. log.Printf("file %s matched by rule %q\n", filename, how.Line) - skip = false } else if how != nil { // File was matched by a rule, but then negated by another. log.Printf("file %s not matched by negated rule %q\n", filename, how.Line) @@ -112,8 +114,8 @@ type config struct { } func loadConfig() (*config, error) { - // Load plugin configuration from current working environment. var cfg config + // Load plugin configuration from current working environment. err := envconfig.Process("", &cfg) if err != nil { return nil, err