Skip to content

Commit 49e3409

Browse files
skryukovEnvek
authored andcommitted
Add golangci-lint workflow
1 parent 3c60f88 commit 49e3409

File tree

8 files changed

+77
-23
lines changed

8 files changed

+77
-23
lines changed

.github/workflows/lint.yml

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
on:
2+
push:
3+
branches:
4+
- master
5+
pull_request:
6+
7+
name: Lint
8+
jobs:
9+
golangci:
10+
name: golangci-lint
11+
runs-on: ubuntu-latest
12+
steps:
13+
- uses: actions/checkout@v2
14+
- name: golangci-lint
15+
uses: golangci/golangci-lint-action@v2
16+
with:
17+
args: '-E gofmt'

.golangci.yml

+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
linters-settings:
2+
govet:
3+
check-shadowing: true
4+
misspell:
5+
locale: US
6+
7+
linters:
8+
disable-all: true
9+
enable:
10+
- bodyclose
11+
- deadcode
12+
- depguard
13+
- dogsled
14+
- dupl
15+
- errcheck
16+
- exportloopref
17+
- exhaustive
18+
- goconst
19+
- gocyclo
20+
- gofmt
21+
- goimports
22+
- golint
23+
- goprintffuncname
24+
- gosimple
25+
- govet
26+
- ineffassign
27+
- misspell
28+
- nakedret
29+
- noctx
30+
- nolintlint
31+
- rowserrcheck
32+
- staticcheck
33+
- structcheck
34+
- typecheck
35+
- unconvert
36+
- unparam
37+
- unused
38+
- varcheck
39+
- whitespace

cmd/cmd_test.go

+8-9
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ func TestAddCmdExecutor(t *testing.T) {
8888
actualFiles = append(actualFiles, f.Name())
8989
}
9090

91-
assert.Equal(t, expectedDirs, actualDirs, "Haven`t renamed file with .old extension")
91+
assert.Equal(t, expectedFiles, actualFiles, "Haven`t renamed file with .old extension")
9292
}
9393

