Repository: goreleaser/nfpm
Pull request #631 (2023-03-09 12:48:08)

refactor: stricter golangci-lint ruleset
pretty much merged with goreleaser's and fixed all issues

cloudflare-pages[bot]: ## Deploying with &nbsp;<a href="https://pages.dev"><img alt="Cloudflare Pages" src="https://user-images.githubusercontent.com/23264/106598434-9e719e00-654f-11eb-9e59-6167043cfa01.png" width="16"></a> &nbsp;Cloudflare Pages

<table><tr><td><strong>Latest commit:</strong> </td><td>
<code>51fb0b1</code>
</td></tr>
<tr><td><strong>Status:</strong></td><td>&nbsp;✅&nbsp; Deploy successful!</td></tr>
<tr><td><strong>Preview URL:</strong></td><td>
<a href='https://3bcde99c.nfpm.pages.dev'>https://3bcde99c.nfpm.pages.dev</a>
</td></tr>
<tr><td><strong>Branch Preview URL:</strong></td><td>
<a href='https://lint.nfpm.pages.dev'>https://lint.nfpm.pages.dev</a>
</td></tr>
</table>

[View logs](https://dash.cloudflare.com/?to=/:account/pages/view/nfpm/3bcde99c-5e23-48df-80b9-47673fb70775)

codecov[bot]: # [Codecov](https://codecov.io/gh/goreleaser/nfpm/pull/631?src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=goreleaser) Report
> Merging [#631](https://codecov.io/gh/goreleaser/nfpm/pull/631?src=pr&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=goreleaser) (51fb0b1) into [main](https://codecov.io/gh/goreleaser/nfpm/commit/745ad27658348663cfee4975cd45dcdf7d9a3b54?el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=goreleaser) (745ad27) will **decrease** coverage by `0.04%`.
> The diff coverage is `88.00%`.

```diff
@@            Coverage Diff             @@
##             main     #631      +/-   ##
==========================================
- Coverage   75.74%   75.71%   -0.04%     
==========================================
  Files          14       14              
  Lines        2948     2944       -4     
==========================================
- Hits         2233     2229       -4     
  Misses        506      506              
  Partials      209      209              
```


| [Impacted Files](https://codecov.io/gh/goreleaser/nfpm/pull/631?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=goreleaser) | Coverage Δ | |
|---|---|---|
| [internal/sign/pgp.go](https://codecov.io/gh/goreleaser/nfpm/pull/631?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=goreleaser#diff-aW50ZXJuYWwvc2lnbi9wZ3AuZ28=) | `65.31% <80.00%> (ø)` | |
| [apk/apk.go](https://codecov.io/gh/goreleaser/nfpm/pull/631?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=goreleaser#diff-YXBrL2Fway5nbw==) | `73.51% <100.00%> (-0.19%)` | :arrow_down: |
| [arch/arch.go](https://codecov.io/gh/goreleaser/nfpm/pull/631?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=goreleaser#diff-YXJjaC9hcmNoLmdv) | `78.52% <100.00%> (ø)` | |
| [deb/deb.go](https://codecov.io/gh/goreleaser/nfpm/pull/631?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=goreleaser#diff-ZGViL2RlYi5nbw==) | `71.34% <100.00%> (-0.12%)` | :arrow_down: |
| [files/files.go](https://codecov.io/gh/goreleaser/nfpm/pull/631?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=goreleaser#diff-ZmlsZXMvZmlsZXMuZ28=) | `77.52% <100.00%> (ø)` | |
| [rpm/rpm.go](https://codecov.io/gh/goreleaser/nfpm/pull/631?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=goreleaser#diff-cnBtL3JwbS5nbw==) | `70.28% <100.00%> (ø)` | |

Help us with your feedback. Take ten seconds to tell us [how you rate us](https://about.codecov.io/nps?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=goreleaser). Have a feature suggestion? [Share it here.](https://app.codecov.io/gh/feedback/?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=goreleaser)


Patch:
diff --git a/.golangci.yml b/.golangci.yml
index 538f529..0582883 100644
--- a/.golangci.yml
+++ b/.golangci.yml
@@ -1,6 +1,31 @@
 run:
+  go: '1.20'
   timeout: 5m
 linters:
   enable:
     - thelper
     - gofumpt
+    - tparallel
+    - unconvert
+    - unparam
+    - wastedassign
+    - revive
+    - forbidigo
+    - tagliatelle
+    - misspell
+    - depguard
+
+linters-settings:
+  forbidigo:
+    forbid:
+      - 'ioutil\.*'
+  tagliatelle:
+    case:
+      use-field-name: false
+      rules:
+        yaml: snake
+        json: snake
+  depguard:
+     list-type: 'denylist'
+     packages-with-error-message:
+       - 'github.com/pkg/errors': 'use stdlib instead'
diff --git a/apk/apk.go b/apk/apk.go
index ebc9f87..5788c81 100644
--- a/apk/apk.go
+++ b/apk/apk.go
@@ -395,14 +395,12 @@ func newItemInsideTarGz(out *tar.Writer, content []byte, header *tar.Header) err
 }
 
 func createBuilderData(info *nfpm.Info, sizep *int64) func(tw *tar.Writer) error {
-	created := map[string]bool{}
-
 	return func(tw *tar.Writer) error {
-		return createFilesInsideTarGz(info, tw, created, sizep)
+		return createFilesInsideTarGz(info, tw, sizep)
 	}
 }
 
-func createFilesInsideTarGz(info *nfpm.Info, tw *tar.Writer, created map[string]bool, sizep *int64) (err error) {
+func createFilesInsideTarGz(info *nfpm.Info, tw *tar.Writer, sizep *int64) (err error) {
 	for _, file := range info.Contents {
 		file.Destination = strings.TrimPrefix(file.Destination, "./")
 
diff --git a/arch/arch.go b/arch/arch.go
index 1c96016..90fad30 100644
--- a/arch/arch.go
+++ b/arch/arch.go
@@ -33,6 +33,8 @@ func init() {
 // nolint: gochecknoglobals
 var Default = ArchLinux{}
 
+// ArchLinux packager.
+// nolint: revive
 type ArchLinux struct{}
 
 // nolint: gochecknoglobals
@@ -149,7 +151,7 @@ func (ArchLinux) Package(info *nfpm.Info, w io.Writer) error {
 	// .PKGINFO must be the first entry in .MTREE
 	entries = append([]MtreeEntry{*pkginfoEntry}, entries...)
 
-	err = createMtree(info, tw, entries)
+	err = createMtree(tw, entries)
 	if err != nil {
 		return fmt.Errorf("create mtree: %w", err)
 	}
@@ -483,7 +485,7 @@ func (me *MtreeEntry) WriteTo(w io.Writer) (int64, error) {
 	}
 }
 
-func createMtree(info *nfpm.Info, tw *tar.Writer, entries []MtreeEntry) error {
+func createMtree(tw *tar.Writer, entries []MtreeEntry) error {
 	buf := &bytes.Buffer{}
 	gw := pgzip.NewWriter(buf)
 	defer gw.Close()
diff --git a/deb/deb.go b/deb/deb.go
index ddb31f9..565833f 100644
--- a/deb/deb.go
+++ b/deb/deb.go
@@ -350,9 +350,7 @@ func fillDataTar(info *nfpm.Info, w io.Writer) (md5sums []byte, instSize int64,
 	// an error in another part of the code.
 	defer out.Close() // nolint: errcheck
 
-	created := map[string]bool{}
-
-	md5buf, instSize, err := createFilesInsideDataTar(info, out, created)
+	md5buf, instSize, err := createFilesInsideDataTar(info, out)
 	if err != nil {
 		return nil, 0, err
 	}
@@ -364,9 +362,7 @@ func fillDataTar(info *nfpm.Info, w io.Writer) (md5sums []byte, instSize int64,
 	return md5buf.Bytes(), instSize, nil
 }
 
-func createFilesInsideDataTar(info *nfpm.Info, tw *tar.Writer,
-	created map[string]bool,
-) (md5buf bytes.Buffer, instSize int64, err error) {
+func createFilesInsideDataTar(info *nfpm.Info, tw *tar.Writer) (md5buf bytes.Buffer, instSize int64, err error) {
 	// create files and implicit directories
 	for _, file := range info.Contents {
 		var size int64 // declare early to avoid shadowing err
diff --git a/files/files.go b/files/files.go
index 1944616..7e1b8cc 100644
--- a/files/files.go
+++ b/files/files.go
@@ -338,7 +338,7 @@ func addParents(contentMap map[string]*Content, path string) error {
 		c, ok := contentMap[parent]
 		if ok {
 			// either we already created this directory as an explicit directory
-			// or as an implict directory of another file
+			// or as an implicit directory of another file
 			if c.Type == TypeDir || c.Type == TypeImplicitDir {
 				continue
 			}
diff --git a/internal/cmd/root.go b/internal/cmd/root.go
index b917e02..f8f9978 100644
--- a/internal/cmd/root.go
+++ b/internal/cmd/root.go
@@ -3,10 +3,10 @@ package cmd
 import (
 	"fmt"
 
-	_ "github.com/goreleaser/nfpm/v2/apk"
-	_ "github.com/goreleaser/nfpm/v2/arch"
-	_ "github.com/goreleaser/nfpm/v2/deb"
-	_ "github.com/goreleaser/nfpm/v2/rpm"
+	_ "github.com/goreleaser/nfpm/v2/apk"  // apk packager
+	_ "github.com/goreleaser/nfpm/v2/arch" // archlinux packager
+	_ "github.com/goreleaser/nfpm/v2/deb"  // deb packager
+	_ "github.com/goreleaser/nfpm/v2/rpm"  // rpm packager
 	"github.com/spf13/cobra"
 )
 
diff --git a/internal/sign/pgp.go b/internal/sign/pgp.go
index 0f6d7ea..1c0af46 100644
--- a/internal/sign/pgp.go
+++ b/internal/sign/pgp.go
@@ -24,11 +24,11 @@ func PGPSigner(keyFile, passphrase string) func([]byte) ([]byte, error) {
 
 // PGPSignerWithKeyID returns a PGP signer that creates a detached non-ASCII-armored
 // signature and is compatible with rpmpack's signature API.
-func PGPSignerWithKeyID(keyFile, passphrase string, hexKeyId *string) func([]byte) ([]byte, error) {
+func PGPSignerWithKeyID(keyFile, passphrase string, hexKeyID *string) func([]byte) ([]byte, error) {
 	return func(data []byte) ([]byte, error) {
-		keyId, err := parseKeyID(hexKeyId)
+		keyID, err := parseKeyID(hexKeyID)
 		if err != nil {
-			return nil, fmt.Errorf("%v is not a valid key id: %w", hexKeyId, err)
+			return nil, fmt.Errorf("%v is not a valid key id: %w", hexKeyID, err)
 		}
 
 		key, err := readSigningKey(keyFile, passphrase)
@@ -39,7 +39,7 @@ func PGPSignerWithKeyID(keyFile, passphrase string, hexKeyId *string) func([]byt
 		var signature bytes.Buffer
 
 		err = openpgp.DetachSign(&signature, key, bytes.NewReader(data), &packet.Config{
-			SigningKeyId: keyId,
+			SigningKeyId: keyID,
 			DefaultHash:  crypto.SHA256,
 		})
 		if err != nil {
@@ -56,10 +56,10 @@ func PGPArmoredDetachSign(message io.Reader, keyFile, passphrase string) ([]byte
 }
 
 // PGPArmoredDetachSignWithKeyID creates an ASCII-armored detached signature.
-func PGPArmoredDetachSignWithKeyID(message io.Reader, keyFile, passphrase string, hexKeyId *string) ([]byte, error) {
-	keyId, err := parseKeyID(hexKeyId)
+func PGPArmoredDetachSignWithKeyID(message io.Reader, keyFile, passphrase string, hexKeyID *string) ([]byte, error) {
+	keyID, err := parseKeyID(hexKeyID)
 	if err != nil {
-		return nil, fmt.Errorf("%v is not a valid key id: %w", hexKeyId, err)
+		return nil, fmt.Errorf("%v is not a valid key id: %w", hexKeyID, err)
 	}
 
 	key, err := readSigningKey(keyFile, passphrase)
@@ -70,7 +70,7 @@ func PGPArmoredDetachSignWithKeyID(message io.Reader, keyFile, passphrase string
 	var signature bytes.Buffer
 
 	err = openpgp.ArmoredDetachSign(&signature, key, message, &packet.Config{
-		SigningKeyId: keyId,
+		SigningKeyId: keyID,
 		DefaultHash:  crypto.SHA256,
 	})
 	if err != nil {
@@ -80,10 +80,10 @@ func PGPArmoredDetachSignWithKeyID(message io.Reader, keyFile, passphrase string
 	return signature.Bytes(), nil
 }
 
-func PGPClearSignWithKeyID(message io.Reader, keyFile, passphrase string, hexKeyId *string) ([]byte, error) {
-	keyId, err := parseKeyID(hexKeyId)
+func PGPClearSignWithKeyID(message io.Reader, keyFile, passphrase string, hexKeyID *string) ([]byte, error) {
+	keyID, err := parseKeyID(hexKeyID)
 	if err != nil {
-		return nil, fmt.Errorf("%v is not a valid key id: %w", hexKeyId, err)
+		return nil, fmt.Errorf("%v is not a valid key id: %w", hexKeyID, err)
 	}
 
 	key, err := readSigningKey(keyFile, passphrase)
@@ -94,7 +94,7 @@ func PGPClearSignWithKeyID(message io.Reader, keyFile, passphrase string, hexKey
 	var signature bytes.Buffer
 
 	writeCloser, err := clearsign.Encode(&signature, key.PrivateKey, &packet.Config{
-		SigningKeyId: keyId,
+		SigningKeyId: keyID,
 		DefaultHash:  crypto.SHA256,
 	})
 	if err != nil {
@@ -171,12 +171,12 @@ func PGPReadMessage(message []byte, armoredPubKeyFile string) error {
 	return err
 }
 
-func parseKeyID(hexKeyId *string) (uint64, error) {
-	if hexKeyId == nil || *hexKeyId == "" {
+func parseKeyID(hexKeyID *string) (uint64, error) {
+	if hexKeyID == nil || *hexKeyID == "" {
 		return 0, nil
 	}
 
-	result, err := strconv.ParseUint(*hexKeyId, 16, 64)
+	result, err := strconv.ParseUint(*hexKeyID, 16, 64)
 	if err != nil {
 		return 0, err
 	}
diff --git a/rpm/rpm.go b/rpm/rpm.go
index 1d5cccc..91cf749 100644
--- a/rpm/rpm.go
+++ b/rpm/rpm.go
@@ -363,7 +363,7 @@ func createFilesInsideRPM(info *nfpm.Info, rpm *rpmpack.RPM) (err error) {
 		case files.TypeSymlink:
 			file = asRPMSymlink(content)
 		case files.TypeDir:
-			file, err = asRPMDirectory(content)
+			file = asRPMDirectory(content)
 		case files.TypeImplicitDir:
 			// we don't need to add imlicit directories to RPMs
 			continue
@@ -384,14 +384,14 @@ func createFilesInsideRPM(info *nfpm.Info, rpm *rpmpack.RPM) (err error) {
 	return nil
 }
 
-func asRPMDirectory(content *files.Content) (*rpmpack.RPMFile, error) {
+func asRPMDirectory(content *files.Content) *rpmpack.RPMFile {
 	return &rpmpack.RPMFile{
 		Name:  content.Destination,
 		Mode:  uint(content.Mode()) | tagDirectory,
 		MTime: uint32(time.Now().Unix()),
 		Owner: content.FileInfo.Owner,
 		Group: content.FileInfo.Group,
-	}, nil
+	}
 }
 
 func asRPMSymlink(content *files.Content) *rpmpack.RPMFile {


Test patch:
diff --git a/apk/apk_test.go b/apk/apk_test.go
index 3d60592..0b6cb6c 100644
--- a/apk/apk_test.go
+++ b/apk/apk_test.go
@@ -524,7 +524,7 @@ func TestDirectories(t *testing.T) {
 
 	var buf bytes.Buffer
 	size := int64(0)
-	err := createFilesInsideTarGz(info, tar.NewWriter(&buf), make(map[string]bool), &size)
+	err := createFilesInsideTarGz(info, tar.NewWriter(&buf), &size)
 	require.NoError(t, err)
 
 	require.Equal(t, []string{
@@ -576,7 +576,7 @@ func TestNoDuplicateAutocreatedDirectories(t *testing.T) {
 
 	var buf bytes.Buffer
 	size := int64(0)
-	err := createFilesInsideTarGz(info, tar.NewWriter(&buf), make(map[string]bool), &size)
+	err := createFilesInsideTarGz(info, tar.NewWriter(&buf), &size)
 	require.NoError(t, err)
 
 	contents := tarContents(t, buf.Bytes())
@@ -637,7 +637,7 @@ func TestNoDuplicateContents(t *testing.T) {
 
 	var buf bytes.Buffer
 	size := int64(0)
-	err := createFilesInsideTarGz(info, tar.NewWriter(&buf), make(map[string]bool), &size)
+	err := createFilesInsideTarGz(info, tar.NewWriter(&buf), &size)
 	require.NoError(t, err)
 
 	exists := map[string]bool{}
diff --git a/arch/arch_test.go b/arch/arch_test.go
index fd5667f..de71021 100644
--- a/arch/arch_test.go
+++ b/arch/arch_test.go
@@ -261,7 +261,7 @@ func TestArchMtree(t *testing.T) {
 	buf := &bytes.Buffer{}
 	tw := tar.NewWriter(buf)
 
-	err := createMtree(info, tw, []MtreeEntry{
+	err := createMtree(tw, []MtreeEntry{
 		{
 			Destination: "foo",
 			Time:        1234,
diff --git a/internal/sign/pgp_test.go b/internal/sign/pgp_test.go
index a8954c9..77d5701 100644
--- a/internal/sign/pgp_test.go
+++ b/internal/sign/pgp_test.go
@@ -20,7 +20,7 @@ var testCases = []struct {
 	privKeyFile string
 	pubKeyFile  string
 	pass        string
-	keyId       *string
+	keyID       *string
 }{
 	{"protected", "testdata/privkey.gpg", "testdata/pubkey", pass, nil},
 	{"unprotected", "testdata/privkey_unprotected.gpg", "testdata/pubkey", "", nil},
@@ -41,7 +41,7 @@ func TestPGPSignerAndVerify(t *testing.T) {
 		t.Run(testCase.name, func(t *testing.T) {
 			armoredPublicKey := fmt.Sprintf("%s.asc", testCase.pubKeyFile)
 			gpgPublicKey := fmt.Sprintf("%s.gpg", testCase.pubKeyFile)
-			sig, err := PGPSignerWithKeyID(testCase.privKeyFile, testCase.pass, testCase.keyId)(data)
+			sig, err := PGPSignerWithKeyID(testCase.privKeyFile, testCase.pass, testCase.keyID)(data)
 			require.NoError(t, err)
 
 			err = PGPVerify(bytes.NewReader(data), sig, armoredPublicKey)
@@ -49,7 +49,7 @@ func TestPGPSignerAndVerify(t *testing.T) {
 
 			err = PGPVerify(bytes.NewReader(data), sig, gpgPublicKey)
 			require.NoError(t, err)
-			if testCase.keyId != nil {
+			if testCase.keyID != nil {
 				var pgpSignature *crypto.PGPSignature
 				if isASCII(sig) {
 					pgpSignature, err = crypto.NewPGPSignatureFromArmored(string(sig))
@@ -59,7 +59,7 @@ func TestPGPSignerAndVerify(t *testing.T) {
 				}
 				sigID, _ := pgpSignature.GetSignatureKeyIDs()
 				require.Len(t, sigID, 1)
-				require.Equal(t, *testCase.keyId, fmt.Sprintf("%x", sigID[0]))
+				require.Equal(t, *testCase.keyID, fmt.Sprintf("%x", sigID[0]))
 			}
 		})
 	}
@@ -76,7 +76,7 @@ func TestArmoredDetachSignAndVerify(t *testing.T) {
 				bytes.NewReader(data),
 				testCase.privKeyFile,
 				testCase.pass,
-				testCase.keyId,
+				testCase.keyID,
 			)
 			require.NoError(t, err)
 
@@ -85,7 +85,7 @@ func TestArmoredDetachSignAndVerify(t *testing.T) {
 
 			err = PGPVerify(bytes.NewReader(data), sig, gpgPublicKey)
 			require.NoError(t, err)
-			if testCase.keyId != nil {
+			if testCase.keyID != nil {
 				var pgpSignature *crypto.PGPSignature
 				if isASCII(sig) {
 					pgpSignature, err = crypto.NewPGPSignatureFromArmored(string(sig))
@@ -95,7 +95,7 @@ func TestArmoredDetachSignAndVerify(t *testing.T) {
 				}
 				sigID, _ := pgpSignature.GetSignatureKeyIDs()
 				require.Len(t, sigID, 1)
-				require.Equal(t, *testCase.keyId, fmt.Sprintf("%x", sigID[0]))
+				require.Equal(t, *testCase.keyID, fmt.Sprintf("%x", sigID[0]))
 			}
 		})
 	}
diff --git a/nfpm_test.go b/nfpm_test.go
index c70d6a8..dcd1942 100644
--- a/nfpm_test.go
+++ b/nfpm_test.go
@@ -299,13 +299,13 @@ func TestParseEnhancedNestedNoGlob(t *testing.T) {
 
 		switch f.Source {
 		case "testdata/globtest/nested/b.txt":
-			tested += 1
+			tested++
 			require.Equal(t, "/etc/foo/nested/b.txt", f.Destination)
 		case "testdata/globtest/multi-nested/subdir/c.txt":
-			tested += 1
+			tested++
 			require.Equal(t, "/etc/foo/multi-nested/subdir/c.txt", f.Destination)
 		case "testdata/globtest/a.txt":
-			tested += 1
+			tested++
 			require.Equal(t, "/etc/foo/a.txt", f.Destination)
 		default:
 			t.Errorf("unknown source %q", f.Source)