Skip to content

Commit 8aceb42

Browse files
authored
dev: fix govet, nestif lint issues (#6)
1 parent 39b4324 commit 8aceb42

File tree

3 files changed

+15
-11
lines changed

3 files changed

+15
-11
lines changed

.golangci.yml

-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ linters-settings:
77
enable-all: true
88
disable:
99
- fieldalignment
10-
- shadow # FIXME(ldez) must be fixed
1110
gocyclo:
1211
min-complexity: 16
1312
goconst:

mime.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,8 @@ func ReadTextFile(filename string) (string, error) {
174174
// if not-text, then exit
175175
isText := false
176176
if fstat.Size() > 50000 {
177-
fin, err := os.Open(filename)
177+
var fin *os.File
178+
fin, err = os.Open(filename)
178179
if err != nil {
179180
return "", fmt.Errorf("unable to open large file %q: %w", filename, err)
180181
}

stringreplacer.go

+13-9
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,6 @@ func (t *trieNode) add(key, val string, priority int, r *genericReplacer) {
102102
return
103103
}
104104

105-
//nolint:nestif // TODO(ldez) must be fixed.
106105
if t.prefix != "" {
107106
// Need to split the prefix among multiple nodes.
108107
var n int // length of the longest common prefix
@@ -111,9 +110,10 @@ func (t *trieNode) add(key, val string, priority int, r *genericReplacer) {
111110
break
112111
}
113112
}
114-
if n == len(t.prefix) {
113+
switch n {
114+
case len(t.prefix):
115115
t.next.add(key[n:], val, priority, r)
116-
} else if n == 0 {
116+
case 0:
117117
// First byte differs, start a new lookup table here. Looking up
118118
// what is currently t.prefix[0] will lead to prefixNode, and
119119
// looking up key[0] will lead to keyNode.
@@ -133,7 +133,7 @@ func (t *trieNode) add(key, val string, priority int, r *genericReplacer) {
133133
t.prefix = ""
134134
t.next = nil
135135
keyNode.add(key[1:], val, priority, r)
136-
} else {
136+
default:
137137
// Insert new node after the common section of the prefix.
138138
next := &trieNode{
139139
prefix: t.prefix[n:],
@@ -143,18 +143,22 @@ func (t *trieNode) add(key, val string, priority int, r *genericReplacer) {
143143
t.next = next
144144
next.add(key[n:], val, priority, r)
145145
}
146-
} else if t.table != nil {
146+
return
147+
}
148+
149+
if t.table != nil {
147150
// Insert into existing table.
148151
m := r.mapping[key[0]]
149152
if t.table[m] == nil {
150153
t.table[m] = new(trieNode)
151154
}
152155
t.table[m].add(key[1:], val, priority, r)
153-
} else {
154-
t.prefix = key
155-
t.next = new(trieNode)
156-
t.next.add("", val, priority, r)
156+
return
157157
}
158+
159+
t.prefix = key
160+
t.next = new(trieNode)
161+
t.next.add("", val, priority, r)
158162
}
159163

160164
// genericReplacer is the fully generic algorithm.

0 commit comments

Comments
 (0)