Enable gosimple and ineffasign linters

This commit is contained in:
Andrey Smirnov
2017-04-27 18:34:30 +03:00
parent 7a7b981d4f
commit bae3f949b4
16 changed files with 32 additions and 49 deletions

View File

@@ -55,11 +55,8 @@ func printReferencesTo(p *deb.Package) (err error) {
}
return nil
})
if err != nil {
return err
}
return nil
return err
}
func aptlyPackageShow(cmd *commander.Command, args []string) error {

View File

@@ -273,7 +273,7 @@ func (context *AptlyContext) ReOpenDatabase() error {
for try := 0; try < MaxTries; try++ {
err := context.database.ReOpen()
if err == nil || strings.Index(err.Error(), "resource temporarily unavailable") == -1 {
if err == nil || !strings.Contains(err.Error(), "resource temporarily unavailable") {
return err
}
context._progress().Printf("Unable to reopen database, sleeping %s\n", Delay)

View File

@@ -103,11 +103,7 @@ func (c *Changes) VerifyAndParse(acceptUnsigned, ignoreSignature bool, verifier
c.Architectures = strings.Fields(c.Stanza["Architecture"])
c.Files, err = c.Files.ParseSumFields(c.Stanza)
if err != nil {
return err
}
return nil
return err
}
// Prepare creates temporary directory, copies file there and verifies checksums
@@ -181,8 +177,7 @@ func (c *Changes) PackageQuery() (PackageQuery, error) {
if len(c.Binary) > 0 {
binaryQuery = &FieldQuery{Field: "Name", Relation: VersionEqual, Value: c.Binary[0]}
// matching debug ddeb packages, they're not present in the Binary field
var ddebQuery PackageQuery
ddebQuery = &FieldQuery{Field: "Name", Relation: VersionEqual, Value: fmt.Sprintf("%s-dbgsym", c.Binary[0])}
var ddebQuery PackageQuery = &FieldQuery{Field: "Name", Relation: VersionEqual, Value: fmt.Sprintf("%s-dbgsym", c.Binary[0])}
for _, binary := range c.Binary[1:] {
binaryQuery = &OrQuery{

View File

@@ -175,9 +175,7 @@ func GetContentsFromDeb(file aptly.ReadSeekerCloser, packageFile string) ([]stri
continue
}
if strings.HasPrefix(tarHeader.Name, "./") {
tarHeader.Name = tarHeader.Name[2:]
}
tarHeader.Name = strings.TrimPrefix(tarHeader.Name[2:], "./")
results = append(results, tarHeader.Name)
}
}

View File

@@ -344,7 +344,7 @@ func (p *Package) GetDependencies(options int) (dependencies []string) {
if source == "" {
source = p.Name
}
if strings.Index(source, ")") != -1 {
if strings.Contains(source, ")") {
dependencies = append(dependencies, fmt.Sprintf("%s {source}", source))
} else {
dependencies = append(dependencies, fmt.Sprintf("%s (= %s) {source}", source, p.Version))

View File

@@ -299,7 +299,7 @@ func (s *PackageSuite) TestMatchesDependency(c *C) {
// ~
c.Check(
p.MatchesDependency(Dependency{Pkg: "alien-arena-common", Architecture: "i386", Relation: VersionRegexp, Version: "7\\.40-.*",
Regexp: regexp.MustCompile("7\\.40-.*")}), Equals, true)
Regexp: regexp.MustCompile(`7\.40-.*`)}), Equals, true)
c.Check(
p.MatchesDependency(Dependency{Pkg: "alien-arena-common", Architecture: "i386", Relation: VersionRegexp, Version: "7\\.40-.*",
Regexp: regexp.MustCompile("40")}), Equals, true)

View File

@@ -226,12 +226,7 @@ func NewPublishedRepo(storage, prefix, distribution string, architectures []stri
// clean & verify prefix
prefix = filepath.Clean(prefix)
if strings.HasPrefix(prefix, "/") {
prefix = prefix[1:]
}
if strings.HasSuffix(prefix, "/") {
prefix = prefix[:len(prefix)-1]
}
prefix = strings.TrimPrefix(strings.TrimSuffix(prefix, "/"), "/")
prefix = filepath.Clean(prefix)
for _, part := range strings.Split(prefix, "/") {
@@ -252,7 +247,7 @@ func NewPublishedRepo(storage, prefix, distribution string, architectures []stri
}
}
if strings.Index(distribution, "/") != -1 {
if strings.Contains(distribution, "/") {
return nil, fmt.Errorf("invalid distribution %s, '/' is not allowed", distribution)
}
@@ -474,8 +469,7 @@ func (p *PublishedRepo) Publish(packagePool aptly.PackagePool, publishedStorageP
return err
}
defer func() {
var e error
e = tempDB.Close()
e := tempDB.Close()
if e != nil && progress != nil {
progress.Printf("failed to close temp DB: %s", err)
}
@@ -730,12 +724,7 @@ func (p *PublishedRepo) Publish(packagePool aptly.PackagePool, publishedStorageP
return err
}
err = indexes.RenameFiles()
if err != nil {
return err
}
return nil
return indexes.RenameFiles()
}
// RemoveFiles removes files that were created by Publish

View File

@@ -505,6 +505,7 @@ func (s *PublishedRepoCollectionSuite) TestAddByStoragePrefixDistribution(c *C)
c.Assert(r.String(), Equals, s.repo1.String())
r, err = s.collection.ByStoragePrefixDistribution("files:other", "ppa", "precise")
c.Assert(err, IsNil)
c.Check(r.String(), Equals, s.repo5.String())
}

View File

@@ -204,7 +204,7 @@ func (q *FieldQuery) Fast(list PackageCatalog) bool {
// String interface
func (q *FieldQuery) String() string {
escape := func(val string) string {
if strings.IndexAny(val, "()|,!{} \t\n") != -1 {
if strings.ContainsAny(val, "()|,!{} \t\n") {
return "'" + strings.Replace(strings.Replace(val, "\\", "\\\\", -1), "'", "\\'", -1) + "'"
}
return val

View File

@@ -92,7 +92,7 @@ func (l *PackageRefList) Has(p *Package) bool {
key := p.Key("")
i := sort.Search(len(l.Refs), func(j int) bool { return bytes.Compare(l.Refs[j], key) >= 0 })
return i < len(l.Refs) && bytes.Compare(l.Refs[i], key) == 0
return i < len(l.Refs) && bytes.Equal(l.Refs[i], key)
}
// Strings builds list of strings with package keys

View File

@@ -331,9 +331,7 @@ ok:
if strings.Contains(repo.Distribution, "/") {
distributionLast := path.Base(repo.Distribution) + "/"
for i := range components {
if strings.HasPrefix(components[i], distributionLast) {
components[i] = components[i][len(distributionLast):]
}
components[i] = strings.TrimPrefix(components[i], distributionLast)
}
}
if len(repo.Components) == 0 {

View File

@@ -1,4 +1,13 @@
{
"DisableAll": true,
"Enable": ["vet", "golint", "gofmt", "deadcode", "goimports", "misspell"]
"Enable": [
"vet",
"golint",
"gofmt",
"deadcode",
"goimports",
"misspell",
"gosimple",
"ineffassign"
]
}

View File

@@ -49,7 +49,7 @@ func (s *SyntaxSuite) TestParsing(c *C) {
c.Assert(err, IsNil)
c.Check(q, DeepEquals, &deb.DependencyQuery{Dep: deb.Dependency{Pkg: "package", Relation: deb.VersionRegexp, Version: "5\\.3.*~dev",
Regexp: regexp.MustCompile("5\\.3.*~dev")}})
Regexp: regexp.MustCompile(`5\.3.*~dev`)}})
l, _ = lex("query", "alien-data_1.3.4~dev_i386")
q, err = parse(l)

View File

@@ -165,7 +165,7 @@ func (storage *PublishedStorage) putFile(path string, source io.ReadSeeker) erro
return err
}
if storage.plusWorkaround && strings.Index(path, "+") != -1 {
if storage.plusWorkaround && strings.Contains(path, "+") {
_, err = source.Seek(0, 0)
if err != nil {
return err
@@ -187,7 +187,7 @@ func (storage *PublishedStorage) Remove(path string) error {
return errors.Wrap(err, fmt.Sprintf("error deleting %s from %s", path, storage))
}
if storage.plusWorkaround && strings.Index(path, "+") != -1 {
if storage.plusWorkaround && strings.Contains(path, "+") {
// try to remove workaround version, but don't care about result
_ = storage.Remove(strings.Replace(path, "+", " ", -1))
}
@@ -332,7 +332,7 @@ func (storage *PublishedStorage) internalFilelist(prefix string, hidePlusWorkaro
err = storage.s3.ListObjectsPages(params, func(contents *s3.ListObjectsOutput, lastPage bool) bool {
for _, key := range contents.Contents {
if storage.plusWorkaround && hidePlusWorkaround && strings.Index(*key.Key, " ") != -1 {
if storage.plusWorkaround && hidePlusWorkaround && strings.Contains(*key.Key, " ") {
// if we use plusWorkaround, we want to hide those duplicates
/// from listing
continue

View File

@@ -646,7 +646,7 @@ func (objr objectResource) put(a *action) interface{} {
fatalError(400, "TODO", "read error")
}
gotHash := sum.Sum(nil)
if expectHash != nil && bytes.Compare(gotHash, expectHash) != 0 {
if expectHash != nil && !bytes.Equal(gotHash, expectHash) {
fatalError(400, "BadDigest", "The Content-MD5 you specified did not match what we received")
}
if a.req.ContentLength >= 0 && int64(len(data)) != a.req.ContentLength {

View File

@@ -324,16 +324,12 @@ func (g *GpgVerifier) VerifyDetachedSignature(signature, cleartext io.Reader) er
func (g *GpgVerifier) IsClearSigned(clearsigned io.Reader) (bool, error) {
scanner := bufio.NewScanner(clearsigned)
for scanner.Scan() {
if strings.Index(scanner.Text(), "BEGIN PGP SIGN") != -1 {
if strings.Contains(scanner.Text(), "BEGIN PGP SIGN") {
return true, nil
}
}
if err := scanner.Err(); err != nil {
return false, err
}
return false, nil
return false, scanner.Err()
}
// VerifyClearsigned verifies clearsigned file using gpgv