-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* rename allRules to defaultRules * rename allFormatters to defaultFormatters * rename GetRules to GetEnabledRules * move config utils to config.go * move linter utils to lint.go * update test files
- Loading branch information
1 parent
e007af6
commit 63f2581
Showing
7 changed files
with
164 additions
and
176 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
package config | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/conventionalcommit/commitlint/lint" | ||
) | ||
|
||
// GetLinter returns Linter for given confFilePath | ||
func GetLinter(conf *lint.Config) (*lint.Linter, error) { | ||
rules, err := GetEnabledRules(conf) | ||
if err != nil { | ||
return nil, err | ||
} | ||
return lint.NewLinter(conf, rules) | ||
} | ||
|
||
// GetFormatter returns the formatter as defined in conf | ||
func GetFormatter(c *lint.Config) (lint.Formatter, error) { | ||
for _, f := range defaultFormatters { | ||
if f.Name() == c.Formatter { | ||
return f, nil | ||
} | ||
} | ||
return nil, fmt.Errorf("%s formatter not found", c.Formatter) | ||
} | ||
|
||
// GetEnabledRules forms Rule object for rules which are enabled in config | ||
func GetEnabledRules(conf *lint.Config) ([]lint.Rule, error) { | ||
// rules lookup map | ||
rulesMap := map[string]lint.Rule{} | ||
for _, r := range defaultRules { | ||
rulesMap[r.Name()] = r | ||
} | ||
|
||
enabledRules := make([]lint.Rule, 0, len(conf.Rules)) | ||
|
||
for ruleName, ruleConfig := range conf.Rules { | ||
r, ok := rulesMap[ruleName] | ||
if !ok { | ||
return nil, fmt.Errorf("unknown rule: %s", ruleName) | ||
} | ||
if ruleConfig.Enabled { | ||
err := r.Apply(ruleConfig.Argument, ruleConfig.Flags) | ||
if err != nil { | ||
return nil, err | ||
} | ||
enabledRules = append(enabledRules, r) | ||
} | ||
} | ||
|
||
return enabledRules, nil | ||
} |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.