Skip to content
This repository has been archived by the owner on Jun 26, 2023. It is now read-only.

Commit

Permalink
Fix panic error and refactor a bit
Browse files Browse the repository at this point in the history
  • Loading branch information
babarot committed Jan 21, 2019
1 parent 27326d9 commit 3f526bb
Showing 1 changed file with 10 additions and 9 deletions.
19 changes: 10 additions & 9 deletions lint/lint.go
Expand Up @@ -169,11 +169,10 @@ func (l *Linter) Run(file File) (Result, error) {
return result, err
}

// Check if the rule has own dependencies
if rule.hasDependencies() {
ok := rule.checkDependenciesFailed(result)
// Skip execution of the rule if the dependent rule fails
ok := rule.checkDependenciesAreOK(result)
if !ok {
// skip this rule because the rule which it depends on has failed
continue
}
}
Expand Down Expand Up @@ -242,14 +241,17 @@ func (r *Rules) Sort() {
}
}

orderNames, ok := graph.Sort()
orderedRuleNames, ok := graph.Sort()
if !ok {
panic("error")
// TODO: Handle this pattern
// For now it can be ignored.
//
// return
}

var sortedRules Rules
for _, name := range orderNames {
sortedRules = append(sortedRules, r.getOneByName(name))
for _, orderedRuleName := range orderedRuleNames {
sortedRules = append(sortedRules, r.getOneByName(orderedRuleName))
}
*r = sortedRules
}
Expand All @@ -267,8 +269,7 @@ func (r *Rule) hasDependencies() bool {
return len(r.Dependencies) > 0
}

// check if the rules which this rule depends on are failed
func (r *Rule) checkDependenciesFailed(result Result) bool {
func (r *Rule) checkDependenciesAreOK(result Result) bool {
for _, dependency := range r.Dependencies {
depRule := strings.TrimPrefix(dependency, RulePrefix)
item := result.Items.getOneByName(depRule)
Expand Down

0 comments on commit 3f526bb

Please sign in to comment.