Skip to content

Commit

Permalink
improve linter and fix issues (#11)
Browse files Browse the repository at this point in the history
  • Loading branch information
sepehrsoh authored Feb 3, 2025
1 parent 0b52c78 commit dd1c3af
Show file tree
Hide file tree
Showing 2 changed files with 87 additions and 11 deletions.
92 changes: 84 additions & 8 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
# Source: https://github.com/ccoVeille/golangci-lint-config-examples/
# Author: @ccoVeille
# License: MIT
# Variant: 03-safe
# Version: v1.1.0
# Variant: 10-cautious
# Version: v1.2.0
#
linters:
# some linters are enabled by default
Expand Down Expand Up @@ -55,6 +55,9 @@ linters:
# detects nested contexts in loops or function literals
- fatcontext

# checks if package imports are in a list of acceptable packages.
- depguard

linters-settings:
gci: # define the section orders for imports
sections:
Expand All @@ -67,15 +70,14 @@ linters-settings:

revive:
rules:
# these are the default revive rules
# you can remove the whole "rules" node if you want
# BUT
# ! /!\ they all need to be present when you want to add more rules than the default ones
# otherwise, you won't have the default rules, but only the ones you define in the "rules" node
# Check for commonly mistaken usages of the sync/atomic package
- name: atomic

# Blank import should be only in a main or test package, or have a comment justifying it.
- name: blank-imports

# Spots comments not starting with a space
- name: comment-spacings
# context.Context() should be the first parameter of a function when provided as argument.
- name: context-as-argument
arguments:
Expand All @@ -84,9 +86,15 @@ linters-settings:
# Basic types should not be used as a key in `context.WithValue`
- name: context-keys-type

# warns on some common mistakes when using defer statement.
- name: defer

# Importing with `.` makes the programs much harder to understand
- name: dot-imports

# suggest to simplify if-then-else constructions when possible
- name: early-return

# Empty blocks make code less readable and could be a symptom of a bug or unfinished refactoring.
- name: empty-block

Expand All @@ -102,6 +110,9 @@ linters-settings:
# report when replacing `errors.New(fmt.Sprintf())` with `fmt.Errorf()` is possible
- name: errorf

# Checking if an error is nil to just after return the error or nil is redundant.
- name: if-return

# incrementing an integer variable by 1 is recommended to be done using the `++` operator
- name: increment-decrement

Expand Down Expand Up @@ -132,12 +143,77 @@ linters-settings:
# Functions or methods with unused parameters can be a symptom of an unfinished refactoring or a bug.
- name: unused-parameter

# warns on useless break statements in case clauses of switch and select statements
- name: useless-break

# report when a variable declaration can be simplified
- name: var-declaration

# warns when initialism, variable or package naming conventions are not followed.
- name: var-naming

depguard:
rules:
obsolete:
deny:
- pkg: "golang.org/x/net/context"
desc: "Should be replaced by standard lib context package (Go 1.7+)"
- pkg: "github.com/pkg/errors"
desc: "Should be replaced by standard lib errors package (Go 1.13+)"
- pkg: "golang.org/x/xerrors"
desc: "Should be replaced by standard lib errors package (Go 1.13+)"
- pkg: github.com/go-errors/errors
desc: "Should be replaced by standard lib errors package"
- pkg: "io/ioutil"
desc: "Should be replaced by standard lib os package (Go 1.16+)"
- pkg: "golang.org/x/exp/slices"
desc: "Should be replaced by slices (Go 1.21+)"
- pkg: "golang.org/x/exp/maps"
desc: "Should be replaced by standard lib maps package (Go 1.21+)"
- pkg: "math/rand$"
desc: "Should be replaced by standard lib math/rand/v2 package (Go 1.23+)"
- pkg: "golang.org/x/syscall"
desc: "Should be replaced by golang.org/x/sys or os package according to Go maintainers. More information: https://golang.org/s/go1.4-syscall"
- pkg: "golang.org/x/crypto/ed25519"
desc: "Should be replaced by standard lib crypto/ed25519 package"
- pkg: "github.com/golang/protobuf"
desc: "Should be replaced by google.golang.org/protobuf package (github.com/golang/protobuf is deprecated)"
- pkg: "github.com/gogo/protobuf"
desc: "Should be replaced by google.golang.org/protobuf package (github.com/gogo/protobuf is deprecated)"
- pkg: "github.com/golang/protobuf/proto"
desc: "Should be replaced by google.golang.org/protobuf/proto package (github.com/golang/protobuf/proto is deprecated)"
- pkg: "github.com/gogo/status"
desc: "Should be replaced by google.golang.org/grpc/status package (github.com/gogo/status is deprecated)"
logs:
deny:
- pkg: "github.com/prometheus/common/log"
desc: "Could be replaced by standard lib log/slog package"
- pkg: "github.com/sirupsen/logrus"
desc: "Should be replaced by standard lib log/slog package"
- pkg: github.com/siddontang/go-log/log
desc: "Could be replaced by standard lib log/slog package"
- pkg: github.com/siddontang/go/log
desc: "Could be replaced by standard lib log/slog package"
- pkg: github.com/mailgun/log
desc: "Could be replaced by standard lib log/slog package"
- pkg: github.com/saferwall/pe/log
desc: "Could be replaced by standard lib log/slog package"
recommended:
deny:
- pkg: "go.uber.org/atomic"
desc: "Could be replaced by standard lib sync/atomic package"
- pkg: "github.com/hashicorp/go-multierror"
desc: "Could be replaced by errors.Join (Go 1.20+)"
forbidigo:
forbid:
# this one could be moved to ldez/exptostd
- p: "constraints\\.Ordered"
msg: "Use standard lib cmp.Ordered instead (Go 1.21+)"
# doesn't work ?
- pkg: "^golang.org/x/exp/constraints$"
p: "^.*$"
msg: "WIP"
- p: ^atomic\.(Add|CompareAndSwap|Load|Store|Swap).
msg: Go 1.19 atomic types should be used instead.
dupword:
# Keywords used to ignore detection.
# Default: []
Expand Down
6 changes: 3 additions & 3 deletions internal/symspell.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,12 +86,12 @@ func (s *SymSpell) createDictionaryEntry(key string, count int) bool {
// Increment the count
count = incrementCount(count, countPrev)
// Check if it reaches the threshold
if count >= s.CountThreshold {
delete(s.BelowThresholdWords, key)
} else {
if count < s.CountThreshold {
s.BelowThresholdWords[key] = count
return false

}
delete(s.BelowThresholdWords, key)
}
} else if countPrev, found := s.Words[key]; found {
// Increment the count
Expand Down

0 comments on commit dd1c3af

Please sign in to comment.