9494
func TestRunCmdExecutor(t *testing.T) {
@@ -101,7 +101,7 @@ pre-commit:
101101
run: echo 'test passed'
102102
`)
103103
viper.SetConfigType("yaml")
104-
viper.ReadConfig(bytes.NewBuffer(yamlExample))
104+
_ = viper.ReadConfig(bytes.NewBuffer(yamlExample))
105105

106106
var buf bytes.Buffer
107107
log.SetOutput(&buf)
@@ -124,29 +124,28 @@ func TestExtendsProperty(t *testing.T) {
124124
var expectedPathsString = []string{"c3.yml"}
125125
viper.SetConfigType("yaml")
126126

127-
viper.ReadConfig(bytes.NewBuffer([]byte("")))
127+
_ = viper.ReadConfig(bytes.NewBuffer([]byte("")))
128128
assert.False(t, isConfigExtends(), "Should not detect extends property")
129129

130-
viper.ReadConfig(bytes.NewBuffer(yamlExampleString))
130+
_ = viper.ReadConfig(bytes.NewBuffer(yamlExampleString))
131131
paths := getExtendsPath()
132132

133133
assert.True(t, isConfigExtends(), "Should detect extends property")
134134
assert.Equal(t, paths, expectedPathsString, "Extends path does not match for string value")
135135

136-
viper.ReadConfig(bytes.NewBuffer(yamlExampleArray))
136+
_ = viper.ReadConfig(bytes.NewBuffer(yamlExampleArray))
137137
paths = getExtendsPath()
138138
assert.Equal(t, paths, expectedPathsArray, "Extends path does not match for array value")
139-
140139
}
141140

142141
func presetConfig(fs afero.Fs) {
143142
viper.SetDefault(configSourceDirKey, ".lefthook")
144143

145144
AddConfigYaml(fs)
146145

147-
fs.Mkdir(filepath.Join(getRootPath(), ".lefthook/commit-msg"), defaultFilePermission)
148-
fs.Mkdir(filepath.Join(getRootPath(), ".lefthook/pre-commit"), defaultFilePermission)
146+
_ = fs.Mkdir(filepath.Join(getRootPath(), ".lefthook/commit-msg"), defaultFilePermission)
147+
_ = fs.Mkdir(filepath.Join(getRootPath(), ".lefthook/pre-commit"), defaultFilePermission)
149148

150149
setGitHooksPath(".git/hooks")
151-
fs.MkdirAll(getGitHooksPath(), defaultFilePermission)
150+
_ = fs.MkdirAll(getGitHooksPath(), defaultFilePermission)
152151
}

cmd/install.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ func getConfigLocalYamlPattern() string {
121121
func hasValidConfigFile(fs afero.Fs) bool {
122122
matches, err := afero.Glob(fs, getConfigYamlPattern())
123123
if err != nil {
124-
log.Println("Error occured for search config file: ", err.Error())
124+
log.Println("Error occurred for search config file: ", err.Error())
125125
}
126126
for _, match := range matches {
127127
extension := filepath.Ext(match)

cmd/root.go

+5-5
Original file line numberDiff line numberDiff line change
@@ -90,23 +90,23 @@ func initAurora() {
9090
func initConfig() {
9191
log.SetFlags(0)
9292

93-
setRootPath(rootExecutionRelPath)
93+
setRootPath()
9494
setGitHooksPath(getHooksPathFromGitConfig())
9595

9696
// store original config before merge
9797
originConfig = viper.New()
9898
originConfig.SetConfigName(configFileName)
9999
originConfig.AddConfigPath(rootExecutionRelPath)
100-
originConfig.ReadInConfig()
100+
_ = originConfig.ReadInConfig()
101101

102102
viper.SetConfigName(configFileName)
103103
viper.AddConfigPath(rootExecutionRelPath)
104104
viper.SetDefault(configSourceDirKey, ".lefthook")
105105
viper.SetDefault(configSourceDirLocalKey, ".lefthook-local")
106-
viper.ReadInConfig()
106+
_ = viper.ReadInConfig()
107107

108108
viper.SetConfigName(configLocalFileName)
109-
viper.MergeInConfig()
109+
_ = viper.MergeInConfig()
110110

111111
if isConfigExtends() {
112112
for _, path := range getExtendsPath() {
@@ -127,7 +127,7 @@ func getRootPath() string {
127127
return rootPath
128128
}
129129

130-
func setRootPath(path string) {
130+
func setRootPath() {
131131
// get absolute path to .git dir (project root)
132132
cmd := exec.Command("git", "rev-parse", "--show-toplevel")
133133

cmd/run.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -199,13 +199,13 @@ func executeCommand(hooksGroup, commandName string, wg *sync.WaitGroup, gitArgs
199199

200200
VerbosePrint("Files after filters: \n", files)
201201

202-
files_esc := []string{}
202+
filesEsc := []string{}
203203
for _, fileName := range files {
204204
if len(fileName) > 0 {
205-
files_esc = append(files_esc, shellescape.Quote(fileName))
205+
filesEsc = append(filesEsc, shellescape.Quote(fileName))
206206
}
207207
}
208-
files = files_esc
208+
files = filesEsc
209209
VerbosePrint("Files after escaping: \n", files)
210210

211211
runner = strings.Replace(runner, pushFiles, strings.Join(files, " "), -1)

cmd/run_command.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,9 @@ func RunPlainCommand(command *exec.Cmd) (*bytes.Buffer, WaitFunc, error) {
3232
commandOutput := bytes.NewBuffer(make([]byte, 0))
3333
_, _ = io.Copy(commandOutput, ptyOut)
3434
waitFunc := func() error {
35-
err := command.Wait()
35+
wErr := command.Wait()
3636
_ = ptyOut.Close()
37-
return err
37+
return wErr
3838
}
39-
return commandOutput, waitFunc, err
39+
return commandOutput, waitFunc, err
4040
}

pkg/context/context.go

+1-2
Original file line numberDiff line numberDiff line change
@@ -65,9 +65,8 @@ func isFile(path string) (bool, error) {
6565
if err != nil {
6666
if os.IsNotExist(err) {
6767
return false, nil
68-
} else {
69-
return false, err
7068
}
69+
return false, err
7170
}
7271

7372
return !stat.IsDir(), nil

0 commit comments

Comments
 (0)