Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: fix linter issues #537

Merged
merged 2 commits into from
Aug 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ jobs:
- name: Install Go
uses: actions/setup-go@v2
with:
go-version: 1.19.x
go-version: 1.21.x
- uses: actions/checkout@v3
- name: golangci-lint
uses: golangci/golangci-lint-action@v3
with:
version: v1.50.1
version: v1.54.1
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ jobs:
- name: Set up Go
uses: actions/setup-go@v2
with:
go-version: 1.19
go-version: 1.21.x

- name: Install Snapcraft
uses: samuelmeuli/action-snapcraft@v1
Expand Down
5 changes: 4 additions & 1 deletion .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ linters-settings:
locale: US
gci:
local-prefixes: github.com/evilmartians/lefthook
revive:
rules:
- name: unused-parameter
disabled: true

linters:
disable-all: true
Expand All @@ -16,7 +20,6 @@ linters:
- containedctx
- contextcheck
- decorder
- depguard
- dogsled
- dupl
- dupword
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ bench:

bin/golangci-lint:
@test -x $$(go env GOPATH)/bin/golangci-lint || \
curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $$(go env GOPATH)/bin v1.50.1
curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $$(go env GOPATH)/bin v1.54.1

lint: bin/golangci-lint
$$(go env GOPATH)/bin/golangci-lint run
Expand Down
2 changes: 1 addition & 1 deletion cmd/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"github.com/evilmartians/lefthook/internal/version"
)

func newVersionCmd(opts *lefthook.Options) *cobra.Command {
func newVersionCmd(_opts *lefthook.Options) *cobra.Command {
var verbose bool

versionCmd := cobra.Command{
Expand Down
31 changes: 10 additions & 21 deletions internal/config/load.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,9 @@ func readOne(fs afero.Fs, path string, names []string) (*viper.Viper, error) {
var notFoundErr viper.ConfigFileNotFoundError
if ok := errors.As(err, &notFoundErr); ok {
continue
} else {
return nil, err
}

return nil, err
}

return v, nil
Expand Down Expand Up @@ -159,11 +159,7 @@ func mergeRemote(fs afero.Fs, repo *git.Repository, v *viper.Viper) error {
}

// Reset extends to omit issues when extending with remote extends.
if err := v.MergeConfigMap(map[string]interface{}{"extends": nil}); err != nil {
return err
}

return nil
return v.MergeConfigMap(map[string]interface{}{"extends": nil})
}

// extend merges all files listed in 'extends' option into the config.
Expand All @@ -186,23 +182,19 @@ func merge(name, path string, v *viper.Viper) error {
if len(path) > 0 {
v.SetConfigFile(path)
}
if err := v.MergeInConfig(); err != nil {
return err
}

return nil
return v.MergeInConfig()
}

func mergeOne(names []string, path string, v *viper.Viper) error {
for _, name := range names {
err := merge(name, path, v)
if err == nil {
break
} else {
var notFoundErr viper.ConfigFileNotFoundError
if ok := errors.As(err, &notFoundErr); !ok {
return err
}
}

var notFoundErr viper.ConfigFileNotFoundError
if ok := errors.As(err, &notFoundErr); !ok {
return err
}
}

Expand Down Expand Up @@ -241,11 +233,8 @@ func unmarshalConfigs(base, extra *viper.Viper, c *Config) error {
if err := base.MergeConfigMap(extra.AllSettings()); err != nil {
return err
}
if err := base.Unmarshal(c); err != nil {
return err
}

return nil
return base.Unmarshal(c)
}

func addHook(hookName string, base, extra *viper.Viper, c *Config) error {
Expand Down
6 changes: 1 addition & 5 deletions internal/config/script.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,9 +128,5 @@ func unmarshalScripts(s map[string]interface{}) (map[string]*Script, error) {
// This is not an expected behavior and cannot be controlled yet
// Working with GetStringMap is the only way to get the structure "as is".
func unmarshal(input, output interface{}) error {
if err := mapstructure.WeakDecode(input, &output); err != nil {
return err
}

return nil
return mapstructure.WeakDecode(input, &output)
}
12 changes: 2 additions & 10 deletions internal/git/remote.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,18 +50,10 @@ func (r *Repository) SyncRemote(url, ref string) error {

_, err = r.Fs.Stat(remotePath)
if err == nil {
if err := r.updateRemote(remotePath, ref); err != nil {
return err
}

return nil
return r.updateRemote(remotePath, ref)
}

if err := r.cloneRemote(remotesPath, url, ref); err != nil {
return err
}

return nil
return r.cloneRemote(remotesPath, url, ref)
}

func (r *Repository) updateRemote(path, ref string) error {
Expand Down
6 changes: 1 addition & 5 deletions internal/lefthook/lefthook.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,11 +90,7 @@ func (l *Lefthook) cleanHook(hook string, force bool) error {

// Just remove lefthook hook
if l.isLefthookFile(hookPath) {
if err = l.Fs.Remove(hookPath); err != nil {
return err
}

return nil
return l.Fs.Remove(hookPath)
}

// Check if .old file already exists before renaming.
Expand Down
8 changes: 4 additions & 4 deletions internal/lefthook/run_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,19 @@ import (

type GitMock struct{}

func (g GitMock) Cmd(cmd string) (string, error) {
func (g GitMock) Cmd(_cmd string) (string, error) {
return "", nil
}

func (g GitMock) CmdArgs(args ...string) (string, error) {
func (g GitMock) CmdArgs(_args ...string) (string, error) {
return "", nil
}

func (g GitMock) CmdLines(cmd string) ([]string, error) {
func (g GitMock) CmdLines(_cmd string) ([]string, error) {
return nil, nil
}

func (g GitMock) RawCmd(cmd string) (string, error) {
func (g GitMock) RawCmd(_cmd string) (string, error) {
return "", nil
}

Expand Down
1 change: 0 additions & 1 deletion internal/lefthook/runner/runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,6 @@ func (r *Runner) runCommands() {
if len(r.RunOnlyCommands) == 0 || slices.Contains(r.RunOnlyCommands, name) {
commands = append(commands, name)
}

}

sort.Strings(commands)
Expand Down
4 changes: 2 additions & 2 deletions internal/lefthook/runner/runner_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import (

type TestExecutor struct{}

func (e TestExecutor) Execute(opts ExecuteOptions, out io.Writer) (err error) {
func (e TestExecutor) Execute(opts ExecuteOptions, _out io.Writer) (err error) {
if opts.args[0] == "success" {
err = nil
} else {
Expand All @@ -28,7 +28,7 @@ func (e TestExecutor) Execute(opts ExecuteOptions, out io.Writer) (err error) {
return
}

func (e TestExecutor) RawExecute(command []string, out io.Writer) error {
func (e TestExecutor) RawExecute(_command []string, _out io.Writer) error {
return nil
}

Expand Down
6 changes: 1 addition & 5 deletions internal/lefthook/uninstall.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,7 @@ func (l *Lefthook) Uninstall(args *UninstallArgs) error {
}
}

if err := l.Fs.RemoveAll(l.repo.RemotesFolder()); err != nil {
return err
}

return nil
return l.Fs.RemoveAll(l.repo.RemotesFolder())
}

func (l *Lefthook) deleteHooks(force bool) error {
Expand Down
Loading