1
0
mirror of https://github.com/mgechev/revive.git synced 2025-07-15 01:04:40 +02:00

Improvements

This commit is contained in:
mgechev
2018-01-27 16:37:30 -08:00
parent 8746067321
commit 1870854374
7 changed files with 20 additions and 10 deletions

View File

@ -1,6 +1,8 @@
ignore-generated-header = true
severity = "warning"
confidence = 0.8
[rule.package-comments]
[rule.else]
[rule.names]
[rule.argument-limit]

View File

@ -1,7 +1,7 @@
// Test for returning errors.
// Package foo ...
package pkg
package foo
// Returns nothing
func f() { // ok

View File

@ -42,7 +42,8 @@ func isGenerated(src []byte) bool {
}
// Lint lints a set of files with the specified rule.
func (l *Linter) Lint(filenames []string, ruleSet []Rule, rulesConfig RulesConfig) (<-chan Failure, error) {
func (l *Linter) Lint(filenames []string, ruleSet []Rule, config Config) (<-chan Failure, error) {
rulesConfig := config.Rules
failures := make(chan Failure)
pkg := &Package{
fset: token.NewFileSet(),
@ -54,7 +55,7 @@ func (l *Linter) Lint(filenames []string, ruleSet []Rule, rulesConfig RulesConfi
if err != nil {
return nil, err
}
if isGenerated(content) {
if isGenerated(content) && !config.IgnoreGeneratedHeader {
continue
}

View File

@ -140,6 +140,10 @@ func receiverType(fn *ast.FuncDecl) string {
}
func (p *Package) lint(rules []Rule, config RulesConfig, failures chan Failure) {
if len(p.files) == 0 {
close(failures)
return
}
p.typeCheck()
p.scanSortable()
var wg sync.WaitGroup

View File

@ -60,6 +60,7 @@ type RulesConfig = map[string]RuleConfig
// Config defines the config of the linter.
type Config struct {
IgnoreGeneratedHeader bool `toml:"ignore-generated-header"`
Confidence float64
Severity Severity
Rules RulesConfig `toml:"rule"`

View File

@ -27,7 +27,7 @@ func main() {
lintingRules := getLintingRules(config)
failures, err := revive.Lint(files, lintingRules, config.Rules)
failures, err := revive.Lint(files, lintingRules, *config)
if err != nil {
panic(err)
}

View File

@ -58,10 +58,10 @@ var rules = []lint.Rule{
func TestVarDeclaration(t *testing.T) {
testRule(t, "cyclomatic", &rule.CyclomaticRule{}, &lint.RuleConfig{
Arguments: []string{"1"},
Arguments: []interface{}{int64(1)},
})
testRule(t, "cyclomatic-2", &rule.CyclomaticRule{}, &lint.RuleConfig{
Arguments: []string{"3"},
Arguments: []interface{}{int64(3)},
})
}
@ -141,7 +141,9 @@ func assertFailures(t *testing.T, baseDir string, fi os.FileInfo, src []byte, ru
return errors.Errorf("Test file %v does not have instructions", fi.Name())
}
ps, err := l.Lint([]string{fi.Name()}, rules, config)
ps, err := l.Lint([]string{fi.Name()}, rules, lint.Config{
Rules: config,
})
if err != nil {
return err
}