Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

dev: fix govet, nestif lint issues #6

Merged
merged 1 commit into from
Feb 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading