1
0
mirror of https://github.com/go-task/task.git synced 2025-06-04 23:38:05 +02:00

Merge pull request #729 from go-task/add-staticcheck

Add golangci-lint
This commit is contained in:
Andrey Nering 2022-05-16 09:34:14 -03:00 committed by GitHub
commit 1d355d74ef
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
13 changed files with 54 additions and 42 deletions

24
.github/workflows/lint.yml vendored Normal file
View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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}}'

View File

@ -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) {

View File

@ -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),

View File

@ -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

View File

@ -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,

View File

@ -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)

View File

@ -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
})

View File

@ -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 {

View File

@ -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
// <no value> to be used in templates.

View File

@ -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()