Skip to content

Commit 2b1375c

Browse files
added a lint, corrected (almost) everything according to it
1 parent 4ef5bea commit 2b1375c

File tree

6 files changed

+61
-18
lines changed

6 files changed

+61
-18
lines changed

.golangci.yml

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
run:
2+
tests: true
3+
skip-dirs:
4+
- build
5+
6+
output:
7+
format: colored-line-number
8+
print-issued-lines: true
9+
print-linter-name: true
10+
unique-by-line: true
11+
sort-results: true
12+
13+
linters:
14+
disable-all: true
15+
enable:
16+
- errcheck
17+
- gosimple
18+
- govet
19+
- ineffassign
20+
- typecheck
21+
- unused
22+
- cyclop
23+
- dupl
24+
- dupword
25+
- funlen
26+
- lll
27+
- gochecknoglobals
28+
- goconst
29+
- gocritic
30+
- gocyclo
31+
- godot
32+
- gosec
33+
- nakedret
34+
- nestif
35+
- stylecheck
36+
- varnamelen

Makefile

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,4 +34,8 @@ test:
3434

3535
.PHONE: clear
3636
clear:
37-
sh ./script/clear.sh
37+
sh ./script/clear.sh
38+
39+
.PHONY: lint
40+
lint:
41+
golangci-lint run

internal/app/dir/dir.go

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import (
1212

1313
const perm = 0755 // Access rights to create folders
1414

15-
// Constants with the name of the project subdirectories
15+
// Constants with the name of the project subdirectories.
1616
const (
1717
cmdDir = "cmd"
1818
pkgDir = "pkg"
@@ -60,6 +60,8 @@ func (d *Dirs) createProjectDir() error {
6060
return nil
6161
}
6262

63+
// TODO calculated cyclomatic complexity for function createProjectDirs is 13,
64+
// max is 10.
6365
func (d *Dirs) createProjectDirs() error {
6466
projectDirs := [4]string{cmdDir, pkgDir, internalDir, cfgDir}
6567

@@ -78,15 +80,16 @@ func (d *Dirs) createProjectDirs() error {
7880
}
7981

8082
// depending on the current directory being created, create files or subdirectories.
81-
if currentDir == cmdDir {
83+
switch currentDir {
84+
case cmdDir:
8285
if err := d.file.GenerateMainFile(dir + "/" + d.projectName + ".go"); err != nil {
8386
return err
8487
}
85-
} else if currentDir == internalDir {
88+
case internalDir:
8689
if err := d.createInternalSubDir(); err != nil {
8790
return err
8891
}
89-
} else if currentDir == cfgDir {
92+
case cfgDir:
9093
if err := d.file.GenerateCfgFile(dir); err != nil {
9194
return err
9295
}

internal/app/file/file.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,18 +15,18 @@ func NewFile() *File {
1515
}
1616

1717
func (fl File) createAndWriteFile(dir, content string) error {
18-
f, err := os.Create(dir)
18+
file, err := os.Create(dir)
1919
if err != nil {
2020
return err
2121
}
2222
defer func() {
23-
err = f.Close()
23+
err = file.Close()
2424
}()
2525
if err != nil {
2626
return err
2727
}
2828

29-
if _, err := f.WriteString(content); err != nil {
29+
if _, err := file.WriteString(content); err != nil {
3030
return err
3131
}
3232

internal/pkg/args/tests/args_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,13 @@ func TestGetProjectName(t *testing.T) {
2828
t.Fatalf("Expected an error, got nil")
2929
}
3030

31-
wd, err := os.Getwd()
31+
pwd, err := os.Getwd()
3232
if err != nil {
3333
t.Fatalf("Fail to get current directory: %s", err.Error())
3434
}
3535

36-
if projectName != wd {
37-
t.Fatalf("Expected project name to be: %s, got: %s", wd, projectName)
36+
if projectName != pwd {
37+
t.Fatalf("Expected project name to be: %s, got: %s", pwd, projectName)
3838
}
3939

4040
if !isCurrentDir {

pkg/version/tests/version_test.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import (
99
)
1010

1111
func TestGetVersion(t *testing.T) {
12-
v, err := version.GoVersion()
12+
vers, err := version.GoVersion()
1313
if err != nil {
1414
t.Fatalf("GoVersion() returned an error: %v", err)
1515
}
@@ -19,24 +19,24 @@ func TestGetVersion(t *testing.T) {
1919
t.Log("verify that the version string is in the correct format")
2020
{
2121
re := regexp.MustCompile(`go \d+\.\d+(\.\d+)?`)
22-
if !re.MatchString(v) {
23-
t.Fatalf("GoVersion() returned an invalid version string: %s", v)
22+
if !re.MatchString(vers) {
23+
t.Fatalf("GoVersion() returned an invalid version string: %s", vers)
2424
}
2525
}
2626

2727
t.Log("verify that the version string is properly formatted")
2828
{
29-
versionDigits := strings.TrimPrefix(v, "go")
29+
versionDigits := strings.TrimPrefix(vers, "go")
3030
versionParts = strings.Split(versionDigits, ".")
3131
if len(versionParts) < 2 || len(versionParts) > 3 {
32-
t.Fatalf("GoVersion() returned an invalid version string: %s", v)
32+
t.Fatalf("GoVersion() returned an invalid version string: %s", vers)
3333
}
3434
}
3535

3636
t.Log("verify that the version string starts with \"go\"")
3737
{
38-
if !strings.HasPrefix(v, "go") {
39-
t.Fatalf("GoVersion() returned an invalid version string: %s", v)
38+
if !strings.HasPrefix(vers, "go") {
39+
t.Fatalf("GoVersion() returned an invalid version string: %s", vers)
4040
}
4141
}
4242

0 commit comments

Comments
 (0)