1
0
mirror of https://github.com/goreleaser/goreleaser.git synced 2025-02-05 13:15:26 +02:00

refactor: remove empty lines, fix //nolint (#5235)

The PR formats code by removing redundant empty lines and fixes
`//nolint` directives. Additionally, this PR adds two more rules to the
`revive` configuration: `empty-lines` and `comment-spacings`.

Removing unnecessary empty lines helps to keep the codebase clean and
concise. This issue is identified by the `revive.empty-lines` rule.

In the `//nolint` directive, there must be no spaces between `:` and the
linter name: `//nolint:gosec`. See ["Nolint
Directive"](https://golangci-lint.run/usage/false-positives/#nolint-directive).
This issue is identified by the `revive.comment-spacings` rule.

Note that it's not possible to add just a few additional rules to the
`revive.enable` list. We need to specify all: default rules plus
additional rules. See the detailed explanation
[here](https://github.com/prometheus/prometheus/pull/13068).
This commit is contained in:
Oleksandr Redko 2024-10-31 18:51:54 +02:00 committed by GitHub
parent b269cc9229
commit 12155a336b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
17 changed files with 36 additions and 17 deletions

View File

@ -42,6 +42,34 @@ linters-settings:
deny:
- pkg: "github.com/pkg/errors"
desc: "use stdlib instead"
revive:
enable-all-rules: false
rules:
- name: blank-imports
- name: context-as-argument
- name: context-keys-type
- name: comment-spacings
- name: dot-imports
- name: empty-block
- name: empty-lines
- name: error-naming
- name: error-return
- name: error-strings
- name: errorf
- name: exported
- name: increment-decrement
- name: indent-error-flow
- name: package-comments
- name: range
- name: receiver-naming
- name: redefines-builtin-id
- name: superfluous-else
- name: time-naming
- name: unexported-return
- name: unreachable-code
- name: unused-parameter
- name: var-declaration
- name: var-naming
testifylint:
enable-all: true
disable:

View File

@ -149,7 +149,6 @@ func (c *giteaClient) CreateFile(
WithError(err).
Warn("error checking for default branch, using master")
}
}
fileOptions := gitea.FileOptions{

View File

@ -269,7 +269,6 @@ func TestRunPipe(t *testing.T) {
header := tarInfo(t, filepath.Join(dist, name), expectBin)
require.Equal(t, "root", header.Uname)
require.Equal(t, "root", header.Gname)
}
}
if format == "zip" {

View File

@ -178,7 +178,7 @@ func doRun(ctx *context.Context, aur config.AUR, cl client.ReleaseURLTemplater)
return fmt.Errorf("failed to write %s: %w", info.kind, err)
}
log.WithField("file", path).Info("writing")
if err := os.WriteFile(path, []byte(pkgContent), 0o644); err != nil { //nolint: gosec
if err := os.WriteFile(path, []byte(pkgContent), 0o644); err != nil { //nolint:gosec
return fmt.Errorf("failed to write %s: %w", info.kind, err)
}

View File

@ -269,7 +269,7 @@ func doRun(ctx *context.Context, brew config.Homebrew, cl client.ReleaseURLTempl
}
log.WithField("formula", path).Info("writing")
if err := os.WriteFile(path, []byte(content), 0o644); err != nil { //nolint: gosec
if err := os.WriteFile(path, []byte(content), 0o644); err != nil { //nolint:gosec
return fmt.Errorf("failed to write brew formula: %w", err)
}

View File

@ -108,7 +108,7 @@ func (Pipe) Run(ctx *context.Context) error {
path := filepath.Join(ctx.Config.Dist, "CHANGELOG.md")
log.WithField("path", path).Debug("writing changelog")
return os.WriteFile(path, []byte(ctx.ReleaseNotes), 0o644) //nolint: gosec
return os.WriteFile(path, []byte(ctx.ReleaseNotes), 0o644) //nolint:gosec
}
type changelogGroup struct {

View File

@ -22,5 +22,5 @@ func (Pipe) Run(ctx *context.Context) (err error) {
return err
}
log.WithField("path", path).Debug("writing effective configuration")
return os.WriteFile(path, bts, 0o644) //nolint: gosec
return os.WriteFile(path, bts, 0o644) //nolint:gosec
}

View File

@ -135,7 +135,7 @@ func doRun(ctx *context.Context, krew config.Krew, cl client.ReleaseURLTemplater
return err
}
log.WithField("manifest", yamlPath).Info("writing")
if err := os.WriteFile(yamlPath, []byte("# This file was generated by GoReleaser. DO NOT EDIT.\n"+content), 0o644); err != nil { //nolint: gosec
if err := os.WriteFile(yamlPath, []byte("# This file was generated by GoReleaser. DO NOT EDIT.\n"+content), 0o644); err != nil { //nolint:gosec
return fmt.Errorf("failed to write krew manifest: %w", err)
}

View File

@ -105,7 +105,6 @@ func TestRunPipe(t *testing.T) {
f, err := os.Create(name)
require.NoError(t, err)
require.NoError(t, f.Close())
}
libPrefix := `/usr/lib
{{- if eq .Arch "amd64" }}{{if eq .Format "rpm"}}_rpm{{end}}64{{- end -}}

View File

@ -174,7 +174,7 @@ func (p Pipe) doRun(ctx *context.Context, nix config.Nix, cl client.ReleaseURLTe
}
log.WithField("nixpkg", path).Info("writing")
if err := os.WriteFile(path, []byte(content), 0o644); err != nil { //nolint: gosec
if err := os.WriteFile(path, []byte(content), 0o644); err != nil { //nolint:gosec
return fmt.Errorf("failed to write nixpkg: %w", err)
}

View File

@ -550,7 +550,6 @@ func TestRunPipe(t *testing.T) {
err := bpipe.Default(ctx)
require.ErrorAs(t, err, &tt.expectDefaultErrorIs)
return
}
require.NoError(t, bpipe.Default(ctx))

View File

@ -139,7 +139,6 @@ func signAndNotarize(ctx *context.Context, cfg config.MacOSSignNotarize) error {
default:
log.WithField("binary", bin.Path).Info("notarize still pending")
}
}
if err := binaries.Refresh(); err != nil {

View File

@ -239,7 +239,6 @@ func catalogArtifact(ctx *context.Context, cfg config.SBOM, a *artifact.Artifact
},
})
}
}
if len(artifacts) == 0 {

View File

@ -408,7 +408,7 @@ func create(ctx *context.Context, snap config.Snapcraft, arch string, binaries [
}
log.WithField("file", file).Debugf("writing metadata file")
if err = os.WriteFile(file, out, 0o644); err != nil { //nolint: gosec
if err = os.WriteFile(file, out, 0o644); err != nil { //nolint:gosec
return err
}

View File

@ -112,7 +112,6 @@ func TestRun(t *testing.T) {
},
})
}
}
}
@ -229,7 +228,6 @@ func TestFindBinaries(t *testing.T) {
},
})
}
}
}

View File

@ -31,7 +31,7 @@ func createYAML(ctx *context.Context, winget config.Winget, in any, tp artifact.
generatedHeader,
langserverLineFor(tp),
string(versionContent),
}, "\n")), 0o644); err != nil { //nolint: gosec
}, "\n")), 0o644); err != nil { //nolint:gosec
return fmt.Errorf("failed to write winget version: %w", err)
}

View File

@ -43,7 +43,6 @@ func Copy(source *os.File, target io.Writer) (Archive, error) {
}
w := New(target)
for _, zf := range r.File {
w.files[zf.Name] = true
hdr := zip.FileHeader{
Name: zf.Name,