diff options
| author | Shulhan <ms@kilabit.info> | 2025-07-14 23:41:06 +0700 |
|---|---|---|
| committer | Shulhan <ms@kilabit.info> | 2025-07-14 23:44:57 +0700 |
| commit | 7f0664344c75f502e7e8f1baf1e394bcbb5ca1ad (patch) | |
| tree | f1dfefe17a835f0e00dbe96d742195ef61337568 | |
| parent | 6754efaefeec3290a690339df563890b85775458 (diff) | |
| download | kamusku-7f0664344c75f502e7e8f1baf1e394bcbb5ca1ad.tar.xz | |
all: replace golangci-lint with internal linter
The internal/cmd/gocheck use the go static analysis [Analyzer] that are
not included in the default go vet.
By using gocheck we found un-alignment and shadowing,
* client.go:18:13: struct with 24 pointer bytes could be 16
* dictionary.go:23:17: struct with 32 pointer bytes could be 16
* client_test.go:18:13: struct with 56 pointer bytes could be 48
* client_test.go:62:13: struct with 56 pointer bytes could be 48
* cmd/kamusku-telegram-bot/main.go:31:3: declaration of "err" shadows
declaration at line 25
* kamusku_test.go:49:3: declaration of "err" shadows declaration at
line 38
[Analyzer]: https://pkg.go.dev/golang.org/x/tools/go/analysis#hdr-Analyzer
| -rw-r--r-- | Makefile | 3 | ||||
| -rw-r--r-- | client.go | 2 | ||||
| -rw-r--r-- | client_test.go | 8 | ||||
| -rw-r--r-- | cmd/kamusku-telegram-bot/main.go | 10 | ||||
| -rw-r--r-- | dictionary.go | 4 | ||||
| -rw-r--r-- | internal/cmd/gocheck/main.go | 17 | ||||
| -rw-r--r-- | kamusku_test.go | 6 |
7 files changed, 35 insertions, 15 deletions
@@ -14,7 +14,8 @@ test: .PHONY: lint lint: - -golangci-lint run ./... + go vet ./... + go run ./internal/cmd/gocheck ./... -reuse lint .PHONY: embed @@ -16,8 +16,8 @@ import ( // Client is client that connect to cached server API. type Client struct { - url string conn *http.Client + url string } // NewClient create a new client for server API. diff --git a/client_test.go b/client_test.go index 94a0b4f..dd6f730 100644 --- a/client_test.go +++ b/client_test.go @@ -16,10 +16,10 @@ func TestApiClient_Lookup_offline(t *testing.T) { client := NewClient(testServerAPI) cases := []struct { - desc string - words []string exp kbbi.LookupResponse + desc string expError string + words []string }{{ desc: `With empty input`, }, { @@ -60,10 +60,10 @@ func TestApiClient_Lookup_online(t *testing.T) { client := NewClient(testServerAPI) cases := []struct { - desc string - words []string exp kbbi.LookupResponse expError string + desc string + words []string }{{ desc: `With empty input`, }, { diff --git a/cmd/kamusku-telegram-bot/main.go b/cmd/kamusku-telegram-bot/main.go index 3dc0828..8704507 100644 --- a/cmd/kamusku-telegram-bot/main.go +++ b/cmd/kamusku-telegram-bot/main.go @@ -19,18 +19,20 @@ func main() { var ( tgToken = `1121465148:AAE6Yf0YevYcyC--eCZyMqSpVia-pK5iFM4` tgWebhook = `https://kamusku.kilabit.info/telegram/webhook` + tgbot *kamusku.TelegramBot + err error ) // Use the token and Webhook URL from environment variables. - tgbot, err := kamusku.NewTelegramBot(tgToken, tgWebhook) + tgbot, err = kamusku.NewTelegramBot(tgToken, tgWebhook) if err != nil { log.Fatal(err) } go func() { - err := tgbot.Start() - if err != nil { - log.Println(err) + var errStart = tgbot.Start() + if errStart != nil { + log.Println(errStart) } }() diff --git a/dictionary.go b/dictionary.go index e58151f..836f3cd 100644 --- a/dictionary.go +++ b/dictionary.go @@ -21,10 +21,10 @@ const ( // dictionary contains cache of words and its definitions. type dictionary struct { - sync.Mutex cache map[string]*kbbi.Word - lastSize int storagePath string + lastSize int + sync.Mutex } // newDictionary create and initialize the cache for dictionary. diff --git a/internal/cmd/gocheck/main.go b/internal/cmd/gocheck/main.go new file mode 100644 index 0000000..956e790 --- /dev/null +++ b/internal/cmd/gocheck/main.go @@ -0,0 +1,17 @@ +// SPDX-FileCopyrightText: 2024 M. Shulhan <ms@kilabit.info> +// +// SPDX-License-Identifier: GPL-3.0-or-later + +// Program gocheck implement go static analysis using [Analyzer] that are not +// included in the default go vet. +// See package [lib/goanalysis] for more information. +// +// [Analyzer]: https://pkg.go.dev/golang.org/x/tools/go/analysis#hdr-Analyzer +// [lib/goanalysis]: https://pkg.go.dev/git.sr.ht/~shulhan/pakakeh.go/lib/goanalysis/ +package main + +import "git.sr.ht/~shulhan/pakakeh.go/lib/goanalysis" + +func main() { + goanalysis.Check() +} diff --git a/kamusku_test.go b/kamusku_test.go index 3d2989f..6a325df 100644 --- a/kamusku_test.go +++ b/kamusku_test.go @@ -46,9 +46,9 @@ func TestMain(m *testing.M) { testServer.kamus.set("mengeja", testKataMengeja) go func() { - err := testServer.Start() - if err != nil { - log.Fatal(err) + var errStart = testServer.Start() + if errStart != nil { + log.Fatal(errStart) } }() |
