From 42bbb80302a7a051ff6a435215a4dc21e68fab00 Mon Sep 17 00:00:00 2001 From: Valentine Kiselev Date: Fri, 4 Nov 2022 10:47:31 +0300 Subject: [PATCH] chore: Remove deprecated config options (#351) - [x] Remove `runner` from `commands` - [x] Remove `run` from `scripts` --- cmd/uninstall.go | 6 ------ internal/config/command.go | 11 +---------- internal/config/hook.go | 34 ---------------------------------- internal/config/load.go | 2 -- internal/config/load_test.go | 5 ++--- internal/config/script.go | 9 --------- internal/lefthook/lefthook.go | 2 +- 7 files changed, 4 insertions(+), 65 deletions(-) diff --git a/cmd/uninstall.go b/cmd/uninstall.go index dca8dc49..e1d67a25 100644 --- a/cmd/uninstall.go +++ b/cmd/uninstall.go @@ -17,12 +17,6 @@ func newUninstallCmd(opts *lefthook.Options) *cobra.Command { }, } - var deprecatedKeepConfig bool - uninstallCmd.Flags().BoolVarP( - &deprecatedKeepConfig, "keep-config", "k", false, - "DEPRECATED: This option is enabled by default. It will be removed in next release.", - ) - uninstallCmd.Flags().BoolVarP( &args.Force, "aggressive", "a", false, "DEPRECATED: will behave like -f/--force option", diff --git a/internal/config/command.go b/internal/config/command.go index c8131f20..6e9558e0 100644 --- a/internal/config/command.go +++ b/internal/config/command.go @@ -25,9 +25,6 @@ type Command struct { FailText string `mapstructure:"fail_text"` Interactive bool `mapstructure:"interactive"` - - // DEPRECATED, will be deleted in 1.2.0 - Runner string `mapstructure:"runner"` } func (c Command) Validate() error { @@ -46,8 +43,7 @@ func (c Command) DoSkip(gitState git.State) bool { } type commandRunReplace struct { - Run string `mapstructure:"run"` - Runner string `mapstructure:"runner"` // DEPRECATED, will be deleted in 1.2.0 + Run string `mapstructure:"run"` } func mergeCommands(base, extra *viper.Viper) (map[string]*Command, error) { @@ -102,11 +98,6 @@ func mergeCommands(base, extra *viper.Viper) (map[string]*Command, error) { if replace.Run != "" { commands[key].Run = strings.Replace(commands[key].Run, CMD, replace.Run, -1) } - - // Deprecated, will be deleted - if replace.Runner != "" { - commands[key].Runner = strings.Replace(commands[key].Runner, CMD, replace.Runner, -1) - } } return commands, nil diff --git a/internal/config/hook.go b/internal/config/hook.go index c474fcd1..cb8b53a6 100644 --- a/internal/config/hook.go +++ b/internal/config/hook.go @@ -6,8 +6,6 @@ import ( "strings" "github.com/spf13/viper" - - "github.com/evilmartians/lefthook/internal/log" ) const CMD = "{cmd}" @@ -77,35 +75,3 @@ func unmarshalHooks(base, extra *viper.Viper) (*Hook, error) { return &hook, nil } - -func (h Hook) processDeprecations() { - var cmdDeprecationUsed, scriptDeprecationUsed bool - - for _, command := range h.Commands { - if command.Runner != "" { - cmdDeprecationUsed = true - - if command.Run == "" { - command.Run = command.Runner - } - } - } - - for _, script := range h.Scripts { - if script.Run != "" { - scriptDeprecationUsed = true - - if script.Runner == "" { - script.Runner = script.Run - } - } - } - - if cmdDeprecationUsed { - log.Errorf("Warning: `runner` alias for commands is deprecated, use `run` instead.\n") - } - - if scriptDeprecationUsed { - log.Errorf("Warning: `run` alias for scripts is deprecated, use `runner` instead.\n") - } -} diff --git a/internal/config/load.go b/internal/config/load.go index 66563c51..a9b231be 100644 --- a/internal/config/load.go +++ b/internal/config/load.go @@ -208,8 +208,6 @@ func addHook(hookName string, base, extra *viper.Viper, c *Config) error { return nil } - resultHook.processDeprecations() - c.Hooks[hookName] = resultHook return nil diff --git a/internal/config/load_test.go b/internal/config/load_test.go index c47b5163..d5d3663f 100644 --- a/internal/config/load_test.go +++ b/internal/config/load_test.go @@ -32,7 +32,7 @@ func TestLoad(t *testing.T) { pre-commit: commands: tests: - runner: yarn test # Using deprecated field + run: yarn test `, local: ` post-commit: @@ -49,8 +49,7 @@ post-commit: Parallel: false, Commands: map[string]*Command{ "tests": { - Run: "yarn test", // copies Runner to Run - Runner: "yarn test", + Run: "yarn test", }, }, }, diff --git a/internal/config/script.go b/internal/config/script.go index f7d174e7..bf9496e2 100644 --- a/internal/config/script.go +++ b/internal/config/script.go @@ -18,9 +18,6 @@ type Script struct { FailText string `mapstructure:"fail_text"` Interactive bool `mapstructure:"interactive"` - - // DEPRECATED - Run string `mapstructure:"run"` } func (s Script) DoSkip(gitState git.State) bool { @@ -32,7 +29,6 @@ func (s Script) DoSkip(gitState git.State) bool { type scriptRunnerReplace struct { Runner string `mapstructure:"runner"` - Run string `mapstructure:"run"` // DEPRECATED } func mergeScripts(base, extra *viper.Viper) (map[string]*Script, error) { @@ -81,11 +77,6 @@ func mergeScripts(base, extra *viper.Viper) (map[string]*Script, error) { } for key, replace := range runReplaces { - // Deprecated, will be deleted - if replace.Run != "" { - scripts[key].Run = strings.Replace(scripts[key].Run, CMD, replace.Run, -1) - } - if replace.Runner != "" { scripts[key].Runner = strings.Replace(scripts[key].Runner, CMD, replace.Runner, -1) } diff --git a/internal/lefthook/lefthook.go b/internal/lefthook/lefthook.go index 2172fb94..d335ab95 100644 --- a/internal/lefthook/lefthook.go +++ b/internal/lefthook/lefthook.go @@ -21,7 +21,7 @@ type Options struct { Fs afero.Fs Verbose, NoColors bool - // DEPRECATED. + // DEPRECATED. Will be removed in 1.3.0. Force, Aggressive bool }