Skip to content

Commit

Permalink
dev: fix govet, nestif lint issues (#6)
Browse files Browse the repository at this point in the history
  • Loading branch information
alexandear authored Feb 19, 2024
1 parent 39b4324 commit 8aceb42
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 11 deletions.
1 change: 0 additions & 1 deletion .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ linters-settings:
enable-all: true
disable:
- fieldalignment
- shadow # FIXME(ldez) must be fixed
gocyclo:
min-complexity: 16
goconst:
Expand Down
3 changes: 2 additions & 1 deletion mime.go
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,8 @@ func ReadTextFile(filename string) (string, error) {
// if not-text, then exit
isText := false
if fstat.Size() > 50000 {
fin, err := os.Open(filename)
var fin *os.File
fin, err = os.Open(filename)
if err != nil {
return "", fmt.Errorf("unable to open large file %q: %w", filename, err)
}
Expand Down
22 changes: 13 additions & 9 deletions stringreplacer.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,6 @@ func (t *trieNode) add(key, val string, priority int, r *genericReplacer) {
return
}

//nolint:nestif // TODO(ldez) must be fixed.
if t.prefix != "" {
// Need to split the prefix among multiple nodes.
var n int // length of the longest common prefix
Expand All @@ -111,9 +110,10 @@ func (t *trieNode) add(key, val string, priority int, r *genericReplacer) {
break
}
}
if n == len(t.prefix) {
switch n {
case len(t.prefix):
t.next.add(key[n:], val, priority, r)
} else if n == 0 {
case 0:
// First byte differs, start a new lookup table here. Looking up
// what is currently t.prefix[0] will lead to prefixNode, and
// looking up key[0] will lead to keyNode.
Expand All @@ -133,7 +133,7 @@ func (t *trieNode) add(key, val string, priority int, r *genericReplacer) {
t.prefix = ""
t.next = nil
keyNode.add(key[1:], val, priority, r)
} else {
default:
// Insert new node after the common section of the prefix.
next := &trieNode{
prefix: t.prefix[n:],
Expand All @@ -143,18 +143,22 @@ func (t *trieNode) add(key, val string, priority int, r *genericReplacer) {
t.next = next
next.add(key[n:], val, priority, r)
}
} else if t.table != nil {
return
}

if t.table != nil {
// Insert into existing table.
m := r.mapping[key[0]]
if t.table[m] == nil {
t.table[m] = new(trieNode)
}
t.table[m].add(key[1:], val, priority, r)
} else {
t.prefix = key
t.next = new(trieNode)
t.next.add("", val, priority, r)
return
}

t.prefix = key
t.next = new(trieNode)
t.next.add("", val, priority, r)
}

// genericReplacer is the fully generic algorithm.
Expand Down

0 comments on commit 8aceb42

Please sign in to comment.