From 2cf2126d6421a85461975824b9e610cded377c9e Mon Sep 17 00:00:00 2001 From: Steven Date: Wed, 2 Apr 2025 22:47:34 +0800 Subject: [PATCH] fix: golangci config --- .golangci.yaml | 30 ++++++++++++++++++++++------- plugin/httpgetter/html_meta_test.go | 7 ------- plugin/httpgetter/image.go | 2 +- 3 files changed, 24 insertions(+), 15 deletions(-) diff --git a/.golangci.yaml b/.golangci.yaml index 9f60ec5ba..670346d6a 100644 --- a/.golangci.yaml +++ b/.golangci.yaml @@ -2,8 +2,6 @@ version: "2" linters: enable: - - errcheck - - goimports - revive - govet - staticcheck @@ -16,10 +14,18 @@ linters: - forbidigo - mirror - bodyclose + disable: + - errcheck settings: - goimports: - # Put imports beginning with prefix after 3rd-party packages. - local-prefixes: github.com/usememos/memos + exhaustive: + explicit-exhaustive-switch: false + staticcheck: + checks: + - all + - -ST1000 + - -ST1003 + - -ST1021 + - -QF1003 revive: # Default to run all linters so that new rules in the future could automatically be added to the static check. enable-all-rules: true @@ -67,6 +73,8 @@ linters: disabled: true - name: redefines-builtin-id disabled: true + - name: package-comments + disabled: true gocritic: disabled-checks: - ifElseChain @@ -81,10 +89,18 @@ linters: - shadow forbidigo: forbid: - - 'fmt\.Errorf(# Please use errors\.Wrap\|Wrapf\|Errorf instead)?' - - 'ioutil\.ReadDir(# Please use os\.ReadDir)?' + - pattern: 'fmt\.Errorf(# Please use errors\.Wrap\|Wrapf\|Errorf instead)?' + - pattern: 'ioutil\.ReadDir(# Please use os\.ReadDir)?' issues: exclude: - Rollback - fmt.Printf + +formatters: + enable: + - goimports + settings: + goimports: + local-prefixes: + - github.com/usememos/memos diff --git a/plugin/httpgetter/html_meta_test.go b/plugin/httpgetter/html_meta_test.go index d0b0d9037..d1668db1d 100644 --- a/plugin/httpgetter/html_meta_test.go +++ b/plugin/httpgetter/html_meta_test.go @@ -2,7 +2,6 @@ package httpgetter import ( "errors" - "strings" "testing" "github.com/stretchr/testify/require" @@ -30,10 +29,4 @@ func TestGetHTMLMetaForInternal(t *testing.T) { if _, err := GetHTMLMeta("http://localhost"); !errors.Is(err, ErrInternalIP) { t.Errorf("Expected error for resolved internal IP, got %v", err) } - - // test for redirected internal IP - // 49.232.126.226:1110 will redirects to 127.0.0.1 - if _, err := GetHTMLMeta("http://49.232.126.226:1110"); !(errors.Is(err, ErrInternalIP) && strings.Contains(err.Error(), "redirect")) { - t.Errorf("Expected error for redirected internal IP, got %v", err) - } } diff --git a/plugin/httpgetter/image.go b/plugin/httpgetter/image.go index 2d6a163f2..536afea80 100644 --- a/plugin/httpgetter/image.go +++ b/plugin/httpgetter/image.go @@ -29,7 +29,7 @@ func GetImage(urlStr string) (*Image, error) { return nil, err } if !strings.HasPrefix(mediatype, "image/") { - return nil, errors.New("Wrong image mediatype") + return nil, errors.New("wrong image mediatype") } bodyBytes, err := io.ReadAll(response.Body)