Skip to content

Commit

Permalink
chore: Remove deprecated config options (#351)
Browse files Browse the repository at this point in the history
- [x] Remove `runner` from `commands`
- [x] Remove `run` from `scripts`
  • Loading branch information
mrexox committed Nov 4, 2022
1 parent 71817fa commit 42bbb80
Show file tree
Hide file tree
Showing 7 changed files with 4 additions and 65 deletions.
6 changes: 0 additions & 6 deletions cmd/uninstall.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
11 changes: 1 addition & 10 deletions internal/config/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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) {
Expand Down Expand Up @@ -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
Expand Down
34 changes: 0 additions & 34 deletions internal/config/hook.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ import (
"strings"

"github.com/spf13/viper"

"github.com/evilmartians/lefthook/internal/log"
)

const CMD = "{cmd}"
Expand Down Expand Up @@ -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")
}
}
2 changes: 0 additions & 2 deletions internal/config/load.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 2 additions & 3 deletions internal/config/load_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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",
},
},
},
Expand Down
9 changes: 0 additions & 9 deletions internal/config/script.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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) {
Expand Down Expand Up @@ -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)
}
Expand Down
2 changes: 1 addition & 1 deletion internal/lefthook/lefthook.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down

0 comments on commit 42bbb80

Please sign in to comment.