Skip to content

Commit c596d27

Browse files
committed
refactor: fixing lint issues
1 parent 0860614 commit c596d27

File tree

9 files changed

+17
-15
lines changed

9 files changed

+17
-15
lines changed

.golangci.yml

+3-3
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,7 @@ run:
44
linters:
55
enable-all: true
66
disable:
7-
- wsl
8-
- lll
7+
- exhaustive
98
- funlen
109
- gci
1110
- gochecknoglobals
@@ -19,9 +18,10 @@ linters:
1918
- goimports
2019
- gomnd
2120
- gosec
21+
- lll
2222
- maligned
2323
- nestif
2424
- nlreturn
2525
- noctx
2626
- scopelint
27-
- stylecheck
27+
- wsl

internal/core/handler.go

+1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import (
1313
"github.com/groupe-edf/watchdog/internal/logging"
1414
)
1515

16+
// HandlerType handler type
1617
type HandlerType string
1718

1819
const (

internal/hook/condition.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ const (
1616
ConditionLength ConditionType = "length"
1717
// ConditionPattern pattern condition
1818
ConditionPattern ConditionType = "pattern"
19-
// ConditionPattern protected condition
19+
// ConditionProtected protected condition
2020
ConditionProtected ConditionType = "protected"
2121
// ConditionSecret secret condition
2222
ConditionSecret ConditionType = "secret"

internal/hook/hook.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ func (gitHooks *GitHooks) Validate() error {
2525
return err
2626
}
2727
if !gitHooksVersion.LessThan(*watchDogVersion) && !gitHooksVersion.Equal(*watchDogVersion) {
28-
return fmt.Errorf("Unsupported .githooks.yml version %s by watchdog v%s", gitHooksVersion.String(), version.Version)
28+
return fmt.Errorf("unsupported .githooks.yml version %s by watchdog v%s", gitHooksVersion.String(), version.Version)
2929
}
3030
return nil
3131
}

internal/hook/hook_file.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ var (
1515
// ConfigFilename Git hooks configuration filename to be parsed
1616
ConfigFilename = ".githooks.yml"
1717
// ErrFileNotFound File not found error
18-
ErrFileNotFound = errors.New("Configuration file .githooks.(yaml|yml) not found")
18+
ErrFileNotFound = errors.New("configuration file .githooks.(yaml|yml) not found")
1919
)
2020

2121
// LoadGitHooks load and return Configuration struct
@@ -44,7 +44,7 @@ func ExtractConfigFile(ctx context.Context, commit *object.Commit) (gitHooks *Gi
4444
func LoadGitHooksFromRaw(fileContent string) (*GitHooks, error) {
4545
var hooks = &GitHooks{}
4646
if err := yaml.Unmarshal([]byte(fileContent), hooks); err != nil {
47-
return nil, fmt.Errorf("Unable to decode into struct, %v", err)
47+
return nil, fmt.Errorf("unable to decode into struct, %v", err)
4848
}
4949
if err := hooks.Validate(); err != nil {
5050
return nil, err

internal/hook/hook_info.go

+6-5
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,8 @@ const (
3131

3232
var (
3333
// ErrNoHookData no hook data error
34-
ErrNoHookData = errors.New("Hook data is mandatory")
34+
ErrNoHookData = errors.New("Hook data is mandatory")
35+
// ErrInvalidHookData invalid hook input
3536
ErrInvalidHookData = errors.New("invalid hook input")
3637
// HookTypes that are supported by Watchdog
3738
HookTypes = [...]string{
@@ -94,12 +95,11 @@ func (info *Info) ParseHookInput(input io.Reader) error {
9495
}
9596
info.NewRev = commit
9697
}
97-
info.parseHookAction()
9898
return nil
9999
}
100100

101-
// ParseHookAction return hook action
102-
func (info *Info) parseHookAction() {
101+
// GetAction return hook action
102+
func (info *Info) GetAction() string {
103103
action := "push"
104104
context := "branch"
105105
if info.Ref.IsTag() {
@@ -110,9 +110,10 @@ func (info *Info) parseHookAction() {
110110
} else if info.OldRev != nil && info.NewRev == nil {
111111
action = "delete"
112112
}
113-
info.Action = fmt.Sprintf("%s.%s", context, action)
113+
return fmt.Sprintf("%s.%s", context, action)
114114
}
115115

116+
// ParseInfo parse info for the current working directory
116117
func ParseInfo(repository *git.Repository) (*Info, error) {
117118
directory, err := os.Getwd()
118119
if err != nil {

internal/hook/hook_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,5 +25,5 @@ func TestParseHookAction(t *testing.T) {
2525
info := Info{
2626
Ref: plumbing.ReferenceName("refs/heads/master"),
2727
}
28-
assert.Equal(info.Action, "branch.push")
28+
assert.Equal("branch.push", info.GetAction())
2929
}

internal/output/formatter.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ func NewReport(writer io.Writer, options *config.Options, set *util.Set) (err er
4848
ErrorMessagePrefix: options.ErrorMessagePrefix,
4949
})
5050
default:
51-
return errors.New("Unsupported output format")
51+
return errors.New("unsupported output format")
5252
}
5353
}
5454

test/data/config.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ docs_link: https://groupe-edf.github.io/watchdog/docs/
33
error_message_prefix: "GL-HOOK-ERR: "
44
logs_level: info
55
logs_format: json
6-
logs_path: /var/log/watchdog/watchdog.log
6+
logs_path: watchdog.log
77
concurrent: 4
88
output_format: text
99
security:

0 commit comments

Comments
 (0)