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
func (storage *PublishedStorage) MkDir(path string) error {
func (storage *PublishedStorage) MkDir(_ string) error {
// no op for Azure
return nil
}
@@ -145,7 +145,7 @@ func (storage *PublishedStorage) putFile(path string, source io.Reader, sourceMD
}
// 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)
if err != nil {
return err
+1 -1
View File
@@ -7,7 +7,7 @@ import (
"github.com/smira/commander"
)
func aptlyConfigShow(cmd *commander.Command, args []string) error {
func aptlyConfigShow(_ *commander.Command, _ []string) error {
config := context.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)
}
func aptlyMirrorListTxt(cmd *commander.Command, args []string) error {
func aptlyMirrorListTxt(cmd *commander.Command, _ []string) error {
var err error
raw := cmd.Flag.Lookup("raw").Value.Get().(bool)
@@ -65,7 +65,7 @@ func aptlyMirrorListTxt(cmd *commander.Command, args []string) error {
return err
}
func aptlyMirrorListJSON(cmd *commander.Command, args []string) error {
func aptlyMirrorListJSON(_ *commander.Command, _ []string) error {
var err error
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)
}
func aptlyMirrorShowTxt(cmd *commander.Command, args []string) error {
func aptlyMirrorShowTxt(_ *commander.Command, args []string) error {
var err error
name := args[0]
@@ -93,7 +93,7 @@ func aptlyMirrorShowTxt(cmd *commander.Command, args []string) error {
return err
}
func aptlyMirrorShowJSON(cmd *commander.Command, args []string) error {
func aptlyMirrorShowJSON(_ *commander.Command, args []string) error {
var err error
name := args[0]
+2 -2
View File
@@ -25,7 +25,7 @@ func aptlyPublishList(cmd *commander.Command, args []string) error {
return aptlyPublishListTxt(cmd, args)
}
func aptlyPublishListTxt(cmd *commander.Command, args []string) error {
func aptlyPublishListTxt(cmd *commander.Command, _ []string) error {
var err error
raw := cmd.Flag.Lookup("raw").Value.Get().(bool)
@@ -77,7 +77,7 @@ func aptlyPublishListTxt(cmd *commander.Command, args []string) error {
return err
}
func aptlyPublishListJSON(cmd *commander.Command, args []string) error {
func aptlyPublishListJSON(_ *commander.Command, _ []string) error {
var err error
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)
}
func aptlyPublishShowTxt(cmd *commander.Command, args []string) error {
func aptlyPublishShowTxt(_ *commander.Command, args []string) error {
var err error
distribution := args[0]
@@ -76,7 +76,7 @@ func aptlyPublishShowTxt(cmd *commander.Command, args []string) error {
return err
}
func aptlyPublishShowJSON(cmd *commander.Command, args []string) error {
func aptlyPublishShowJSON(_ *commander.Command, args []string) error {
var err error
distribution := args[0]
+2 -2
View File
@@ -24,7 +24,7 @@ func aptlyRepoList(cmd *commander.Command, args []string) error {
return aptlyRepoListTxt(cmd, args)
}
func aptlyRepoListTxt(cmd *commander.Command, args []string) error {
func aptlyRepoListTxt(cmd *commander.Command, _ []string) error {
var err error
raw := cmd.Flag.Lookup("raw").Value.Get().(bool)
@@ -71,7 +71,7 @@ func aptlyRepoListTxt(cmd *commander.Command, args []string) error {
return err
}
func aptlyRepoListJSON(cmd *commander.Command, args []string) error {
func aptlyRepoListJSON(_ *commander.Command, _ []string) error {
var err error
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)
}
func aptlyRepoShowTxt(cmd *commander.Command, args []string) error {
func aptlyRepoShowTxt(_ *commander.Command, args []string) error {
var err error
name := args[0]
@@ -58,7 +58,7 @@ func aptlyRepoShowTxt(cmd *commander.Command, args []string) error {
return err
}
func aptlyRepoShowJSON(cmd *commander.Command, args []string) error {
func aptlyRepoShowJSON(_ *commander.Command, args []string) error {
var err error
name := args[0]
+2 -2
View File
@@ -23,7 +23,7 @@ func aptlySnapshotList(cmd *commander.Command, args []string) error {
return aptlySnapshotListTxt(cmd, args)
}
func aptlySnapshotListTxt(cmd *commander.Command, args []string) error {
func aptlySnapshotListTxt(cmd *commander.Command, _ []string) error {
var err error
raw := cmd.Flag.Lookup("raw").Value.Get().(bool)
@@ -59,7 +59,7 @@ func aptlySnapshotListTxt(cmd *commander.Command, args []string) error {
return err
}
func aptlySnapshotListJSON(cmd *commander.Command, args []string) error {
func aptlySnapshotListJSON(cmd *commander.Command, _ []string) error {
var err error
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)
}
func aptlySnapshotShowTxt(cmd *commander.Command, args []string) error {
func aptlySnapshotShowTxt(_ *commander.Command, args []string) error {
var err error
name := args[0]
collectionFactory := context.NewCollectionFactory()
@@ -85,7 +85,7 @@ func aptlySnapshotShowTxt(cmd *commander.Command, args []string) error {
return err
}
func aptlySnapshotShowJSON(cmd *commander.Command, args []string) error {
func aptlySnapshotShowJSON(_ *commander.Command, args []string) error {
var err error
name := args[0]
+3 -4
View File
@@ -62,11 +62,10 @@ func aptlyTaskRun(cmd *commander.Command, args []string) error {
text, _ = reader.ReadString('\n')
if text == "\n" {
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 {
+1 -1
View File
@@ -74,7 +74,7 @@ func (p *Progress) Flush() {
}
// 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 {
panic("bar already initialized")
}
+3 -3
View File
@@ -457,7 +457,7 @@ func (context *AptlyContext) pgpProvider() string {
return provider
}
func (context *AptlyContext) getGPGFinder(provider string) pgp.GPGFinder {
func (context *AptlyContext) getGPGFinder() pgp.GPGFinder {
switch context.pgpProvider() {
case "gpg1":
return pgp.GPG1Finder()
@@ -480,7 +480,7 @@ func (context *AptlyContext) GetSigner() pgp.Signer {
return &pgp.GoSigner{}
}
return pgp.NewGpgSigner(context.getGPGFinder(provider))
return pgp.NewGpgSigner(context.getGPGFinder())
}
// GetVerifier returns Verifier with respect to provider
@@ -493,7 +493,7 @@ func (context *AptlyContext) GetVerifier() pgp.Verifier {
return &pgp.GoVerifier{}
}
return pgp.NewGpgVerifier(context.getGPGFinder(provider))
return pgp.NewGpgVerifier(context.getGPGFinder())
}
// 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
func (c *Changes) MatchesDependency(d Dependency) bool {
func (c *Changes) MatchesDependency(_ Dependency) bool {
return false
}
// MatchesArchitecture implements PackageLike interface
func (c *Changes) MatchesArchitecture(arch string) bool {
func (c *Changes) MatchesArchitecture(_ string) bool {
return false
}
+1 -1
View File
@@ -317,7 +317,7 @@ func (collection *PackageCollection) Scan(q PackageQuery) (result *PackageList)
}
// 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")
}
+5 -5
View File
@@ -138,7 +138,7 @@ func (q *NotQuery) Matches(pkg PackageLike) bool {
}
// Fast is false
func (q *NotQuery) Fast(list PackageCatalog) bool {
func (q *NotQuery) Fast(_ PackageCatalog) bool {
return false
}
@@ -197,7 +197,7 @@ func (q *FieldQuery) Query(list PackageCatalog) (result *PackageList) {
}
// Fast depends on the query
func (q *FieldQuery) Fast(list PackageCatalog) bool {
func (q *FieldQuery) Fast(_ PackageCatalog) bool {
return false
}
@@ -265,7 +265,7 @@ func (q *PkgQuery) Matches(pkg PackageLike) bool {
}
// Fast is always true for package query
func (q *PkgQuery) Fast(list PackageCatalog) bool {
func (q *PkgQuery) Fast(_ PackageCatalog) bool {
return true
}
@@ -280,12 +280,12 @@ func (q *PkgQuery) String() string {
}
// Matches on specific properties
func (q *MatchAllQuery) Matches(pkg PackageLike) bool {
func (q *MatchAllQuery) Matches(_ PackageLike) bool {
return true
}
// Fast is always true for match all query
func (q *MatchAllQuery) Fast(list PackageCatalog) bool {
func (q *MatchAllQuery) Fast(_ PackageCatalog) bool {
return true
}
+1 -1
View File
@@ -428,7 +428,7 @@ ok:
}
// 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 {
if repo.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
}
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 {
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
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)
if err != nil {
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
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)
if err != nil {
return err
+2 -2
View File
@@ -114,7 +114,7 @@ func (d *GrabDownloader) maybeSetupChecksum(req *grab.Request, expected *utils.C
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
d.log("Download %s -> %s\n", url, destination)
@@ -155,7 +155,7 @@ func (d *GrabDownloader) GetProgress() aptly.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)
if err != nil {
return -1, err
-4
View File
@@ -1,9 +1,7 @@
package main
import (
"math/rand"
"os"
"time"
"github.com/aptly-dev/aptly/aptly"
"github.com/aptly-dev/aptly/cmd"
@@ -22,7 +20,5 @@ func main() {
aptly.Version = Version
rand.Seed(time.Now().UnixNano())
os.Exit(cmd.Run(cmd.RootCommand(), os.Args[1:], true))
}
-3
View File
@@ -6,7 +6,6 @@ package main
import (
"flag"
"fmt"
"math/rand"
"os"
"strings"
"testing"
@@ -53,8 +52,6 @@ func TestRunMain(t *testing.T) {
aptly.Version = Version
rand.Seed(time.Now().UnixNano())
args := filterOutTestArgs(os.Args[1:])
root := cmd.RootCommand()
root.UsageLine = "aptly"
+2 -2
View File
@@ -131,7 +131,7 @@ func (storage *PublishedStorage) String() string {
}
// MkDir creates directory recursively under public path
func (storage *PublishedStorage) MkDir(path string) error {
func (storage *PublishedStorage) MkDir(_ string) error {
// no op for S3
return nil
}
@@ -232,7 +232,7 @@ func (storage *PublishedStorage) Remove(path string) error {
}
// 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
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
func (storage *PublishedStorage) MkDir(path string) error {
func (storage *PublishedStorage) MkDir(_ string) error {
// no op for Swift
return nil
}
@@ -155,7 +155,7 @@ func (storage *PublishedStorage) Remove(path string) error {
}
// 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)
opts := swift.ObjectsOpts{
Prefix: path,
-3
View File
@@ -6,7 +6,6 @@ import (
"math/rand"
"os"
"path/filepath"
"time"
. "gopkg.in/check.v1"
@@ -27,8 +26,6 @@ var _ = Suite(&PublishedStorageSuite{})
func (s *PublishedStorageSuite) SetUpTest(c *C) {
var err error
rand.Seed(int64(time.Now().Nanosecond()))
s.TestAddress = fmt.Sprintf("localhost:%d", rand.Intn(10000)+20000)
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
func (t *Output) InitBar(count int64, isBytes bool, barType aptly.BarType) {
func (t *Output) InitBar(_ int64, _ bool, _ aptly.BarType) {
// Not implemented
}
// 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
if barType == aptly.BarPublishGeneratePackageFiles {
t.TotalNumberOfPackages = count
@@ -88,12 +88,12 @@ func (t *PublishOutput) ShutdownBar() {
}
// AddBar is needed for progress compatibility
func (t *Output) AddBar(count int) {
func (t *Output) AddBar(_ int) {
// Not implemented
}
// AddBar publish output specific
func (t *PublishOutput) AddBar(count int) {
func (t *PublishOutput) AddBar(_ int) {
if t.barType != nil && *t.barType == aptly.BarPublishGeneratePackageFiles {
t.RemainingNumberOfPackages--
t.Store(t)
@@ -101,7 +101,7 @@ func (t *PublishOutput) AddBar(count int) {
}
// SetBar sets current position for progress bar
func (t *Output) SetBar(count int) {
func (t *Output) SetBar(_ int) {
// Not implemented
}
@@ -123,5 +123,5 @@ func (t *Output) ColoredPrintf(msg string, a ...interface{}) {
// PrintfStdErr does printf but in safe manner to output
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{}
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()
ts := t.Format(time.RFC3339)
e.Str("time", ts)