Skip to content

Commit

Permalink
update golangci-lint
Browse files Browse the repository at this point in the history
  • Loading branch information
s12chung committed Apr 9, 2024
1 parent cb76fe6 commit 045ed06
Show file tree
Hide file tree
Showing 46 changed files with 158 additions and 134 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/golangci-lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ jobs:
uses: golangci/golangci-lint-action@v3
with:
# Optional: version of golangci-lint to use in form of v1.2 or v1.2.3 or `latest` to use the latest version
version: 'v1.54.2'
version: 'v1.57.2'

# Optional: working directory, useful for monorepos
# working-directory: somedir
Expand Down
22 changes: 21 additions & 1 deletion .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ linters:
- govet
- ineffassign
- staticcheck
- typecheck
- unused
# disabled by default
- asasalint
Expand All @@ -19,6 +18,7 @@ linters:
- bodyclose
- containedctx
- contextcheck
- copyloopvar
- cyclop
# - deadcode [deprecated]
- decorder
Expand All @@ -43,6 +43,7 @@ linters:
- gocheckcompilerdirectives
# - gochecknoglobals # globals are ok
# - gochecknoinits # init() is ok
- gochecksumtype
- gocognit
- goconst
- gocritic
Expand All @@ -64,8 +65,10 @@ linters:
- grouper
# - ifshort [deprecated]
- importas
- inamedparam
- interfacebloat
# - interfacer [deprecated]
- intrange
# - ireturn # return interfaces are fine
- lll
# - loggercheck # not using these logs
Expand All @@ -86,20 +89,25 @@ linters:
# - nosnakecase [deprecated]
- nosprintfhostport
# - paralleltest # not making every test parallel
- perfsprint
- prealloc
- predeclared
# - promlinter # not using prometheus
- protogetter
- reassign
- revive
- rowserrcheck
# - scopelint [deprecated]
- sloglint
- spancheck
- sqlclosecheck
# - structcheck [deprecated]
- stylecheck
- tagalign
- tagliatelle
- tenv
# - testableexamples # no output comments are ok
- testifylint
# - testpackage # _test packages are not preferred
# - thelper # no need to clean up call stack for tests
- tparallel
Expand Down Expand Up @@ -183,3 +191,15 @@ issues:
path: '(.+)_test\.go'
linters:
- forbidigo
# Does not apply for go 1.22
- text: "G601: Implicit memory aliasing in for loop."
linters:
- gosec
# context is not needed, should be used in the wrapper function
- source: 'jhttp\.ReturnModelOr500\(func\(\) \(any, error\)'
linters:
- contextcheck
# context is not needed, should be used in the wrapper function
- source: 'rs\.runOr500\(r, func\(r \*http\.Request, tx db\.TxQs\) error'
linters:
- contextcheck
4 changes: 2 additions & 2 deletions db/pkg/db/source.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"bufio"
"context"
"encoding/json"
"fmt"
"errors"
"io/fs"
"strings"
"time"
Expand Down Expand Up @@ -265,7 +265,7 @@ func (t TextTokenizer) TokenizedTexts(ctx context.Context, s, translation string
// TokenizeTexts takes the texts and tokenizes them
func (t TextTokenizer) TokenizeTexts(ctx context.Context, texts []text.Text) ([]TokenizedText, error) {
if !t.Tokenizer.IsSetup() {
return nil, fmt.Errorf("TextTokenizer not set up")
return nil, errors.New("TextTokenizer not set up")
}

tokenizedTexts := make([]TokenizedText, len(texts))
Expand Down
4 changes: 2 additions & 2 deletions db/pkg/db/source_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,14 +65,14 @@ func setupParts(t *testing.T, part SourcePart, prePartListID string) []SourcePar

parts := make([]SourcePart, 3)
baseKey := storage.BaseKey(SourcesTable, PartsColumn, prePartListID)
for i := 0; i < len(parts); i++ {
for i := range len(parts) {
parts[i] = part

key := baseKey + ".PreParts[" + strconv.Itoa(i) + "].Image.txt"
parts[i].Media = &SourcePartMedia{ImageKey: key}
require.NoError(storageAPI.Store(key, bytes.NewReader([]byte("image"+strconv.Itoa(i)))))
}
for i := 0; i < 1; i++ {
for i := range 1 {
key := baseKey + ".PreParts[0].Audio.txt"
parts[i].Media.AudioKey = key
require.NoError(storageAPI.Store(key, bytes.NewReader([]byte("audio"+strconv.Itoa(i)+"!"))))
Expand Down
10 changes: 5 additions & 5 deletions db/pkg/seedkrdict/seed.go
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ func (l *LexicalEntry) textVariants() (string, []string, error) {

var err error
if text == "" {
err = fmt.Errorf("LexicalEntry.writtenForm not found")
err = errors.New("LexicalEntry.writtenForm not found")
}
return text, variants, err
}
Expand Down Expand Up @@ -295,7 +295,7 @@ func (s *Sense) translation() (dictionary.Translation, error) {
}
return translation, nil
}
return dictionary.Translation{}, fmt.Errorf("not found")
return dictionary.Translation{}, errors.New("not found")
}

// Equivalent represents the translation of the entry given a special language
Expand All @@ -318,7 +318,7 @@ func (e *Equivalent) translation() (dictionary.Translation, error) {
}
}
if !isEng {
return dictionary.Translation{}, fmt.Errorf("not found")
return dictionary.Translation{}, errors.New("not found")
}

text, explanation := "", ""
Expand All @@ -333,10 +333,10 @@ func (e *Equivalent) translation() (dictionary.Translation, error) {

var err error
if text == "" {
err = fmt.Errorf("text is empty")
err = errors.New("text is empty")
}
if explanation == "" {
err = fmt.Errorf("explanation is empty")
err = errors.New("explanation is empty")
}
for k, v := range cleanTranslationMap {
explanation = strings.ReplaceAll(explanation, k, v)
Expand Down
4 changes: 2 additions & 2 deletions db/pkg/seedkrdict/seed_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package seedkrdict

import (
"fmt"
"errors"
"testing"

"github.com/stretchr/testify/require"
Expand Down Expand Up @@ -74,7 +74,7 @@ func TestIsNoTranslationsFoundError(t *testing.T) {
require := require.New(t)
t.Parallel()
require.True(IsNoTranslationsFoundError(NoTranslationsFoundError{}))
require.False(IsNoTranslationsFoundError(fmt.Errorf("test error")))
require.False(IsNoTranslationsFoundError(errors.New("test error")))
}

func TestLexicalEntry_CreateParams(t *testing.T) {
Expand Down
5 changes: 3 additions & 2 deletions integrations/tokenizers/khaiii/pkg/khaiii/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ typedef struct khaiii_word_t_ {
import "C"

import (
"errors"
"fmt"
"unsafe"
)
Expand Down Expand Up @@ -70,7 +71,7 @@ func (k *Khaiii) Version() string {
// Open opens the training resource directory
func (k *Khaiii) Open(rscDir string) error {
if k.openHandle != 0 {
return fmt.Errorf("Khaiii.Open() is already open")
return errors.New("Khaiii.Open() is already open")
}
openHandle := open(rscDir, "{}")
if openHandle == -1 {
Expand All @@ -83,7 +84,7 @@ func (k *Khaiii) Open(rscDir string) error {
// Analyze analyzes the input string
func (k *Khaiii) Analyze(input string) ([]Word, error) {
if k.openHandle <= 0 {
return nil, fmt.Errorf("Khaiii.Open() invalid for Analyze()")
return nil, errors.New("Khaiii.Open() invalid for Analyze()")
}

var err error
Expand Down
3 changes: 2 additions & 1 deletion pkg/api/pre_part_lists.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package api

import (
"errors"
"fmt"
"net/http"

Expand Down Expand Up @@ -85,7 +86,7 @@ func (rs Routes) PrePartListSign(r *http.Request, _ db.TxQs) (any, *jhttp.HTTPEr
func (rs Routes) PrePartListGet(r *http.Request, _ db.TxQs) (any, *jhttp.HTTPError) {
prePartListID := chi.URLParam(r, "id")
if prePartListID == "" {
return nil, jhttp.Error(http.StatusNotFound, fmt.Errorf("id not found"))
return nil, jhttp.Error(http.StatusNotFound, errors.New("id not found"))
}
prePartList := db.PrePartListURL{}
err := rs.Storage.DBStorage.SignGetTree(db.SourcesTable, db.PartsColumn, prePartListID, &prePartList)
Expand Down
2 changes: 1 addition & 1 deletion pkg/api/pre_part_lists_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ func TestRoutes_PrePartListGet(t *testing.T) {

func setupPreParts(t *testing.T, id string) {
baseKey := storage.BaseKey(db.SourcesTable, db.PartsColumn, id)
for i := 0; i < 2; i++ {
for i := range 2 {
err := routes.Storage.Storer.Store(baseKey+".PreParts["+strconv.Itoa(i)+"].Image.txt", bytes.NewReader([]byte("image"+strconv.Itoa(i))))
require.NoError(t, err)
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/api/sources.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package api

import (
"context"
"fmt"
"errors"
"net/http"
"strings"

Expand Down Expand Up @@ -180,7 +180,7 @@ func (rs Routes) requestPartsToDBParts(ctx context.Context, reqParts []PartCreat
parts = append(parts, sourcePart)
}
if len(parts) == 0 {
return nil, jhttp.Error(http.StatusUnprocessableEntity, fmt.Errorf("no parts found with text set"))
return nil, jhttp.Error(http.StatusUnprocessableEntity, errors.New("no parts found with text set"))
}
return parts, nil
}
10 changes: 5 additions & 5 deletions pkg/api/sources_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package api

import (
"bytes"
"fmt"
"errors"
"net/http"
"strconv"
"strings"
Expand Down Expand Up @@ -168,7 +168,7 @@ func TestRoutes_SourceDestroy(t *testing.T) {
}

_, err := txQs.SourceGet(txQs.Ctx(), created.ID)
require.Equal(fmt.Errorf("sql: no rows in result set"), err)
require.Equal(errors.New("sql: no rows in result set"), err)
})
}
}
Expand All @@ -185,7 +185,7 @@ func setupSourceCreateMediaWithInfo(t *testing.T, prePartListID string) {
func setupSourceCreateMedia(t *testing.T, prePartListID string) {
baseKey := storage.BaseKey(db.SourcesTable, db.PartsColumn, prePartListID)

for i := 0; i < 3; i++ {
for i := range 3 {
err := routes.Storage.Storer.Store(baseKey+".PreParts["+strconv.Itoa(i)+"].Image.txt", bytes.NewReader([]byte("image"+strconv.Itoa(i))))
require.NoError(t, err)
}
Expand All @@ -206,11 +206,11 @@ func sourceCreateRequestParts(t *testing.T, caseName, testName string, partCount
case "51_parts":
partsLen := 51
parts = make([]PartCreateMultiRequestPart, partsLen)
for i := 0; i < partsLen; i++ {
for i := range partsLen {
parts[i] = PartCreateMultiRequestPart{}
}
default:
for i := 0; i < partCount; i++ {
for i := range partCount {
parts[i] = sourceCreateRequestPartFromFile(t, testName, caseName+strconv.Itoa(i)+".txt")
}
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/dictionary/koreanbasic/koreanbasic_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ func TestPartOfSpeechToAPIIntMatch(t *testing.T) {
func TestMergePosMap(t *testing.T) {
require := require.New(t)

require.Equal(lang.PartOfSpeechCount, len(mergePosMap))
require.Len(mergePosMap, lang.PartOfSpeechCount)

uniquePosMapValues := map[lang.PartOfSpeech]bool{}
for _, v := range partOfSpeechMap {
Expand Down
2 changes: 1 addition & 1 deletion pkg/dictionary/krdict/krdict_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ func TestKrDict_Search(t *testing.T) {
func TestMergePosMap(t *testing.T) {
require := require.New(t)

require.Equal(lang.PartOfSpeechCount, len(mergePosMap))
require.Len(mergePosMap, lang.PartOfSpeechCount)

posMap := seedkrdict.PartOfSpeechMap()
uniquePosMapValues := map[lang.PartOfSpeech]bool{}
Expand Down
6 changes: 3 additions & 3 deletions pkg/extractor/extractor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package extractor_test

import (
"encoding/json"
"fmt"
"errors"
"io"
"os"
"path"
Expand Down Expand Up @@ -45,8 +45,8 @@ func TestExtractor_Extract(t *testing.T) {
err error
}{
{name: "basic", s: extractortest.VerifyString},
{name: "skip_extract", s: extractortest.SkipExtractString, err: fmt.Errorf("no filenames that match extensions extracted: .jpg, .png")},
{name: "no_verify", s: "fail", err: fmt.Errorf("string does not match factory source: fail")},
{name: "skip_extract", s: extractortest.SkipExtractString, err: errors.New("no filenames that match extensions extracted: .jpg, .png")},
{name: "no_verify", s: "fail", err: errors.New("string does not match factory source: fail")},
}
for _, tc := range testCases {
t.Run(tc.name, func(t *testing.T) {
Expand Down
4 changes: 2 additions & 2 deletions pkg/extractor/extractortest/extractortest.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
package extractortest

import (
"fmt"
"errors"
"os"
"path/filepath"

Expand Down Expand Up @@ -56,7 +56,7 @@ func (t Source) ExtractToDir(cacheDir string) error {
return err
}
if len(items) != 0 {
return fmt.Errorf("extracting to non-empty cacheDir")
return errors.New("extracting to non-empty cacheDir")
}
return filepath.Walk(t.fixturePath, func(path string, info os.FileInfo, err error) error {
if err != nil {
Expand Down
3 changes: 2 additions & 1 deletion pkg/extractor/instagram/instagram.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package instagram

import (
"encoding/json"
"errors"
"fmt"
"net/url"
"os"
Expand Down Expand Up @@ -99,7 +100,7 @@ func numberPadFilenames(cacheDir string) error {
for _, filename := range filenames {
parts := strings.Split(filename, "_")
if len(parts) < 2 {
return fmt.Errorf("file found with no underscore")
return errors.New("file found with no underscore")
}
numberPart := strings.Split(parts[len(parts)-1], ".")[0]
number, err := strconv.Atoi(numberPart)
Expand Down
4 changes: 2 additions & 2 deletions pkg/extractor/instagram/instagram_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package instagram

import (
"fmt"
"errors"
"os"
"path"
"path/filepath"
Expand Down Expand Up @@ -84,7 +84,7 @@ func TestPost_ExtractToDir(t *testing.T) {
url string
err error
}{
{name: "broken", url: "https://waka.com", err: fmt.Errorf("url is not verified for instagram: https://waka.com")},
{name: "broken", url: "https://waka.com", err: errors.New("url is not verified for instagram: https://waka.com")},
{name: "fake", url: testURL},
}
for _, tc := range testCases {
Expand Down
2 changes: 1 addition & 1 deletion pkg/firm/error.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ type ErrorKey string
// RootTypeName returns the type name of the key
func (e ErrorKey) RootTypeName() string {
suffix := string(e)
for i := 0; i < 2; i++ {
for range 2 {
index := strings.Index(suffix, keySeparator)
if index == -1 {
return ""
Expand Down
Loading

0 comments on commit 045ed06

Please sign in to comment.