Skip to content

Commit

Permalink
Merge branch 'master' into fix-test-data-race
Browse files Browse the repository at this point in the history
  • Loading branch information
alexandear committed Mar 2, 2024
2 parents 206910d + 201b6e6 commit f8df434
Show file tree
Hide file tree
Showing 13 changed files with 40 additions and 35 deletions.
5 changes: 3 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ jobs:
runs-on: ubuntu-latest
env:
GO_VERSION: stable
GOLANGCI_LINT_VERSION: v1.55.2
GOLANGCI_LINT_VERSION: v1.56.2
CGO_ENABLED: 1

steps:

Expand All @@ -25,7 +26,7 @@ jobs:

# https://github.com/marketplace/actions/setup-go-environment
- name: Set up Go ${{ env.GO_VERSION }}
uses: actions/setup-go@v4
uses: actions/setup-go@v5
with:
go-version: ${{ env.GO_VERSION }}

Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/go-cross.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ jobs:

# https://github.com/marketplace/actions/setup-go-environment
- name: Set up Go ${{ matrix.go-version }}
uses: actions/setup-go@v4
uses: actions/setup-go@v5
with:
go-version: ${{ matrix.go-version }}

Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ jobs:

# https://github.com/marketplace/actions/setup-go-environment
- name: Set up Go ${{ env.GO_VERSION }}
uses: actions/setup-go@v4
uses: actions/setup-go@v5
with:
go-version: ${{ env.GO_VERSION }}

Expand Down
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
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM golang:1.19-alpine
FROM golang:1.22-alpine

# cache buster
RUN echo 4
Expand Down
4 changes: 2 additions & 2 deletions cmd/misspell/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ func main() {
//
// Stuff to ignore
//
if len(*ignores) > 0 {
if *ignores != "" {
r.RemoveRule(strings.Split(*ignores, ","))
}

Expand Down Expand Up @@ -188,7 +188,7 @@ func main() {
defaultWrite = tmpl
defaultRead = tmpl
stdout.Println(sqliteHeader)
case len(*format) > 0:
case *format != "":
t, err := template.New("custom").Parse(*format)
if err != nil {
log.Fatalf("Unable to compile log format: %s", err)
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
module github.com/golangci/misspell

go 1.19
go 1.21

require github.com/gobwas/glob v0.2.3
2 changes: 1 addition & 1 deletion ignore/glob.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ func NewBaseGlobMatch(arg string, truth bool) (*GlobMatch, error) {
// Arg true should be set to false if the output is inverted.
func NewPathGlobMatch(arg string, truth bool) (*GlobMatch, error) {
// if starts with "/" then glob only applies to top level
if len(arg) > 0 && arg[0] == '/' {
if arg != "" && arg[0] == '/' {
arg = arg[1:]
}

Expand Down
15 changes: 8 additions & 7 deletions mime.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"net/http"
"os"
"path/filepath"
"slices"
"strings"
)

Expand Down Expand Up @@ -77,13 +78,12 @@ func isSCMPath(s string) bool {
if strings.Contains(filepath.Base(s), "EDITMSG") {
return false
}

parts := strings.Split(filepath.Clean(s), string(filepath.Separator))
for _, dir := range parts {
if scm[dir] {
return true
}
}
return false

return slices.ContainsFunc(parts, func(dir string) bool {
return scm[dir]
})
}

var magicHeaders = [][]byte{
Expand Down 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
2 changes: 1 addition & 1 deletion notwords.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ var (
func RemovePath(s string) string {
out := bytes.Buffer{}
var idx int
for len(s) > 0 {
for s != "" {
if idx = strings.IndexByte(s, '/'); idx == -1 {
out.WriteString(s)
break
Expand Down
12 changes: 5 additions & 7 deletions replace.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"bytes"
"io"
"regexp"
"slices"
"strings"
"text/scanner"
)
Expand All @@ -17,12 +18,9 @@ func max(x, y int) int {
}

func inArray(haystack []string, needle string) bool {
for _, word := range haystack {
if strings.EqualFold(needle, word) {
return true
}
}
return false
return slices.ContainsFunc(haystack, func(word string) bool {
return strings.EqualFold(needle, word)
})
}

var wordRegexp = regexp.MustCompile(`[a-zA-Z0-9']+`)
Expand Down Expand Up @@ -192,7 +190,7 @@ Loop:
return buf.String(), diffs
}

// Replace is corrects misspellings in input, returning corrected version along with a list of diffs.
// Replace is correcting misspellings in input, returning corrected version along with a list of diffs.
func (r *Replacer) Replace(input string) (string, []Diff) {
output := r.engine.Replace(input)
if input == output {
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
4 changes: 3 additions & 1 deletion words_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,16 @@ func (a sortByLen) Less(i, j int) bool {
return len(a[i]) > len(a[j])
}

func TestWordSort(t *testing.T) {
func Test_wordSort(t *testing.T) {
if len(DictMain)%2 == 1 {
t.Errorf("Dictionary is a not a multiple of 2")
}

words := make([]string, 0, len(DictMain)/2)
for i := 0; i < len(DictMain); i += 2 {
words = append(words, DictMain[i])
}

if !sort.IsSorted(sortByLen(words)) {
t.Errorf("Words not sorted by len, by alpha!")
t.Errorf("Words.go is autogenerated -- do not edit.")
Expand Down

0 comments on commit f8df434

Please sign in to comment.