diff --git a/.golangci.yml b/.golangci.yml index f21a2856..fe8c4d96 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -6,7 +6,12 @@ linters: enable: - goimports + - gofmt linters-settings: goimports: local-prefixes: github.com/go-task/task + gofmt: + rewrite-rules: + - pattern: 'interface{}' + replacement: 'any' diff --git a/args/args_test.go b/args/args_test.go index 80638c55..cb007b02 100644 --- a/args/args_test.go +++ b/args/args_test.go @@ -34,9 +34,9 @@ func TestArgsV3(t *testing.T) { ExpectedGlobals: &taskfile.Vars{ Keys: []string{"FOO", "BAR", "BAZ"}, Mapping: map[string]taskfile.Var{ - "FOO": taskfile.Var{Static: "bar"}, - "BAR": taskfile.Var{Static: "baz"}, - "BAZ": taskfile.Var{Static: "foo"}, + "FOO": {Static: "bar"}, + "BAR": {Static: "baz"}, + "BAZ": {Static: "foo"}, }, }, }, @@ -48,7 +48,7 @@ func TestArgsV3(t *testing.T) { ExpectedGlobals: &taskfile.Vars{ Keys: []string{"CONTENT"}, Mapping: map[string]taskfile.Var{ - "CONTENT": taskfile.Var{Static: "with some spaces"}, + "CONTENT": {Static: "with some spaces"}, }, }, }, @@ -125,7 +125,7 @@ func TestArgsV2(t *testing.T) { Vars: &taskfile.Vars{ Keys: []string{"FOO"}, Mapping: map[string]taskfile.Var{ - "FOO": taskfile.Var{Static: "bar"}, + "FOO": {Static: "bar"}, }, }, }, @@ -135,8 +135,8 @@ func TestArgsV2(t *testing.T) { Vars: &taskfile.Vars{ Keys: []string{"BAR", "BAZ"}, Mapping: map[string]taskfile.Var{ - "BAR": taskfile.Var{Static: "baz"}, - "BAZ": taskfile.Var{Static: "foo"}, + "BAR": {Static: "baz"}, + "BAZ": {Static: "foo"}, }, }, }, @@ -150,7 +150,7 @@ func TestArgsV2(t *testing.T) { Vars: &taskfile.Vars{ Keys: []string{"CONTENT"}, Mapping: map[string]taskfile.Var{ - "CONTENT": taskfile.Var{Static: "with some spaces"}, + "CONTENT": {Static: "with some spaces"}, }, }, }, diff --git a/internal/fingerprint/checker.go b/internal/fingerprint/checker.go index ba1a5289..4cdc7e8d 100644 --- a/internal/fingerprint/checker.go +++ b/internal/fingerprint/checker.go @@ -14,7 +14,7 @@ type StatusCheckable interface { // SourcesCheckable defines any type that can check if the sources of a task are up-to-date. type SourcesCheckable interface { IsUpToDate(t *taskfile.Task) (bool, error) - Value(t *taskfile.Task) (interface{}, error) + Value(t *taskfile.Task) (any, error) OnError(t *taskfile.Task) error Kind() string } diff --git a/internal/fingerprint/checker_mock.go b/internal/fingerprint/checker_mock.go index eb10670f..fbafd4a7 100644 --- a/internal/fingerprint/checker_mock.go +++ b/internal/fingerprint/checker_mock.go @@ -1,5 +1,5 @@ // Code generated by MockGen. DO NOT EDIT. -// Source: checker.go +// Source: internal/fingerprint/checker.go // Package fingerprint is a generated GoMock package. package fingerprint @@ -117,10 +117,10 @@ func (mr *MockSourcesCheckableMockRecorder) OnError(t interface{}) *gomock.Call } // Value mocks base method. -func (m *MockSourcesCheckable) Value(t *taskfile.Task) (interface{}, error) { +func (m *MockSourcesCheckable) Value(t *taskfile.Task) (any, error) { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "Value", t) - ret0, _ := ret[0].(interface{}) + ret0, _ := ret[0].(any) ret1, _ := ret[1].(error) return ret0, ret1 } diff --git a/internal/fingerprint/sources_checksum.go b/internal/fingerprint/sources_checksum.go index 64e57f3f..da6f50d3 100644 --- a/internal/fingerprint/sources_checksum.go +++ b/internal/fingerprint/sources_checksum.go @@ -68,7 +68,7 @@ func (checker *ChecksumChecker) IsUpToDate(t *taskfile.Task) (bool, error) { return oldMd5 == newMd5, nil } -func (checker *ChecksumChecker) Value(t *taskfile.Task) (interface{}, error) { +func (checker *ChecksumChecker) Value(t *taskfile.Task) (any, error) { return checker.checksum(t) } diff --git a/internal/fingerprint/sources_none.go b/internal/fingerprint/sources_none.go index 8fd955fb..dbbf55f8 100644 --- a/internal/fingerprint/sources_none.go +++ b/internal/fingerprint/sources_none.go @@ -10,7 +10,7 @@ func (NoneChecker) IsUpToDate(t *taskfile.Task) (bool, error) { return false, nil } -func (NoneChecker) Value(t *taskfile.Task) (interface{}, error) { +func (NoneChecker) Value(t *taskfile.Task) (any, error) { return "", nil } diff --git a/internal/fingerprint/sources_timestamp.go b/internal/fingerprint/sources_timestamp.go index 92dd4540..2d53d78f 100644 --- a/internal/fingerprint/sources_timestamp.go +++ b/internal/fingerprint/sources_timestamp.go @@ -89,7 +89,7 @@ func (checker *TimestampChecker) Kind() string { } // Value implements the Checker Interface -func (checker *TimestampChecker) Value(t *taskfile.Task) (interface{}, error) { +func (checker *TimestampChecker) Value(t *taskfile.Task) (any, error) { sources, err := globs(t.Dir, t.Sources) if err != nil { return time.Now(), err diff --git a/internal/logger/logger.go b/internal/logger/logger.go index 42b6d453..b695325f 100644 --- a/internal/logger/logger.go +++ b/internal/logger/logger.go @@ -9,7 +9,7 @@ import ( ) type Color func() PrintFunc -type PrintFunc func(io.Writer, string, ...interface{}) +type PrintFunc func(io.Writer, string, ...any) func Default() PrintFunc { return color.New(envColor("TASK_COLOR_RESET", color.Reset)).FprintfFunc() @@ -56,14 +56,14 @@ type Logger struct { } // Outf prints stuff to STDOUT. -func (l *Logger) Outf(color Color, s string, args ...interface{}) { +func (l *Logger) Outf(color Color, s string, args ...any) { l.FOutf(l.Stdout, color, s+"\n", args...) } // FOutf prints stuff to the given writer. -func (l *Logger) FOutf(w io.Writer, color Color, s string, args ...interface{}) { +func (l *Logger) FOutf(w io.Writer, color Color, s string, args ...any) { if len(args) == 0 { - s, args = "%s", []interface{}{s} + s, args = "%s", []any{s} } if !l.Color { color = Default @@ -73,16 +73,16 @@ func (l *Logger) FOutf(w io.Writer, color Color, s string, args ...interface{}) } // VerboseOutf prints stuff to STDOUT if verbose mode is enabled. -func (l *Logger) VerboseOutf(color Color, s string, args ...interface{}) { +func (l *Logger) VerboseOutf(color Color, s string, args ...any) { if l.Verbose { l.Outf(color, s, args...) } } // Errf prints stuff to STDERR. -func (l *Logger) Errf(color Color, s string, args ...interface{}) { +func (l *Logger) Errf(color Color, s string, args ...any) { if len(args) == 0 { - s, args = "%s", []interface{}{s} + s, args = "%s", []any{s} } if !l.Color { color = Default @@ -92,7 +92,7 @@ func (l *Logger) Errf(color Color, s string, args ...interface{}) { } // VerboseErrf prints stuff to STDERR if verbose mode is enabled. -func (l *Logger) VerboseErrf(color Color, s string, args ...interface{}) { +func (l *Logger) VerboseErrf(color Color, s string, args ...any) { if l.Verbose { l.Errf(color, s, args...) } diff --git a/internal/templater/templater.go b/internal/templater/templater.go index 640bbe97..46ff5eb0 100644 --- a/internal/templater/templater.go +++ b/internal/templater/templater.go @@ -16,7 +16,7 @@ type Templater struct { Vars *taskfile.Vars RemoveNoValue bool - cacheMap map[string]interface{} + cacheMap map[string]any err error } diff --git a/taskfile/precondition_test.go b/taskfile/precondition_test.go index 0d92832e..25c19867 100644 --- a/taskfile/precondition_test.go +++ b/taskfile/precondition_test.go @@ -12,8 +12,8 @@ import ( func TestPreconditionParse(t *testing.T) { tests := []struct { content string - v interface{} - expected interface{} + v any + expected any }{ { "test -f foo.txt", diff --git a/taskfile/taskfile_test.go b/taskfile/taskfile_test.go index bb29d350..18f9c66d 100644 --- a/taskfile/taskfile_test.go +++ b/taskfile/taskfile_test.go @@ -24,8 +24,8 @@ vars: ) tests := []struct { content string - v interface{} - expected interface{} + v any + expected any }{ { yamlCmd, @@ -38,8 +38,8 @@ vars: &taskfile.Cmd{Task: "another-task", Vars: &taskfile.Vars{ Keys: []string{"PARAM1", "PARAM2"}, Mapping: map[string]taskfile.Var{ - "PARAM1": taskfile.Var{Static: "VALUE1"}, - "PARAM2": taskfile.Var{Static: "VALUE2"}, + "PARAM1": {Static: "VALUE1"}, + "PARAM2": {Static: "VALUE2"}, }, }}, }, @@ -54,7 +54,7 @@ vars: &taskfile.Cmd{Task: "some_task", Vars: &taskfile.Vars{ Keys: []string{"PARAM1"}, Mapping: map[string]taskfile.Var{ - "PARAM1": taskfile.Var{Static: "var"}, + "PARAM1": {Static: "var"}, }, }, Defer: true}, }, @@ -69,8 +69,8 @@ vars: &taskfile.Dep{Task: "another-task", Vars: &taskfile.Vars{ Keys: []string{"PARAM1", "PARAM2"}, Mapping: map[string]taskfile.Var{ - "PARAM1": taskfile.Var{Static: "VALUE1"}, - "PARAM2": taskfile.Var{Static: "VALUE2"}, + "PARAM1": {Static: "VALUE1"}, + "PARAM2": {Static: "VALUE2"}, }, }}, }, diff --git a/taskfile/var.go b/taskfile/var.go index b9403bd5..e84ce8e8 100644 --- a/taskfile/var.go +++ b/taskfile/var.go @@ -82,8 +82,8 @@ func (vs *Vars) Range(yield func(key string, value Var) error) error { // ToCacheMap converts Vars to a map containing only the static // variables -func (vs *Vars) ToCacheMap() (m map[string]interface{}) { - m = make(map[string]interface{}, vs.Len()) +func (vs *Vars) ToCacheMap() (m map[string]any) { + m = make(map[string]any, vs.Len()) _ = vs.Range(func(k string, v Var) error { if v.Sh != "" { // Dynamic variable is not yet resolved; trigger @@ -112,7 +112,7 @@ func (vs *Vars) Len() int { // Var represents either a static or dynamic variable. type Var struct { Static string - Live interface{} + Live any Sh string Dir string }