Skip to content

Commit 179adb4

Browse files
committed
Major linting fixes.
1 parent dda2296 commit 179adb4

File tree

8 files changed

+184
-255
lines changed

8 files changed

+184
-255
lines changed

.golangci.yml

+22-142
Original file line numberDiff line numberDiff line change
@@ -1,142 +1,22 @@
1-
linters-settings:
2-
depguard:
3-
list-type: blacklist
4-
packages:
5-
# logging is allowed only by logutils.Log, logrus
6-
# is allowed to use only in logutils package
7-
- github.com/sirupsen/logrus
8-
packages-with-error-message:
9-
- github.com/sirupsen/logrus: "logging is allowed only by logutils.Log"
10-
dupl:
11-
threshold: 100
12-
funlen:
13-
lines: 100
14-
statements: 50
15-
gci:
16-
local-prefixes: github.com/golangci/golangci-lint
17-
goconst:
18-
min-len: 2
19-
min-occurrences: 2
20-
gocritic:
21-
enabled-tags:
22-
- diagnostic
23-
- experimental
24-
- opinionated
25-
- performance
26-
- style
27-
disabled-checks:
28-
- dupImport # https://github.com/go-critic/go-critic/issues/845
29-
- ifElseChain
30-
- octalLiteral
31-
- whyNoLint
32-
- wrapperFunc
33-
gocyclo:
34-
min-complexity: 15
35-
goimports:
36-
local-prefixes: github.com/golangci/golangci-lint
37-
golint:
38-
min-confidence: 0
39-
gomnd:
40-
settings:
41-
mnd:
42-
# don't include the "operation" and "assign"
43-
checks: argument,case,condition,return
44-
govet:
45-
check-shadowing: true
46-
settings:
47-
printf:
48-
funcs:
49-
- (github.com/golangci/golangci-lint/pkg/logutils.Log).Infof
50-
- (github.com/golangci/golangci-lint/pkg/logutils.Log).Warnf
51-
- (github.com/golangci/golangci-lint/pkg/logutils.Log).Errorf
52-
- (github.com/golangci/golangci-lint/pkg/logutils.Log).Fatalf
53-
lll:
54-
line-length: 140
55-
maligned:
56-
suggest-new: true
57-
misspell:
58-
locale: US
59-
nolintlint:
60-
allow-leading-space: true # don't require machine-readable nolint directives (i.e. with no leading space)
61-
allow-unused: false # report any unused nolint directives
62-
require-explanation: false # don't require an explanation for nolint directives
63-
require-specific: false # don't require nolint directives to be specific about which linter is being skipped
64-
65-
linters:
66-
# please, do not use `enable-all`: it's deprecated and will be removed soon.
67-
# inverted configuration with `enable-all` and `disable` is not scalable during updates of golangci-lint
68-
disable-all: true
69-
enable:
70-
- bodyclose
71-
- deadcode
72-
- depguard
73-
- dogsled
74-
- dupl
75-
- errcheck
76-
- exportloopref
77-
- exhaustive
78-
- funlen
79-
- gochecknoglobals
80-
- gochecknoinits
81-
- goconst
82-
- gocritic
83-
- gocyclo
84-
- godot
85-
- goerr113
86-
- gofmt
87-
- goimports
88-
- gomnd
89-
- goprintffuncname
90-
- gosec
91-
- gosimple
92-
- govet
93-
- ineffassign
94-
- lll
95-
- misspell
96-
- nakedret
97-
- noctx
98-
- nolintlint
99-
- revive
100-
- rowserrcheck
101-
- staticcheck
102-
- structcheck
103-
- stylecheck
104-
- typecheck
105-
- unconvert
106-
- unparam
107-
- unused
108-
- varcheck
109-
- whitespace
110-
111-
# don't enable:
112-
# - asciicheck
113-
# - scopelint
114-
# - gocognit
115-
# - godot
116-
# - godox
117-
# - interfacer
118-
# - maligned
119-
# - nestif
120-
# - prealloc
121-
# - testpackage
122-
# - revive
123-
# - wsl
124-
125-
issues:
126-
# Excluding configuration per-path, per-linter, per-text and per-source
127-
exclude-rules:
128-
- path: _test\.go
129-
linters:
130-
- gomnd
131-
132-
# https://github.com/go-critic/go-critic/issues/926
133-
- linters:
134-
- gocritic
135-
text: "unnecessaryDefer:"
136-
137-
run:
138-
skip-dirs:
139-
- test/testdata_etc
140-
- internal/cache
141-
- internal/renameio
142-
- internal/robustio
1+
# golangci-lint run
2+
# gofumpt -l -w -s .
3+
4+
linters:
5+
enable-all: true
6+
disable:
7+
- interfacer # Deprecated
8+
- scopelint # Deprecated
9+
- golint # Deprecated
10+
- maligned # Deprecated
11+
12+
- exhaustivestruct # 'It is not recommended to use it for all files in a project'
13+
- forbidigo # forbids the use for fmt.Print(f|ln)
14+
- nlreturn # opinionated
15+
- paralleltest # causes tests to randomly fail
16+
- wsl # whitespace linter, slow, aggressive and opinionated
17+
18+
linters-settings:
19+
cyclop:
20+
max-complexity: 15 # default value 10 requires unnecessary refactoring
21+
varnamelen:
22+
min-name-length: 1 # default value 3 is too short

