From 419469c29752aeddc48d9a1c7c2af689ebe10edd Mon Sep 17 00:00:00 2001 From: Winni Neessen Date: Mon, 17 Oct 2022 18:10:24 +0200 Subject: [PATCH 01/14] Introduce golangci-lint --- .gitignore | 2 +- .golangci.toml | 7 +++++++ 2 files changed, 8 insertions(+), 1 deletion(-) create mode 100644 .golangci.toml diff --git a/.gitignore b/.gitignore index 0d4d42d..b6f3875 100644 --- a/.gitignore +++ b/.gitignore @@ -20,7 +20,7 @@ # Local testfiles and auth data .auth -cmd/* +examples/* # SonarQube .scannerwork/ diff --git a/.golangci.toml b/.golangci.toml new file mode 100644 index 0000000..f10bc89 --- /dev/null +++ b/.golangci.toml @@ -0,0 +1,7 @@ +[run] +go = "1.16" +tests = true + +[linters] +enable = ["stylecheck", "whitespace", "containedctx", "contextcheck", "decorder", + "errname", "errorlint", "gofmt", "gofumpt"] \ No newline at end of file From 5bea905ff90a827da836c5759bd7df0464035b3f Mon Sep 17 00:00:00 2001 From: Winni Neessen Date: Mon, 17 Oct 2022 18:12:18 +0200 Subject: [PATCH 02/14] Make golangci-lint gofumpt happy --- auth/auth_test.go | 10 +++++++--- client.go | 3 ++- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/auth/auth_test.go b/auth/auth_test.go index e1a57b2..75875af 100644 --- a/auth/auth_test.go +++ b/auth/auth_test.go @@ -20,9 +20,13 @@ func TestAuth(t *testing.T) { } authTests := []authTest{ - {LoginAuth("user", "pass", "testserver"), - []string{"Username:", "Password:", "2.7.0 Authentication successful", "Invalid:"}, "LOGIN", - []string{"", "user", "pass", "", ""}, []bool{false, false, false, true}}, + { + LoginAuth("user", "pass", "testserver"), + []string{"Username:", "Password:", "2.7.0 Authentication successful", "Invalid:"}, + "LOGIN", + []string{"", "user", "pass", "", ""}, + []bool{false, false, false, true}, + }, } testLoop: diff --git a/client.go b/client.go index 9fb5301..ddc54f1 100644 --- a/client.go +++ b/client.go @@ -9,12 +9,13 @@ import ( "crypto/tls" "errors" "fmt" - "github.com/wneessen/go-mail/auth" "net" "net/smtp" "os" "strings" "time" + + "github.com/wneessen/go-mail/auth" ) // Defaults From 94ad8af58a0cc7f50be3d7692ec01acf0576b169 Mon Sep 17 00:00:00 2001 From: Winni Neessen Date: Mon, 17 Oct 2022 18:13:00 +0200 Subject: [PATCH 03/14] Make golangci-lint gofumpt happy --- client_test.go | 17 ++++++++++------- encoding.go | 2 +- 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/client_test.go b/client_test.go index d7e568a..47965ac 100644 --- a/client_test.go +++ b/client_test.go @@ -8,11 +8,12 @@ import ( "context" "crypto/tls" "fmt" - "github.com/wneessen/go-mail/auth" "net/smtp" "os" "testing" "time" + + "github.com/wneessen/go-mail/auth" ) // DefaultHost is used as default hostname for the Client @@ -89,9 +90,11 @@ func TestNewClientWithOptions(t *testing.T) { {"WithTLSConfig()", WithTLSConfig(&tls.Config{}), false}, {"WithTLSConfig(); config is nil", WithTLSConfig(nil), true}, {"WithSMTPAuth()", WithSMTPAuth(SMTPAuthLogin), false}, - {"WithSMTPAuthCustom()", + { + "WithSMTPAuthCustom()", WithSMTPAuthCustom(smtp.PlainAuth("", "", "", "")), - false}, + false, + }, {"WithUsername()", WithUsername("test"), false}, {"WithPassword()", WithPassword("test"), false}, {"WithDSN()", WithDSN(), false}, @@ -99,8 +102,10 @@ func TestNewClientWithOptions(t *testing.T) { {"WithDSNMailReturnType() wrong option", WithDSNMailReturnType("FAIL"), true}, {"WithDSNRcptNotifyType()", WithDSNRcptNotifyType(DSNRcptNotifySuccess), false}, {"WithDSNRcptNotifyType() wrong option", WithDSNRcptNotifyType("FAIL"), true}, - {"WithDSNRcptNotifyType() NEVER combination", - WithDSNRcptNotifyType(DSNRcptNotifySuccess, DSNRcptNotifyNever), true}, + { + "WithDSNRcptNotifyType() NEVER combination", + WithDSNRcptNotifyType(DSNRcptNotifySuccess, DSNRcptNotifyNever), true, + }, } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { @@ -796,7 +801,6 @@ func TestClient_DialSendCloseBroken(t *testing.T) { } }) } - } // TestClient_DialSendCloseBrokenWithDSN tests the Dial(), Send() and Close() method of Client with @@ -857,7 +861,6 @@ func TestClient_DialSendCloseBrokenWithDSN(t *testing.T) { } }) } - } // TestClient_auth tests the Dial(), Send() and Close() method of Client with broken settings diff --git a/encoding.go b/encoding.go index 3fd20e0..f10a903 100644 --- a/encoding.go +++ b/encoding.go @@ -132,7 +132,7 @@ const ( // List of MIME versions const ( - //Mime10 is the MIME Version 1.0 + // Mime10 is the MIME Version 1.0 Mime10 MIMEVersion = "1.0" ) From 321b512c95c44bf246b3a4b6b78022597513ca72 Mon Sep 17 00:00:00 2001 From: Winni Neessen Date: Mon, 17 Oct 2022 18:13:28 +0200 Subject: [PATCH 04/14] Make golangci-lint gofumpt happy --- doc_test.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/doc_test.go b/doc_test.go index 8a71f11..dbf3604 100644 --- a/doc_test.go +++ b/doc_test.go @@ -7,10 +7,11 @@ package mail_test import ( "context" "fmt" - "github.com/wneessen/go-mail" "os" "text/template" "time" + + "github.com/wneessen/go-mail" ) // Code example for the NewClient method From d200e982bf62d320bca1a9fde416e381a38386ab Mon Sep 17 00:00:00 2001 From: Winni Neessen Date: Mon, 17 Oct 2022 18:16:00 +0200 Subject: [PATCH 05/14] Make golangci-lint errorlint happy --- client.go | 4 ++-- client_test.go | 8 ++++---- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/client.go b/client.go index ddc54f1..eb608bb 100644 --- a/client.go +++ b/client.go @@ -505,7 +505,7 @@ func (c *Client) Send(ml ...*Msg) error { } if err := c.Reset(); err != nil { - return fmt.Errorf("sending RSET command failed: %s", err) + return fmt.Errorf("sending RSET command failed: %w", err) } if err := c.checkConn(); err != nil { return fmt.Errorf("failed to check server connection: %w", err) @@ -556,7 +556,7 @@ func (c *Client) DialAndSendWithContext(ctx context.Context, ml ...*Msg) error { return fmt.Errorf("send failed: %w", err) } if err := c.Close(); err != nil { - return fmt.Errorf("failed to close connction: %s", err) + return fmt.Errorf("failed to close connction: %w", err) } return nil } diff --git a/client_test.go b/client_test.go index 47965ac..645d142 100644 --- a/client_test.go +++ b/client_test.go @@ -951,10 +951,10 @@ func getTestConnection(auth bool) (*Client, error) { } } if err := c.DialWithContext(context.Background()); err != nil { - return c, fmt.Errorf("connection to test server failed: %s", err) + return c, fmt.Errorf("connection to test server failed: %w", err) } if err := c.Close(); err != nil { - return c, fmt.Errorf("disconnect from test server failed: %s", err) + return c, fmt.Errorf("disconnect from test server failed: %w", err) } return c, nil } @@ -988,10 +988,10 @@ func getTestConnectionWithDSN(auth bool) (*Client, error) { } } if err := c.DialWithContext(context.Background()); err != nil { - return c, fmt.Errorf("connection to test server failed: %s", err) + return c, fmt.Errorf("connection to test server failed: %w", err) } if err := c.Close(); err != nil { - return c, fmt.Errorf("disconnect from test server failed: %s", err) + return c, fmt.Errorf("disconnect from test server failed: %w", err) } return c, nil } From 872315ed8041d28df7289937dd29d0894ee62126 Mon Sep 17 00:00:00 2001 From: Winni Neessen Date: Mon, 17 Oct 2022 18:18:32 +0200 Subject: [PATCH 06/14] Create golangci-lint.yml --- .github/workflows/golangci-lint.yml | 46 +++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 .github/workflows/golangci-lint.yml diff --git a/.github/workflows/golangci-lint.yml b/.github/workflows/golangci-lint.yml new file mode 100644 index 0000000..448f349 --- /dev/null +++ b/.github/workflows/golangci-lint.yml @@ -0,0 +1,46 @@ +name: golangci-lint +on: + push: + tags: + - v* + branches: + - master + - main + pull_request: +permissions: + contents: read + # Optional: allow read access to pull request. Use with `only-new-issues` option. + # pull-requests: read +jobs: + golangci: + name: lint + runs-on: ubuntu-latest + steps: + - uses: actions/setup-go@v3 + with: + go-version: 1.19 + - uses: actions/checkout@v3 + - name: golangci-lint + 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.29 + + # Optional: working directory, useful for monorepos + # working-directory: somedir + + # Optional: golangci-lint command line arguments. + # args: --issues-exit-code=0 + + # Optional: show only new issues if it's a pull request. The default value is `false`. + # only-new-issues: true + + # Optional: if set to true then the all caching functionality will be complete disabled, + # takes precedence over all other caching options. + # skip-cache: true + + # Optional: if set to true then the action don't cache or restore ~/go/pkg. + # skip-pkg-cache: true + + # Optional: if set to true then the action don't cache or restore ~/.cache/go-build. + # skip-build-cache: true From d4ae5fe07cfd257606bb50a4956e8b400267a1b3 Mon Sep 17 00:00:00 2001 From: Winni Neessen Date: Mon, 17 Oct 2022 18:19:50 +0200 Subject: [PATCH 07/14] Fix golangci-lint config SPDX license --- .golangci.toml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.golangci.toml b/.golangci.toml index f10bc89..7d1b888 100644 --- a/.golangci.toml +++ b/.golangci.toml @@ -1,3 +1,7 @@ +## SPDX-FileCopyrightText: 2022 Winni Neessen +## +## SPDX-License-Identifier: MIT + [run] go = "1.16" tests = true From 0149003d492597b5033a2051a3a8b43a74a431e0 Mon Sep 17 00:00:00 2001 From: Winni Neessen Date: Mon, 17 Oct 2022 18:20:37 +0200 Subject: [PATCH 08/14] Update golangci-lint.yml --- .github/workflows/golangci-lint.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/workflows/golangci-lint.yml b/.github/workflows/golangci-lint.yml index 448f349..72cc044 100644 --- a/.github/workflows/golangci-lint.yml +++ b/.github/workflows/golangci-lint.yml @@ -4,7 +4,6 @@ on: tags: - v* branches: - - master - main pull_request: permissions: From 9e2fc70ee698301c6abca3ed7163fa960be85ced Mon Sep 17 00:00:00 2001 From: Winni Neessen Date: Mon, 17 Oct 2022 18:21:28 +0200 Subject: [PATCH 09/14] Update golangci-lint.yml --- .github/workflows/golangci-lint.yml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.github/workflows/golangci-lint.yml b/.github/workflows/golangci-lint.yml index 72cc044..410b2d4 100644 --- a/.github/workflows/golangci-lint.yml +++ b/.github/workflows/golangci-lint.yml @@ -1,3 +1,7 @@ +# SPDX-FileCopyrightText: 2022 Winni Neessen +# +# SPDX-License-Identifier: CC0-1.0 + name: golangci-lint on: push: From d89f50ec6ba9df381774663f130c94621e9fd21c Mon Sep 17 00:00:00 2001 From: Winni Neessen Date: Mon, 17 Oct 2022 18:26:54 +0200 Subject: [PATCH 10/14] Update golangci-lint config --- .golangci.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.golangci.toml b/.golangci.toml index 7d1b888..b876a3a 100644 --- a/.golangci.toml +++ b/.golangci.toml @@ -7,5 +7,5 @@ go = "1.16" tests = true [linters] -enable = ["stylecheck", "whitespace", "containedctx", "contextcheck", "decorder", +enable = ["stylecheck", "whitespace", "contextcheck", "decorder", "errname", "errorlint", "gofmt", "gofumpt"] \ No newline at end of file From 69a97c7c9821d48e01989e30997d2fa2b39b36f6 Mon Sep 17 00:00:00 2001 From: Winni Neessen Date: Mon, 17 Oct 2022 18:27:53 +0200 Subject: [PATCH 11/14] Update golangci-lint config --- .golangci.toml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/.golangci.toml b/.golangci.toml index b876a3a..1b700db 100644 --- a/.golangci.toml +++ b/.golangci.toml @@ -7,5 +7,4 @@ go = "1.16" tests = true [linters] -enable = ["stylecheck", "whitespace", "contextcheck", "decorder", - "errname", "errorlint", "gofmt", "gofumpt"] \ No newline at end of file +enable = ["stylecheck", "whitespace", "decorder", "errname", "errorlint", "gofmt", "gofumpt"] \ No newline at end of file From 03b591661530617516b27854f5dc066d4b3a2049 Mon Sep 17 00:00:00 2001 From: Winni Neessen Date: Mon, 17 Oct 2022 18:29:18 +0200 Subject: [PATCH 12/14] Update golangci-lint config --- .golangci.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.golangci.toml b/.golangci.toml index 1b700db..680d6d6 100644 --- a/.golangci.toml +++ b/.golangci.toml @@ -7,4 +7,4 @@ go = "1.16" tests = true [linters] -enable = ["stylecheck", "whitespace", "decorder", "errname", "errorlint", "gofmt", "gofumpt"] \ No newline at end of file +enable = ["stylecheck", "whitespace", "errname", "errorlint", "gofmt", "gofumpt"] \ No newline at end of file From b01947117bd6559f69676f357482adb597a6d6f4 Mon Sep 17 00:00:00 2001 From: Winni Neessen Date: Mon, 17 Oct 2022 18:34:05 +0200 Subject: [PATCH 13/14] Update golangci-lint config --- .golangci.toml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.golangci.toml b/.golangci.toml index 680d6d6..7d1b888 100644 --- a/.golangci.toml +++ b/.golangci.toml @@ -7,4 +7,5 @@ go = "1.16" tests = true [linters] -enable = ["stylecheck", "whitespace", "errname", "errorlint", "gofmt", "gofumpt"] \ No newline at end of file +enable = ["stylecheck", "whitespace", "containedctx", "contextcheck", "decorder", + "errname", "errorlint", "gofmt", "gofumpt"] \ No newline at end of file From 8c6f291b3887d0a9986d1d2bd52aed5b5b51f0cc Mon Sep 17 00:00:00 2001 From: Winni Neessen Date: Mon, 17 Oct 2022 18:35:53 +0200 Subject: [PATCH 14/14] Update golangci-lint.yml --- .github/workflows/golangci-lint.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/golangci-lint.yml b/.github/workflows/golangci-lint.yml index 410b2d4..2d0a327 100644 --- a/.github/workflows/golangci-lint.yml +++ b/.github/workflows/golangci-lint.yml @@ -27,7 +27,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.29 + version: latest # Optional: working directory, useful for monorepos # working-directory: somedir