Skip to content

Commit

Permalink
prefer fallbacks within switch statement
Browse files Browse the repository at this point in the history
  • Loading branch information
microsoftly committed Sep 10, 2018
1 parent 8bedfaf commit d2c7dda
Showing 1 changed file with 15 additions and 9 deletions.
24 changes: 15 additions & 9 deletions analyzers/ruby/ruby.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ func (a *Analyzer) Analyze() (graph.Deps, error) {
case "list":
return a.bundlerListAnalyzerStrategy()
case "lockfile":
return a.lockfileAnalyzerStrategy(lockfilePath, shouldFallback)
return a.lockfileAnalyzerStrategy(lockfilePath)
case "list-lockfile":
fallthrough
default:
Expand All @@ -151,7 +151,7 @@ func (a *Analyzer) Analyze() (graph.Deps, error) {
return graph.Deps{}, err
}

return a.lockfileAnalyzerStrategy(lockfilePath, shouldFallback)
return a.lockfileAnalyzerStrategy(lockfilePath)
}

gems, err := a.Bundler.List()
Expand All @@ -160,7 +160,17 @@ func (a *Analyzer) Analyze() (graph.Deps, error) {
return graph.Deps{}, err
}

return a.lockfileAnalyzerStrategy(lockfilePath, shouldFallback)
deps, err := a.lockfileAnalyzerStrategy(lockfilePath)

if err != nil {
if !shouldFallback {
return graph.Deps{}, err
}

return a.bundlerListAnalyzerStrategy()
}

return deps, err
}

imports, deps := FilteredLockfile(gems, lockfile)
Expand All @@ -186,14 +196,10 @@ func (a *Analyzer) bundlerListAnalyzerStrategy() (graph.Deps, error) {
}, nil
}

func (a *Analyzer) lockfileAnalyzerStrategy(lockfilePath string, shouldFallback bool) (graph.Deps, error) {
func (a *Analyzer) lockfileAnalyzerStrategy(lockfilePath string) (graph.Deps, error) {
lockfile, err := bundler.FromLockfile(lockfilePath)
if err != nil {
if !shouldFallback {
return graph.Deps{}, err
}

return a.bundlerListAnalyzerStrategy()
return graph.Deps{}, err
}

imports, deps := FromLockfile(lockfile)
Expand Down

0 comments on commit d2c7dda

Please sign in to comment.