From 661f042cb404264b0c4bcddf8b76232f3466bace Mon Sep 17 00:00:00 2001 From: Dmitry Verkhoturov Date: Thu, 9 May 2024 23:49:32 +0200 Subject: [PATCH] pin golangci-lint version to latest available, fix reported errors --- .github/workflows/ci-backend.yml | 4 ++-- backend/.golangci.yml | 17 ++++++++--------- backend/app/main.go | 2 +- backend/app/store/engine/bolt.go | 8 ++++---- backend/app/store/formatter.go | 6 +++--- 5 files changed, 18 insertions(+), 19 deletions(-) diff --git a/.github/workflows/ci-backend.yml b/.github/workflows/ci-backend.yml index ab4101b5..90784bcc 100644 --- a/.github/workflows/ci-backend.yml +++ b/.github/workflows/ci-backend.yml @@ -54,13 +54,13 @@ jobs: - name: golangci-lint uses: golangci/golangci-lint-action@v3 with: - version: latest + version: v1.58 working-directory: backend/app - name: golangci-lint on example directory uses: golangci/golangci-lint-action@v3 with: - version: latest + version: v1.58 args: --config ../../.golangci.yml working-directory: backend/_example/memory_store diff --git a/backend/.golangci.yml b/backend/.golangci.yml index 9c94c15f..7c3c7425 100644 --- a/backend/.golangci.yml +++ b/backend/.golangci.yml @@ -1,15 +1,10 @@ run: timeout: 5m - output: - format: tab - skip-dirs: - - vendor linters-settings: govet: - check-shadowing: true - maligned: - suggest-new: true + enable: + - shadow goconst: min-len: 2 min-occurrences: 2 @@ -31,11 +26,13 @@ linters-settings: linters: enable: - bodyclose - - megacheck + - gosimple + - staticcheck + - unused - revive - govet - unconvert - - gas + - gosec - gocyclo - dupl - misspell @@ -54,6 +51,8 @@ linters: disable-all: true issues: + exclude-dirs: + - vendor exclude-rules: - text: "at least one file in a package should have a package comment" linters: diff --git a/backend/app/main.go b/backend/app/main.go index 87bdff7b..c163ad1f 100644 --- a/backend/app/main.go +++ b/backend/app/main.go @@ -99,7 +99,7 @@ func getDump() string { return string(stacktrace[:length]) } -// nolint:gochecknoinits // can't avoid it in this place +//nolint:gochecknoinits // can't avoid it in this place func init() { // catch SIGQUIT and print stack traces sigChan := make(chan os.Signal, 1) diff --git a/backend/app/store/engine/bolt.go b/backend/app/store/engine/bolt.go index 3117c144..6e2abc7f 100644 --- a/backend/app/store/engine/bolt.go +++ b/backend/app/store/engine/bolt.go @@ -424,11 +424,11 @@ func (b *BoltDB) Close() error { } // Last returns up to max last comments for given siteID -func (b *BoltDB) lastComments(siteID string, max int, since time.Time) (comments []store.Comment, err error) { +func (b *BoltDB) lastComments(siteID string, maximum int, since time.Time) (comments []store.Comment, err error) { comments = []store.Comment{} - if max > lastLimit || max == 0 { - max = lastLimit + if maximum > lastLimit || maximum == 0 { + maximum = lastLimit } bdb, err := b.db(siteID) @@ -466,7 +466,7 @@ func (b *BoltDB) lastComments(siteID string, max int, since time.Time) (comments continue } comments = append(comments, comment) - if len(comments) >= max { + if len(comments) >= maximum { break } } diff --git a/backend/app/store/formatter.go b/backend/app/store/formatter.go index 0959a85e..550e6c73 100644 --- a/backend/app/store/formatter.go +++ b/backend/app/store/formatter.go @@ -57,14 +57,14 @@ func (f *CommentFormatter) FormatText(txt string, raw bool) (res string) { } // Shortens all the automatic links in HTML: auto link has equal "href" and "text" attributes. -func (f *CommentFormatter) shortenAutoLinks(commentHTML string, max int) (resHTML string) { +func (f *CommentFormatter) shortenAutoLinks(commentHTML string, maximum int) (resHTML string) { doc, err := goquery.NewDocumentFromReader(strings.NewReader(commentHTML)) if err != nil { return commentHTML } doc.Find("a").Each(func(_ int, s *goquery.Selection) { if href, ok := s.Attr("href"); ok { - if href != s.Text() || len(href) < max+3 || max < 3 { + if href != s.Text() || len(href) < maximum+3 || maximum < 3 { return } commentURL, e := url.Parse(href) @@ -77,7 +77,7 @@ func (f *CommentFormatter) shortenAutoLinks(commentHTML string, max int) (resHTM return } - short := string([]rune(href)[:max-3]) + short := string([]rune(href)[:maximum-3]) if len(short) < len(host) { short = host }