1
1
mirror of https://github.com/joshdk/drone-skip-pipeline synced 2024-11-22 13:41:57 +01:00

ci: lint code with golangci-lint (#11)

This commit is contained in:
Josh Komoroske 2021-11-14 18:27:59 -08:00 committed by GitHub
parent d6844517de
commit eaad6116e5
Signed by: GitHub
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 21 additions and 6 deletions

@ -15,6 +15,11 @@ jobs:
- name: Run commitlint - name: Run commitlint
uses: wagoid/commitlint-github-action@v4 uses: wagoid/commitlint-github-action@v4
- name: Run golangci-lint
uses: golangci/golangci-lint-action@v2
with:
version: v1.42.0
docker: docker:
name: Docker name: Docker
runs-on: ubuntu-latest runs-on: ubuntu-latest

8
.golangci.yml Normal file

@ -0,0 +1,8 @@
linters:
enable-all: true
disable:
- goerr113
- wrapcheck
issues:
exclude-use-default: false

14
main.go

@ -30,9 +30,10 @@ const exitCodeDroneSkipPipeline = 78
var errDroneSkipPipeline = errors.New("skipping pipeline") var errDroneSkipPipeline = errors.New("skipping pipeline")
func main() { func main() {
switch err := mainCmd(); err { switch err := mainCmd(); err { // nolint:errorlint
case nil: case nil:
log.Println("continuing pipeline") log.Println("continuing pipeline")
return return
case errDroneSkipPipeline: case errDroneSkipPipeline:
log.Println("skipping pipeline") log.Println("skipping pipeline")
@ -58,10 +59,11 @@ func mainCmd() error {
if cfg.GithubToken != "" { if cfg.GithubToken != "" {
httpClient = oauth2.NewClient(ctx, httpClient = oauth2.NewClient(ctx,
oauth2.StaticTokenSource( oauth2.StaticTokenSource(
&oauth2.Token{AccessToken: cfg.GithubToken}, &oauth2.Token{AccessToken: cfg.GithubToken}, // nolint:exhaustivestruct
), ),
) )
} }
client := github.NewClient(httpClient) client := github.NewClient(httpClient)
// Get a list of all files (added, deleted, modified) that are a part of // 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...) matcher := ignore.CompileIgnoreLines(cfg.Rules...)
skip := true
// Examine every file in the current pull request, and try to match it // Examine every file in the current pull request, and try to match it
// against the set of configured plugin rules. // against the set of configured plugin rules.
skip := true
for _, commitFile := range commitFiles { for _, commitFile := range commitFiles {
filename := commitFile.GetFilename() 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. // File was matched by a rule.
log.Printf("file %s matched by rule %q\n", filename, how.Line) log.Printf("file %s matched by rule %q\n", filename, how.Line)
skip = false
} else if how != nil { } else if how != nil {
// File was matched by a rule, but then negated by another. // 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) 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) { func loadConfig() (*config, error) {
// Load plugin configuration from current working environment.
var cfg config var cfg config
// Load plugin configuration from current working environment.
err := envconfig.Process("", &cfg) err := envconfig.Process("", &cfg)
if err != nil { if err != nil {
return nil, err return nil, err