Fix: Implement golangci-lint suggestions

This commit is contained in:
Mauro Regli
2023-09-13 11:44:58 +02:00
committed by Mauro
parent f4a152ab22
commit ae61706a34
27 changed files with 51 additions and 62 deletions
+2 -2
View File
@@ -83,7 +83,7 @@ func (storage *PublishedStorage) String() string {
} }
// MkDir creates directory recursively under public path // MkDir creates directory recursively under public path
func (storage *PublishedStorage) MkDir(path string) error { func (storage *PublishedStorage) MkDir(_ string) error {
// no op for Azure // no op for Azure
return nil return nil
} }
@@ -145,7 +145,7 @@ func (storage *PublishedStorage) putFile(path string, source io.Reader, sourceMD
} }
// RemoveDirs removes directory structure under public path // RemoveDirs removes directory structure under public path
func (storage *PublishedStorage) RemoveDirs(path string, progress aptly.Progress) error { func (storage *PublishedStorage) RemoveDirs(path string, _ aptly.Progress) error {
filelist, err := storage.Filelist(path) filelist, err := storage.Filelist(path)
if err != nil { if err != nil {
return err return err
+1 -1
View File
@@ -7,7 +7,7 @@ import (
"github.com/smira/commander" "github.com/smira/commander"
) )
func aptlyConfigShow(cmd *commander.Command, args []string) error { func aptlyConfigShow(_ *commander.Command, _ []string) error {
config := context.Config() config := context.Config()
prettyJSON, err := json.MarshalIndent(config, "", " ") prettyJSON, err := json.MarshalIndent(config, "", " ")
+2 -2
View File
@@ -24,7 +24,7 @@ func aptlyMirrorList(cmd *commander.Command, args []string) error {
return aptlyMirrorListTxt(cmd, args) return aptlyMirrorListTxt(cmd, args)
} }
func aptlyMirrorListTxt(cmd *commander.Command, args []string) error { func aptlyMirrorListTxt(cmd *commander.Command, _ []string) error {
var err error var err error
raw := cmd.Flag.Lookup("raw").Value.Get().(bool) raw := cmd.Flag.Lookup("raw").Value.Get().(bool)
@@ -65,7 +65,7 @@ func aptlyMirrorListTxt(cmd *commander.Command, args []string) error {
return err return err
} }
func aptlyMirrorListJSON(cmd *commander.Command, args []string) error { func aptlyMirrorListJSON(_ *commander.Command, _ []string) error {
var err error var err error
repos := make([]*deb.RemoteRepo, context.NewCollectionFactory().RemoteRepoCollection().Len()) repos := make([]*deb.RemoteRepo, context.NewCollectionFactory().RemoteRepoCollection().Len())
+2 -2
View File
@@ -27,7 +27,7 @@ func aptlyMirrorShow(cmd *commander.Command, args []string) error {
return aptlyMirrorShowTxt(cmd, args) return aptlyMirrorShowTxt(cmd, args)
} }
func aptlyMirrorShowTxt(cmd *commander.Command, args []string) error { func aptlyMirrorShowTxt(_ *commander.Command, args []string) error {
var err error var err error
name := args[0] name := args[0]
@@ -93,7 +93,7 @@ func aptlyMirrorShowTxt(cmd *commander.Command, args []string) error {
return err return err
} }
func aptlyMirrorShowJSON(cmd *commander.Command, args []string) error { func aptlyMirrorShowJSON(_ *commander.Command, args []string) error {
var err error var err error
name := args[0] name := args[0]
+2 -2
View File
@@ -25,7 +25,7 @@ func aptlyPublishList(cmd *commander.Command, args []string) error {
return aptlyPublishListTxt(cmd, args) return aptlyPublishListTxt(cmd, args)
} }
func aptlyPublishListTxt(cmd *commander.Command, args []string) error { func aptlyPublishListTxt(cmd *commander.Command, _ []string) error {
var err error var err error
raw := cmd.Flag.Lookup("raw").Value.Get().(bool) raw := cmd.Flag.Lookup("raw").Value.Get().(bool)
@@ -77,7 +77,7 @@ func aptlyPublishListTxt(cmd *commander.Command, args []string) error {
return err return err
} }
func aptlyPublishListJSON(cmd *commander.Command, args []string) error { func aptlyPublishListJSON(_ *commander.Command, _ []string) error {
var err error var err error
repos := make([]*deb.PublishedRepo, 0, context.NewCollectionFactory().PublishedRepoCollection().Len()) repos := make([]*deb.PublishedRepo, 0, context.NewCollectionFactory().PublishedRepoCollection().Len())
+2 -2
View File
@@ -24,7 +24,7 @@ func aptlyPublishShow(cmd *commander.Command, args []string) error {
return aptlyPublishShowTxt(cmd, args) return aptlyPublishShowTxt(cmd, args)
} }
func aptlyPublishShowTxt(cmd *commander.Command, args []string) error { func aptlyPublishShowTxt(_ *commander.Command, args []string) error {
var err error var err error
distribution := args[0] distribution := args[0]
@@ -76,7 +76,7 @@ func aptlyPublishShowTxt(cmd *commander.Command, args []string) error {
return err return err
} }
func aptlyPublishShowJSON(cmd *commander.Command, args []string) error { func aptlyPublishShowJSON(_ *commander.Command, args []string) error {
var err error var err error
distribution := args[0] distribution := args[0]
+2 -2
View File
@@ -24,7 +24,7 @@ func aptlyRepoList(cmd *commander.Command, args []string) error {
return aptlyRepoListTxt(cmd, args) return aptlyRepoListTxt(cmd, args)
} }
func aptlyRepoListTxt(cmd *commander.Command, args []string) error { func aptlyRepoListTxt(cmd *commander.Command, _ []string) error {
var err error var err error
raw := cmd.Flag.Lookup("raw").Value.Get().(bool) raw := cmd.Flag.Lookup("raw").Value.Get().(bool)
@@ -71,7 +71,7 @@ func aptlyRepoListTxt(cmd *commander.Command, args []string) error {
return err return err
} }
func aptlyRepoListJSON(cmd *commander.Command, args []string) error { func aptlyRepoListJSON(_ *commander.Command, _ []string) error {
var err error var err error
repos := make([]*deb.LocalRepo, context.NewCollectionFactory().LocalRepoCollection().Len()) repos := make([]*deb.LocalRepo, context.NewCollectionFactory().LocalRepoCollection().Len())
+2 -2
View File
@@ -25,7 +25,7 @@ func aptlyRepoShow(cmd *commander.Command, args []string) error {
return aptlyRepoShowTxt(cmd, args) return aptlyRepoShowTxt(cmd, args)
} }
func aptlyRepoShowTxt(cmd *commander.Command, args []string) error { func aptlyRepoShowTxt(_ *commander.Command, args []string) error {
var err error var err error
name := args[0] name := args[0]
@@ -58,7 +58,7 @@ func aptlyRepoShowTxt(cmd *commander.Command, args []string) error {
return err return err
} }
func aptlyRepoShowJSON(cmd *commander.Command, args []string) error { func aptlyRepoShowJSON(_ *commander.Command, args []string) error {
var err error var err error
name := args[0] name := args[0]
+2 -2
View File
@@ -23,7 +23,7 @@ func aptlySnapshotList(cmd *commander.Command, args []string) error {
return aptlySnapshotListTxt(cmd, args) return aptlySnapshotListTxt(cmd, args)
} }
func aptlySnapshotListTxt(cmd *commander.Command, args []string) error { func aptlySnapshotListTxt(cmd *commander.Command, _ []string) error {
var err error var err error
raw := cmd.Flag.Lookup("raw").Value.Get().(bool) raw := cmd.Flag.Lookup("raw").Value.Get().(bool)
@@ -59,7 +59,7 @@ func aptlySnapshotListTxt(cmd *commander.Command, args []string) error {
return err return err
} }
func aptlySnapshotListJSON(cmd *commander.Command, args []string) error { func aptlySnapshotListJSON(cmd *commander.Command, _ []string) error {
var err error var err error
sortMethodString := cmd.Flag.Lookup("sort").Value.Get().(string) sortMethodString := cmd.Flag.Lookup("sort").Value.Get().(string)
+2 -2
View File
@@ -25,7 +25,7 @@ func aptlySnapshotShow(cmd *commander.Command, args []string) error {
return aptlySnapshotShowTxt(cmd, args) return aptlySnapshotShowTxt(cmd, args)
} }
func aptlySnapshotShowTxt(cmd *commander.Command, args []string) error { func aptlySnapshotShowTxt(_ *commander.Command, args []string) error {
var err error var err error
name := args[0] name := args[0]
collectionFactory := context.NewCollectionFactory() collectionFactory := context.NewCollectionFactory()
@@ -85,7 +85,7 @@ func aptlySnapshotShowTxt(cmd *commander.Command, args []string) error {
return err return err
} }
func aptlySnapshotShowJSON(cmd *commander.Command, args []string) error { func aptlySnapshotShowJSON(_ *commander.Command, args []string) error {
var err error var err error
name := args[0] name := args[0]
+3 -4
View File
@@ -62,11 +62,10 @@ func aptlyTaskRun(cmd *commander.Command, args []string) error {
text, _ = reader.ReadString('\n') text, _ = reader.ReadString('\n')
if text == "\n" { if text == "\n" {
break break
} else {
text = strings.TrimSpace(text) + ","
parsedArgs, _ := shellwords.Parse(text)
cmdArgs = append(cmdArgs, parsedArgs...)
} }
text = strings.TrimSpace(text) + ","
parsedArgs, _ := shellwords.Parse(text)
cmdArgs = append(cmdArgs, parsedArgs...)
} }
if len(cmdArgs) == 0 { if len(cmdArgs) == 0 {
+1 -1
View File
@@ -74,7 +74,7 @@ func (p *Progress) Flush() {
} }
// InitBar starts progressbar for count bytes or count items // InitBar starts progressbar for count bytes or count items
func (p *Progress) InitBar(count int64, isBytes bool, barType aptly.BarType) { func (p *Progress) InitBar(count int64, isBytes bool, _ aptly.BarType) {
if p.bar != nil { if p.bar != nil {
panic("bar already initialized") panic("bar already initialized")
} }
+3 -3
View File
@@ -457,7 +457,7 @@ func (context *AptlyContext) pgpProvider() string {
return provider return provider
} }
func (context *AptlyContext) getGPGFinder(provider string) pgp.GPGFinder { func (context *AptlyContext) getGPGFinder() pgp.GPGFinder {
switch context.pgpProvider() { switch context.pgpProvider() {
case "gpg1": case "gpg1":
return pgp.GPG1Finder() return pgp.GPG1Finder()
@@ -480,7 +480,7 @@ func (context *AptlyContext) GetSigner() pgp.Signer {
return &pgp.GoSigner{} return &pgp.GoSigner{}
} }
return pgp.NewGpgSigner(context.getGPGFinder(provider)) return pgp.NewGpgSigner(context.getGPGFinder())
} }
// GetVerifier returns Verifier with respect to provider // GetVerifier returns Verifier with respect to provider
@@ -493,7 +493,7 @@ func (context *AptlyContext) GetVerifier() pgp.Verifier {
return &pgp.GoVerifier{} return &pgp.GoVerifier{}
} }
return pgp.NewGpgVerifier(context.getGPGFinder(provider)) return pgp.NewGpgVerifier(context.getGPGFinder())
} }
// UpdateFlags sets internal copy of flags in the context // UpdateFlags sets internal copy of flags in the context
+2 -2
View File
@@ -220,12 +220,12 @@ func (c *Changes) GetField(field string) string {
} }
// MatchesDependency implements PackageLike interface // MatchesDependency implements PackageLike interface
func (c *Changes) MatchesDependency(d Dependency) bool { func (c *Changes) MatchesDependency(_ Dependency) bool {
return false return false
} }
// MatchesArchitecture implements PackageLike interface // MatchesArchitecture implements PackageLike interface
func (c *Changes) MatchesArchitecture(arch string) bool { func (c *Changes) MatchesArchitecture(_ string) bool {
return false return false
} }
+1 -1
View File
@@ -317,7 +317,7 @@ func (collection *PackageCollection) Scan(q PackageQuery) (result *PackageList)
} }
// Search is not implemented // Search is not implemented
func (collection *PackageCollection) Search(dep Dependency, allMatches bool) (searchResults []*Package) { func (collection *PackageCollection) Search(_ Dependency, _ bool) (searchResults []*Package) {
panic("Not implemented") panic("Not implemented")
} }
+5 -5
View File
@@ -138,7 +138,7 @@ func (q *NotQuery) Matches(pkg PackageLike) bool {
} }
// Fast is false // Fast is false
func (q *NotQuery) Fast(list PackageCatalog) bool { func (q *NotQuery) Fast(_ PackageCatalog) bool {
return false return false
} }
@@ -197,7 +197,7 @@ func (q *FieldQuery) Query(list PackageCatalog) (result *PackageList) {
} }
// Fast depends on the query // Fast depends on the query
func (q *FieldQuery) Fast(list PackageCatalog) bool { func (q *FieldQuery) Fast(_ PackageCatalog) bool {
return false return false
} }
@@ -265,7 +265,7 @@ func (q *PkgQuery) Matches(pkg PackageLike) bool {
} }
// Fast is always true for package query // Fast is always true for package query
func (q *PkgQuery) Fast(list PackageCatalog) bool { func (q *PkgQuery) Fast(_ PackageCatalog) bool {
return true return true
} }
@@ -280,12 +280,12 @@ func (q *PkgQuery) String() string {
} }
// Matches on specific properties // Matches on specific properties
func (q *MatchAllQuery) Matches(pkg PackageLike) bool { func (q *MatchAllQuery) Matches(_ PackageLike) bool {
return true return true
} }
// Fast is always true for match all query // Fast is always true for match all query
func (q *MatchAllQuery) Fast(list PackageCatalog) bool { func (q *MatchAllQuery) Fast(_ PackageCatalog) bool {
return true return true
} }
+1 -1
View File
@@ -428,7 +428,7 @@ ok:
} }
// DownloadPackageIndexes downloads & parses package index files // DownloadPackageIndexes downloads & parses package index files
func (repo *RemoteRepo) DownloadPackageIndexes(progress aptly.Progress, d aptly.Downloader, verifier pgp.Verifier, collectionFactory *CollectionFactory, func (repo *RemoteRepo) DownloadPackageIndexes(progress aptly.Progress, d aptly.Downloader, verifier pgp.Verifier, _ *CollectionFactory,
ignoreMismatch bool) error { ignoreMismatch bool) error {
if repo.packageList != nil { if repo.packageList != nil {
panic("packageList != nil") panic("packageList != nil")
+1 -1
View File
@@ -68,7 +68,7 @@ func NewDownloader(downLimit int64, maxTries int, progress aptly.Progress) aptly
return downloader return downloader
} }
func (downloader *downloaderImpl) checkRedirect(req *http.Request, via []*http.Request) error { func (downloader *downloaderImpl) checkRedirect(req *http.Request, _ []*http.Request) error {
if downloader.progress != nil { if downloader.progress != nil {
downloader.progress.Printf("Following redirect to %s...\n", req.URL) downloader.progress.Printf("Following redirect to %s...\n", req.URL)
} }
+2 -2
View File
@@ -61,7 +61,7 @@ func (f *FakeDownloader) Empty() bool {
} }
// GetLength returns content length of given url // GetLength returns content length of given url
func (f *FakeDownloader) GetLength(ctx context.Context, url string) (int64, error) { func (f *FakeDownloader) GetLength(_ context.Context, url string) (int64, error) {
expectation, err := f.getExpectedRequest(url) expectation, err := f.getExpectedRequest(url)
if err != nil { if err != nil {
return -1, err return -1, err
@@ -89,7 +89,7 @@ func (f *FakeDownloader) getExpectedRequest(url string) (*expectedRequest, error
} }
// DownloadWithChecksum performs fake download by matching against first expectation in the queue or any expectation, with cheksum verification // DownloadWithChecksum performs fake download by matching against first expectation in the queue or any expectation, with cheksum verification
func (f *FakeDownloader) DownloadWithChecksum(ctx context.Context, url string, filename string, expected *utils.ChecksumInfo, ignoreMismatch bool) error { func (f *FakeDownloader) DownloadWithChecksum(_ context.Context, url string, filename string, expected *utils.ChecksumInfo, ignoreMismatch bool) error {
expectation, err := f.getExpectedRequest(url) expectation, err := f.getExpectedRequest(url)
if err != nil { if err != nil {
return err return err
+2 -2
View File
@@ -114,7 +114,7 @@ func (d *GrabDownloader) maybeSetupChecksum(req *grab.Request, expected *utils.C
return nil return nil
} }
func (d *GrabDownloader) download(ctx context.Context, url string, destination string, expected *utils.ChecksumInfo, ignoreMismatch bool) error { func (d *GrabDownloader) download(_ context.Context, url string, destination string, expected *utils.ChecksumInfo, ignoreMismatch bool) error {
// TODO clean up dest dir on permanent failure // TODO clean up dest dir on permanent failure
d.log("Download %s -> %s\n", url, destination) d.log("Download %s -> %s\n", url, destination)
@@ -155,7 +155,7 @@ func (d *GrabDownloader) GetProgress() aptly.Progress {
return d.progress return d.progress
} }
func (d *GrabDownloader) GetLength(ctx context.Context, url string) (int64, error) { func (d *GrabDownloader) GetLength(_ context.Context, url string) (int64, error) {
resp, err := http.Head(url) resp, err := http.Head(url)
if err != nil { if err != nil {
return -1, err return -1, err
-4
View File
@@ -1,9 +1,7 @@
package main package main
import ( import (
"math/rand"
"os" "os"
"time"
"github.com/aptly-dev/aptly/aptly" "github.com/aptly-dev/aptly/aptly"
"github.com/aptly-dev/aptly/cmd" "github.com/aptly-dev/aptly/cmd"
@@ -22,7 +20,5 @@ func main() {
aptly.Version = Version aptly.Version = Version
rand.Seed(time.Now().UnixNano())
os.Exit(cmd.Run(cmd.RootCommand(), os.Args[1:], true)) os.Exit(cmd.Run(cmd.RootCommand(), os.Args[1:], true))
} }
-3
View File
@@ -6,7 +6,6 @@ package main
import ( import (
"flag" "flag"
"fmt" "fmt"
"math/rand"
"os" "os"
"strings" "strings"
"testing" "testing"
@@ -53,8 +52,6 @@ func TestRunMain(t *testing.T) {
aptly.Version = Version aptly.Version = Version
rand.Seed(time.Now().UnixNano())
args := filterOutTestArgs(os.Args[1:]) args := filterOutTestArgs(os.Args[1:])
root := cmd.RootCommand() root := cmd.RootCommand()
root.UsageLine = "aptly" root.UsageLine = "aptly"
+2 -2
View File
@@ -131,7 +131,7 @@ func (storage *PublishedStorage) String() string {
} }
// MkDir creates directory recursively under public path // MkDir creates directory recursively under public path
func (storage *PublishedStorage) MkDir(path string) error { func (storage *PublishedStorage) MkDir(_ string) error {
// no op for S3 // no op for S3
return nil return nil
} }
@@ -232,7 +232,7 @@ func (storage *PublishedStorage) Remove(path string) error {
} }
// RemoveDirs removes directory structure under public path // RemoveDirs removes directory structure under public path
func (storage *PublishedStorage) RemoveDirs(path string, progress aptly.Progress) error { func (storage *PublishedStorage) RemoveDirs(path string, _ aptly.Progress) error {
const page = 1000 const page = 1000
filelist, _, err := storage.internalFilelist(path, false) filelist, _, err := storage.internalFilelist(path, false)
+2 -2
View File
@@ -113,7 +113,7 @@ func (storage *PublishedStorage) String() string {
} }
// MkDir creates directory recursively under public path // MkDir creates directory recursively under public path
func (storage *PublishedStorage) MkDir(path string) error { func (storage *PublishedStorage) MkDir(_ string) error {
// no op for Swift // no op for Swift
return nil return nil
} }
@@ -155,7 +155,7 @@ func (storage *PublishedStorage) Remove(path string) error {
} }
// RemoveDirs removes directory structure under public path // RemoveDirs removes directory structure under public path
func (storage *PublishedStorage) RemoveDirs(path string, progress aptly.Progress) error { func (storage *PublishedStorage) RemoveDirs(path string, _ aptly.Progress) error {
path = filepath.Join(storage.prefix, path) path = filepath.Join(storage.prefix, path)
opts := swift.ObjectsOpts{ opts := swift.ObjectsOpts{
Prefix: path, Prefix: path,
-3
View File
@@ -6,7 +6,6 @@ import (
"math/rand" "math/rand"
"os" "os"
"path/filepath" "path/filepath"
"time"
. "gopkg.in/check.v1" . "gopkg.in/check.v1"
@@ -27,8 +26,6 @@ var _ = Suite(&PublishedStorageSuite{})
func (s *PublishedStorageSuite) SetUpTest(c *C) { func (s *PublishedStorageSuite) SetUpTest(c *C) {
var err error var err error
rand.Seed(int64(time.Now().Nanosecond()))
s.TestAddress = fmt.Sprintf("localhost:%d", rand.Intn(10000)+20000) s.TestAddress = fmt.Sprintf("localhost:%d", rand.Intn(10000)+20000)
s.AuthURL = "http://" + s.TestAddress + "/v1.0" s.AuthURL = "http://" + s.TestAddress + "/v1.0"
+6 -6
View File
@@ -63,12 +63,12 @@ func (t *Output) Flush() {
} }
// InitBar is needed for progress compatibility // InitBar is needed for progress compatibility
func (t *Output) InitBar(count int64, isBytes bool, barType aptly.BarType) { func (t *Output) InitBar(_ int64, _ bool, _ aptly.BarType) {
// Not implemented // Not implemented
} }
// InitBar publish output specific // InitBar publish output specific
func (t *PublishOutput) InitBar(count int64, isBytes bool, barType aptly.BarType) { func (t *PublishOutput) InitBar(count int64, _ bool, barType aptly.BarType) {
t.barType = &barType t.barType = &barType
if barType == aptly.BarPublishGeneratePackageFiles { if barType == aptly.BarPublishGeneratePackageFiles {
t.TotalNumberOfPackages = count t.TotalNumberOfPackages = count
@@ -88,12 +88,12 @@ func (t *PublishOutput) ShutdownBar() {
} }
// AddBar is needed for progress compatibility // AddBar is needed for progress compatibility
func (t *Output) AddBar(count int) { func (t *Output) AddBar(_ int) {
// Not implemented // Not implemented
} }
// AddBar publish output specific // AddBar publish output specific
func (t *PublishOutput) AddBar(count int) { func (t *PublishOutput) AddBar(_ int) {
if t.barType != nil && *t.barType == aptly.BarPublishGeneratePackageFiles { if t.barType != nil && *t.barType == aptly.BarPublishGeneratePackageFiles {
t.RemainingNumberOfPackages-- t.RemainingNumberOfPackages--
t.Store(t) t.Store(t)
@@ -101,7 +101,7 @@ func (t *PublishOutput) AddBar(count int) {
} }
// SetBar sets current position for progress bar // SetBar sets current position for progress bar
func (t *Output) SetBar(count int) { func (t *Output) SetBar(_ int) {
// Not implemented // Not implemented
} }
@@ -123,5 +123,5 @@ func (t *Output) ColoredPrintf(msg string, a ...interface{}) {
// PrintfStdErr does printf but in safe manner to output // PrintfStdErr does printf but in safe manner to output
func (t *Output) PrintfStdErr(msg string, a ...interface{}) { func (t *Output) PrintfStdErr(msg string, a ...interface{}) {
t.WriteString(msg) t.WriteString(fmt.Sprintf(msg, a...))
} }
+1 -1
View File
@@ -58,7 +58,7 @@ func GetLogLevelOrDebug(levelStr string) zerolog.Level {
type timestampHook struct{} type timestampHook struct{}
func (h *timestampHook) Run(e *zerolog.Event, l zerolog.Level, msg string) { func (h *timestampHook) Run(e *zerolog.Event, _ zerolog.Level, _ string) {
t := time.Now() t := time.Now()
ts := t.Format(time.RFC3339) ts := t.Format(time.RFC3339)
e.Str("time", ts) e.Str("time", ts)