Skip to content
This repository has been archived by the owner on Sep 9, 2020. It is now read-only.

Commit

Permalink
Address code climate warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
carolynvs committed Aug 30, 2017
1 parent ee8ead1 commit 834e8e6
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 37 deletions.
15 changes: 3 additions & 12 deletions cmd/dep/base_importer.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ import (
"github.com/pkg/errors"
)

// baseImporter provides a common implementation for importing from other
// dependency managers.
type baseImporter struct {
logger *log.Logger
verbose bool
Expand All @@ -21,6 +23,7 @@ type baseImporter struct {
lock *dep.Lock
}

// newBaseImporter creates a new baseImporter for embedding in an importer.
func newBaseImporter(logger *log.Logger, verbose bool, sm gps.SourceManager) *baseImporter {
return &baseImporter{
logger: logger,
Expand Down Expand Up @@ -90,18 +93,6 @@ func (i *baseImporter) lookupVersionForLockedProject(pi gps.ProjectIdentifier, c
return rev, nil
}

// projectExistsInLock checks if the given project already exists in
// a lockfile.
func projectExistsInLock(l *dep.Lock, pr gps.ProjectRoot) bool {
for _, lp := range l.P {
if pr == lp.Ident().ProjectRoot {
return true
}
}

return false
}

// importedPackage is a common intermediate representation of a package imported
// from an external tool's configuration.
type importedPackage struct {
Expand Down
20 changes: 10 additions & 10 deletions cmd/dep/glide_importer.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ type glideLock struct {

type glidePackage struct {
Name string `yaml:"package"`
Reference string `yaml:"version"`
Reference string `yaml:"version"` // could contain a semver, tag or branch
Repository string `yaml:"repo"`

// Unsupported fields that we will warn if used
Expand All @@ -60,7 +60,7 @@ type glidePackage struct {

type glideLockedPackage struct {
Name string `yaml:"name"`
Reference string `yaml:"version"` // TODO(carolynvs) Rename to Revision
Revision string `yaml:"version"`
Repository string `yaml:"repo"`
}

Expand Down Expand Up @@ -96,11 +96,11 @@ func (g *glideImporter) load(projectDir string) error {
}
yb, err := ioutil.ReadFile(y)
if err != nil {
return errors.Wrapf(err, "Unable to read %s", y)
return errors.Wrapf(err, "unable to read %s", y)
}
err = yaml.Unmarshal(yb, &g.glideConfig)
if err != nil {
return errors.Wrapf(err, "Unable to parse %s", y)
return errors.Wrapf(err, "unable to parse %s", y)
}

l := filepath.Join(projectDir, glideLockName)
Expand All @@ -111,12 +111,12 @@ func (g *glideImporter) load(projectDir string) error {
g.lockFound = true
lb, err := ioutil.ReadFile(l)
if err != nil {
return errors.Wrapf(err, "Unable to read %s", l)
return errors.Wrapf(err, "unable to read %s", l)
}
lock := glideLock{}
err = yaml.Unmarshal(lb, &lock)
if err != nil {
return errors.Wrapf(err, "Unable to parse %s", l)
return errors.Wrapf(err, "unable to parse %s", l)
}
g.glideLock = lock
}
Expand All @@ -142,7 +142,7 @@ func (g *glideImporter) convert(pr gps.ProjectRoot) (*dep.Manifest, *dep.Lock, e
for _, pkg := range append(g.glideConfig.Imports, g.glideConfig.TestImports...) {
// Validate
if pkg.Name == "" {
return nil, nil, errors.New("Invalid glide configuration: Name is required.")
return nil, nil, errors.New("invalid glide configuration: Name is required.")
}

// Warn
Expand All @@ -167,20 +167,20 @@ func (g *glideImporter) convert(pr gps.ProjectRoot) (*dep.Manifest, *dep.Lock, e
for _, pkg := range append(g.glideLock.Imports, g.glideLock.TestImports...) {
// Validate
if pkg.Name == "" {
return nil, nil, errors.New("Invalid glide lock: Name is required.")
return nil, nil, errors.New("invalid glide lock: Name is required.")
}

ip := importedPackage{
Name: pkg.Name,
Source: pkg.Repository,
LockHint: pkg.Reference,
LockHint: pkg.Revision,
}
packages = append(packages, ip)
}

err := g.importPackages(packages, false)
if err != nil {
return nil, nil, errors.Wrap(err, "Invalid glide configuration")
return nil, nil, errors.Wrap(err, "invalid glide configuration")
}

// Ignores
Expand Down
10 changes: 5 additions & 5 deletions cmd/dep/glide_importer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ func TestGlideConfig_Convert(t *testing.T) {
{
Name: "github.com/sdboyer/deptest",
Repository: "https://github.com/sdboyer/deptest.git",
Reference: "ff2948a2ac8f538c4ecd55962e919d1e13e74baf",
Revision: "ff2948a2ac8f538c4ecd55962e919d1e13e74baf",
},
},
},
Expand All @@ -76,8 +76,8 @@ func TestGlideConfig_Convert(t *testing.T) {
glideLock{
TestImports: []glideLockedPackage{
{
Name: "github.com/sdboyer/deptest",
Reference: "ff2948a2ac8f538c4ecd55962e919d1e13e74baf",
Name: "github.com/sdboyer/deptest",
Revision: "ff2948a2ac8f538c4ecd55962e919d1e13e74baf",
},
},
},
Expand All @@ -99,8 +99,8 @@ func TestGlideConfig_Convert(t *testing.T) {
glideLock{
Imports: []glideLockedPackage{
{
Name: "github.com/sdboyer/deptest",
Reference: "ff2948a2ac8f538c4ecd55962e919d1e13e74baf",
Name: "github.com/sdboyer/deptest",
Revision: "ff2948a2ac8f538c4ecd55962e919d1e13e74baf",
},
},
},
Expand Down
8 changes: 4 additions & 4 deletions cmd/dep/godep_importer.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,11 +67,11 @@ func (g *godepImporter) load(projectDir string) error {
}
jb, err := ioutil.ReadFile(j)
if err != nil {
return errors.Wrapf(err, "Unable to read %s", j)
return errors.Wrapf(err, "unable to read %s", j)
}
err = json.Unmarshal(jb, &g.json)
if err != nil {
return errors.Wrapf(err, "Unable to parse %s", j)
return errors.Wrapf(err, "unable to parse %s", j)
}

return nil
Expand All @@ -84,12 +84,12 @@ func (g *godepImporter) convert(pr gps.ProjectRoot) (*dep.Manifest, *dep.Lock, e
for _, pkg := range g.json.Imports {
// Validate
if pkg.ImportPath == "" {
err := errors.New("Invalid godep configuration, ImportPath is required")
err := errors.New("invalid godep configuration, ImportPath is required")
return nil, nil, err
}

if pkg.Rev == "" {
err := errors.New("Invalid godep configuration, Rev is required")
err := errors.New("invalid godep configuration, Rev is required")
return nil, nil, err
}

Expand Down
6 changes: 3 additions & 3 deletions cmd/dep/govend_importer.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,11 +70,11 @@ func (g *govendImporter) load(projectDir string) error {
}
yb, err := ioutil.ReadFile(y)
if err != nil {
return errors.Wrapf(err, "Unable to read %s", y)
return errors.Wrapf(err, "unable to read %s", y)
}
err = yaml.Unmarshal(yb, &g.yaml)
if err != nil {
return errors.Wrapf(err, "Unable to parse %s", y)
return errors.Wrapf(err, "unable to parse %s", y)
}
return nil
}
Expand All @@ -87,7 +87,7 @@ func (g *govendImporter) convert(pr gps.ProjectRoot) (*dep.Manifest, *dep.Lock,
for _, pkg := range g.yaml.Imports {
// Path must not be empty
if pkg.Path == "" || pkg.Revision == "" {
return nil, nil, errors.New("Invalid govend configuration, path and rev are required")
return nil, nil, errors.New("invalid govend configuration, path and rev are required")
}

ip := importedPackage{
Expand Down
6 changes: 3 additions & 3 deletions cmd/dep/vndr_importer.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ func (v *vndrImporter) loadVndrFile(dir string) error {

f, err := os.Open(vndrFile(dir))
if err != nil {
return errors.Wrapf(err, "Unable to open %s", vndrFile(dir))
return errors.Wrapf(err, "unable to open %s", vndrFile(dir))
}
defer f.Close()

Expand Down Expand Up @@ -81,12 +81,12 @@ func (v *vndrImporter) convert(pr gps.ProjectRoot) (*dep.Manifest, *dep.Lock, er
for _, pkg := range v.packages {
// Validate
if pkg.importPath == "" {
err := errors.New("Invalid vndr configuration, import path is required")
err := errors.New("invalid vndr configuration: import path is required")
return nil, nil, err
}

if pkg.reference == "" {
err := errors.New("Invalid vndr configuration, revision is required")
err := errors.New("invalid vndr configuration: revision is required")
return nil, nil, err
}

Expand Down

0 comments on commit 834e8e6

Please sign in to comment.