internal/misc/misc.go

+6-5
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,8 @@ func (e Export) Find(name string) string {
4242
if !e[name] {
4343
return name
4444
}
45-
i, new := 0, ""
45+
i := 0
46+
const maximum = 9999
4647
for {
4748
i++
4849
ext := filepath.Ext(name)
@@ -54,11 +55,11 @@ func (e Export) Find(name string) string {
5455
base = strings.Join(a[0:len(a)-1], "_")
5556
}
5657
suf := fmt.Sprintf("_%d", i+1)
57-
new = fmt.Sprintf("%s%s%s", base, suf, ext)
58-
if !e[new] {
59-
return new
58+
s := fmt.Sprintf("%s%s%s", base, suf, ext)
59+
if !e[s] {
60+
return s
6061
}
61-
if i > 9999 {
62+
if i > maximum {
6263
break
6364
}
6465
}

lib/example_posix_test.go

+5-3
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,17 @@
33

44
// © Ben Garrett https://github.com/bengarrett/zipcmt
55

6-
package zipcmt
6+
package zipcmt_test
77

88
import (
99
"fmt"
1010
"log"
11+
12+
zipcmt "github.com/bengarrett/zipcmt/lib"
1113
)
1214

1315
func ExampleConfig_Clean() {
14-
c := Config{
16+
c := zipcmt.Config{
1517
SaveName: "..//test///.",
1618
}
1719
if err := c.Clean(); err != nil {
@@ -22,7 +24,7 @@ func ExampleConfig_Clean() {
2224
}
2325

2426
func ExampleConfig_WalkDir() {
25-
c := Config{
27+
c := zipcmt.Config{
2628
Print: true,
2729
Dupes: true,
2830
}

lib/example_test.go

+7-6
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,39 @@
11
// © Ben Garrett https://github.com/bengarrett/zipcmt
22

3-
package zipcmt
3+
package zipcmt_test
44

55
import (
66
"fmt"
77
"log"
88

9+
zipcmt "github.com/bengarrett/zipcmt/lib"
910
"github.com/gookit/color"
1011
)
1112

12-
func init() {
13+
func init() { // nolint:gochecknoinits
1314
color.Enable = false
1415
}
1516

1617
func ExampleRead() {
17-
s, err := Read("../test/test-with-comment.zip", false)
18+
s, err := zipcmt.Read("../test/test-with-comment.zip", false)
1819
if err != nil {
1920
log.Fatalln(err)
2021
}
2122
fmt.Print(s)
2223
// Output:
23-
//This is an example test comment for zipcmmt.
24+
// This is an example test comment for zipcmmt.
2425
//
2526
}
2627

2728
func ExampleConfig_Status() {
28-
c := Config{}
29+
c := zipcmt.Config{}
2930
c.SetTest()
3031
if err := c.WalkDir("../test"); err != nil {
3132
log.Panicln(err)
3233
}
3334
fmt.Print(c.Status())
3435

35-
c = Config{
36+
c = zipcmt.Config{
3637
Dupes: true,
3738
}
3839
c.SetTest()

lib/example_win_test.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -3,26 +3,26 @@
33

44
// © Ben Garrett https://github.com/bengarrett/zipcmt
55

6-
package zipcmt
6+
package zipcmt_test
77

88
import (
99
"fmt"
1010
"log"
1111
)
1212

1313
func ExampleConfig_clean() {
14-
c := Config{
14+
c := zipcmt.Config{
1515
SaveName: "..//test///.",
1616
}
17-
if err := c.clean(); err != nil {
17+
if err := c.Clean(); err != nil {
1818
log.Fatalln(err)
1919
}
2020
fmt.Print(c.SaveName)
2121
// Output: ..\test
2222
}
2323

2424
func ExampleConfig_WalkDir() {
25-
c := Config{
25+
c := zipcmt.Config{
2626
Print: true,
2727
Dupes: true,
2828
}

lib/log.go

+13-5
Original file line numberDiff line numberDiff line change
@@ -37,27 +37,33 @@ func (c *Config) WriteLog(s string) {
3737
d := filepath.Dir(c.LogName())
3838
_, err := os.Stat(d)
3939
if os.IsNotExist(err) {
40-
os.MkdirAll(d, 0755)
40+
const perm = 0o755
41+
if err := os.MkdirAll(d, perm); err != nil {
42+
log.Fatalln(err)
43+
}
4144
}
4245
}
4346

44-
f, err1 := os.OpenFile(c.LogName(), os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0644)
47+
const perm = 0o644
48+
f, err1 := os.OpenFile(c.LogName(), os.O_APPEND|os.O_CREATE|os.O_WRONLY, perm)
4549
if err1 != nil {
4650
log.Fatalln(err1)
4751
}
48-
defer f.Close()
4952

5053
logger := log.New(f, "zipcmt|", log.LstdFlags)
5154
st, err2 := f.Stat()
5255
if err2 != nil {
56+
f.Close()
5357
log.Fatalln(err2)
5458
}
59+
defer f.Close()
5560
if st.Size() == 0 {
5661
c.logHeader(logger)
5762
}
5863
l := fmt.Sprintf("zip#: %07d; cmmt#: %07d; ", c.Zips, c.Cmmts)
5964
if !c.Dupes {
60-
l += fmt.Sprintf("hashes: %s; ", humanize.Bytes(uint64(len(c.hashes)*32)))
65+
const hashLen = 32
66+
l += fmt.Sprintf("hashes: %s; ", humanize.Bytes(uint64(len(c.hashes)*hashLen)))
6167
}
6268
if c.SaveName != "" {
6369
l += fmt.Sprintf("names: %s; ", humanize.Bytes(uint64(c.names)))
@@ -69,12 +75,14 @@ func (c *Config) WriteLog(s string) {
6975
// logHeader creates a header for new log files that lists all the values of Config.
7076
func (c *Config) logHeader(logger *log.Logger) {
7177
w := new(tabwriter.Writer)
72-
w.Init(logger.Writer(), 0, 8, 0, '\t', 0)
78+
const tabWidth = 8
79+
w.Init(logger.Writer(), 0, tabWidth, 0, '\t', 0)
7380
fmt.Fprintln(w, "Zip Comment Log - Configurations and arguments")
7481
fmt.Fprintln(w, "")
7582
// see: https://scene-si.org/2017/12/21/introduction-to-reflection/
7683
v := reflect.ValueOf(c).Elem()
7784
t := v.Type()
85+
7886
for i := 0; i < v.NumField(); i++ {
7987
fmt.Fprintf(w, "%02d. %s:\t\t%v\n", i+1, t.Field(i).Name, v.Field(i))
8088
if t.Field(i).Name == "test" {

0 commit comments

Comments
 (0)