From 9e1d4e78553254428093d2ec6d5921fea7e158be Mon Sep 17 00:00:00 2001 From: Andrey Nering Date: Sat, 14 May 2022 21:00:15 -0300 Subject: [PATCH] Add golangci-lint https://golangci-lint.run/ --- .github/workflows/lint.yml | 24 +++++++++++++++++++++++ .github/workflows/release.yml | 4 ++-- .github/workflows/test.yml | 14 +++++++++++--- Taskfile.yml | 30 ++++++----------------------- help.go | 2 -- internal/compiler/v2/compiler_v2.go | 2 +- internal/sleepit/main.go | 6 +++--- internal/templater/templater.go | 2 +- task_test.go | 2 +- taskfile/included_taskfile.go | 2 +- taskfile/merge.go | 2 +- taskfile/var.go | 4 ++-- watch.go | 2 +- 13 files changed, 54 insertions(+), 42 deletions(-) create mode 100644 .github/workflows/lint.yml diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml new file mode 100644 index 00000000..0f837f4f --- /dev/null +++ b/.github/workflows/lint.yml @@ -0,0 +1,24 @@ +name: Lint + +on: + pull_request: + push: + tags: + - v* + branches: + - master + +jobs: + lint: + runs-on: ubuntu-latest + steps: + - uses: actions/setup-go@v3 + with: + go-version: 1.18 + + - uses: actions/checkout@v3 + + - name: golangci-lint + uses: golangci/golangci-lint-action@v3 + with: + version: v1.46.1 diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 6b82190e..61494a75 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -10,10 +10,10 @@ jobs: runs-on: ubuntu-latest steps: - name: Checkout - uses: actions/checkout@v2 + uses: actions/checkout@v3 - name: Set up Go - uses: actions/setup-go@v2 + uses: actions/setup-go@v3 with: go-version: 1.18.x diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index ccae5cb3..bd43a499 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -1,5 +1,13 @@ name: Test -on: [push, pull_request] + +on: + pull_request: + push: + tags: + - v* + branches: + - master + jobs: test: name: Test @@ -10,13 +18,13 @@ jobs: runs-on: ${{matrix.platform}} steps: - name: Set up Go ${{matrix.go-version}} - uses: actions/setup-go@v2 + uses: actions/setup-go@v3 with: go-version: ${{matrix.go-version}} id: go - name: Check out code into the Go module directory - uses: actions/checkout@v2 + uses: actions/checkout@v3 - name: Download Go modules run: go mod download diff --git a/Taskfile.yml b/Taskfile.yml index edc845f3..7e7c11b2 100644 --- a/Taskfile.yml +++ b/Taskfile.yml @@ -18,6 +18,7 @@ env: tasks: default: cmds: + - task: lint - task: test install: @@ -31,34 +32,23 @@ tasks: - go mod download - go mod tidy - cli-deps: - desc: Downloads CLI dependencies - cmds: - - task: go-get - vars: {REPO: golang.org/x/lint/golint} - - task: go-get - vars: {REPO: github.com/goreleaser/goreleaser} - - task: go-get - vars: {REPO: github.com/goreleaser/godownloader} - clean: desc: Cleans temp files and folders cmds: - rm -rf dist/ - rm -rf tmp/ - lint: - desc: Runs golint - cmds: - - golint {{catLines .GO_PACKAGES}} - silent: true - sleepit: desc: Builds the sleepit test helper dir: tmp cmds: - go build ../internal/sleepit + lint: + desc: Runs golangci-lint + cmds: + - golangci-lint run + test: desc: Runs test suite deps: [install, sleepit] @@ -76,14 +66,6 @@ tasks: - godownloader --repo go-task/task -o install-task.sh - cp ./install-task.sh ./docs/install.sh - ci: - - task: go-get - vars: {REPO: golang.org/x/lint/golint} - - task: lint - - task: test - - go-get: go get -u {{.REPO}} - packages: cmds: - echo '{{.GO_PACKAGES}}' diff --git a/help.go b/help.go index 9b9a5874..0dc99718 100644 --- a/help.go +++ b/help.go @@ -16,13 +16,11 @@ import ( // ListTasksWithDesc reports tasks that have a description spec. func (e *Executor) ListTasksWithDesc() { e.printTasks(false) - return } // ListAllTasks reports all tasks, with or without a description spec. func (e *Executor) ListAllTasks() { e.printTasks(true) - return } func (e *Executor) printTasks(listAll bool) { diff --git a/internal/compiler/v2/compiler_v2.go b/internal/compiler/v2/compiler_v2.go index 2b3970bb..376a9556 100644 --- a/internal/compiler/v2/compiler_v2.go +++ b/internal/compiler/v2/compiler_v2.go @@ -71,7 +71,7 @@ func (vr *varResolver) merge(vars *taskfile.Vars) { return } tr := templater.Templater{Vars: vr.vars} - vars.Range(func(k string, v taskfile.Var) error { + _ = vars.Range(func(k string, v taskfile.Var) error { v = taskfile.Var{ Static: tr.Replace(v.Static), Sh: tr.Replace(v.Sh), diff --git a/internal/sleepit/main.go b/internal/sleepit/main.go index 5a3433a2..a6e6bf02 100644 --- a/internal/sleepit/main.go +++ b/internal/sleepit/main.go @@ -52,7 +52,7 @@ func run(args []string) int { switch args[0] { case "default": - defaultCmd.Parse(args[1:]) + _ = defaultCmd.Parse(args[1:]) if len(defaultCmd.Args()) > 0 { fmt.Fprintf(os.Stderr, "default: unexpected arguments: %v\n", defaultCmd.Args()) return 2 @@ -60,7 +60,7 @@ func run(args []string) int { return supervisor(*defaultSleep, 0, 0, nil) case "handle": - handleCmd.Parse(args[1:]) + _ = handleCmd.Parse(args[1:]) if *handleTermAfter == 1 { fmt.Fprintf(os.Stderr, "handle: term-after cannot be 1\n") return 2 @@ -74,7 +74,7 @@ func run(args []string) int { return supervisor(*handleSleep, *handleCleanup, *handleTermAfter, sigCh) case "version": - versionCmd.Parse(args[1:]) + _ = versionCmd.Parse(args[1:]) if len(versionCmd.Args()) > 0 { fmt.Fprintf(os.Stderr, "version: unexpected arguments: %v\n", versionCmd.Args()) return 2 diff --git a/internal/templater/templater.go b/internal/templater/templater.go index f1617148..640bbe97 100644 --- a/internal/templater/templater.go +++ b/internal/templater/templater.go @@ -68,7 +68,7 @@ func (r *Templater) ReplaceVars(vars *taskfile.Vars) *taskfile.Vars { } var new taskfile.Vars - vars.Range(func(k string, v taskfile.Var) error { + _ = vars.Range(func(k string, v taskfile.Var) error { new.Set(k, taskfile.Var{ Static: r.Replace(v.Static), Live: v.Live, diff --git a/task_test.go b/task_test.go index 9f5165eb..a6a47b76 100644 --- a/task_test.go +++ b/task_test.go @@ -592,7 +592,7 @@ func TestStatusVariables(t *testing.T) { inf, err := os.Stat(filepath.Join(dir, "source.txt")) assert.NoError(t, err) ts := fmt.Sprintf("%d", inf.ModTime().Unix()) - tf := fmt.Sprintf("%s", inf.ModTime()) + tf := inf.ModTime().String() assert.Contains(t, buff.String(), ts) assert.Contains(t, buff.String(), tf) diff --git a/taskfile/included_taskfile.go b/taskfile/included_taskfile.go index 332f986e..744dca02 100644 --- a/taskfile/included_taskfile.go +++ b/taskfile/included_taskfile.go @@ -53,7 +53,7 @@ func (tfs *IncludedTaskfiles) Len() int { // Merge merges the given IncludedTaskfiles into the caller one func (tfs *IncludedTaskfiles) Merge(other *IncludedTaskfiles) { - other.Range(func(key string, value IncludedTaskfile) error { + _ = other.Range(func(key string, value IncludedTaskfile) error { tfs.Set(key, value) return nil }) diff --git a/taskfile/merge.go b/taskfile/merge.go index 4bab0e23..a5731c71 100644 --- a/taskfile/merge.go +++ b/taskfile/merge.go @@ -11,7 +11,7 @@ const NamespaceSeparator = ":" // Merge merges the second Taskfile into the first func Merge(t1, t2 *Taskfile, namespaces ...string) error { if t1.Version != t2.Version { - return fmt.Errorf(`Taskfiles versions should match. First is "%s" but second is "%s"`, t1.Version, t2.Version) + return fmt.Errorf(`task: Taskfiles versions should match. First is "%s" but second is "%s"`, t1.Version, t2.Version) } if t2.Expansions != 0 && t2.Expansions != 2 { diff --git a/taskfile/var.go b/taskfile/var.go index fbda3895..2693444f 100644 --- a/taskfile/var.go +++ b/taskfile/var.go @@ -36,7 +36,7 @@ func (vs *Vars) UnmarshalYAML(node *yaml.Node) error { // Merge merges the given Vars into the caller one func (vs *Vars) Merge(other *Vars) { - other.Range(func(key string, value Var) error { + _ = other.Range(func(key string, value Var) error { vs.Set(key, value) return nil }) @@ -70,7 +70,7 @@ func (vs *Vars) Range(yield func(key string, value Var) error) error { // variables func (vs *Vars) ToCacheMap() (m map[string]interface{}) { m = make(map[string]interface{}, vs.Len()) - vs.Range(func(k string, v Var) error { + _ = vs.Range(func(k string, v Var) error { if v.Sh != "" { // Dynamic variable is not yet resolved; trigger // to be used in templates. diff --git a/watch.go b/watch.go index b5e443c8..78ca06d9 100644 --- a/watch.go +++ b/watch.go @@ -97,7 +97,7 @@ func isContextError(err error) bool { func closeOnInterrupt(w *watcher.Watcher) { ch := make(chan os.Signal, 1) - signal.Notify(ch, os.Interrupt, os.Kill, syscall.SIGTERM) + signal.Notify(ch, os.Interrupt, syscall.SIGTERM) go func() { <-ch w.Close()