mirror of
https://github.com/mgechev/revive.git
synced 2025-07-17 01:12:27 +02:00
Improvements
This commit is contained in:
@ -1,6 +1,8 @@
|
|||||||
|
ignore-generated-header = true
|
||||||
severity = "warning"
|
severity = "warning"
|
||||||
confidence = 0.8
|
confidence = 0.8
|
||||||
|
|
||||||
|
[rule.package-comments]
|
||||||
[rule.else]
|
[rule.else]
|
||||||
[rule.names]
|
[rule.names]
|
||||||
[rule.argument-limit]
|
[rule.argument-limit]
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
// Test for returning errors.
|
// Test for returning errors.
|
||||||
|
|
||||||
// Package foo ...
|
// Package foo ...
|
||||||
package pkg
|
package foo
|
||||||
|
|
||||||
// Returns nothing
|
// Returns nothing
|
||||||
func f() { // ok
|
func f() { // ok
|
||||||
|
@ -42,7 +42,8 @@ func isGenerated(src []byte) bool {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Lint lints a set of files with the specified rule.
|
// 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)
|
failures := make(chan Failure)
|
||||||
pkg := &Package{
|
pkg := &Package{
|
||||||
fset: token.NewFileSet(),
|
fset: token.NewFileSet(),
|
||||||
@ -54,7 +55,7 @@ func (l *Linter) Lint(filenames []string, ruleSet []Rule, rulesConfig RulesConfi
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
if isGenerated(content) {
|
if isGenerated(content) && !config.IgnoreGeneratedHeader {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -140,6 +140,10 @@ func receiverType(fn *ast.FuncDecl) string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (p *Package) lint(rules []Rule, config RulesConfig, failures chan Failure) {
|
func (p *Package) lint(rules []Rule, config RulesConfig, failures chan Failure) {
|
||||||
|
if len(p.files) == 0 {
|
||||||
|
close(failures)
|
||||||
|
return
|
||||||
|
}
|
||||||
p.typeCheck()
|
p.typeCheck()
|
||||||
p.scanSortable()
|
p.scanSortable()
|
||||||
var wg sync.WaitGroup
|
var wg sync.WaitGroup
|
||||||
|
@ -60,6 +60,7 @@ type RulesConfig = map[string]RuleConfig
|
|||||||
|
|
||||||
// Config defines the config of the linter.
|
// Config defines the config of the linter.
|
||||||
type Config struct {
|
type Config struct {
|
||||||
|
IgnoreGeneratedHeader bool `toml:"ignore-generated-header"`
|
||||||
Confidence float64
|
Confidence float64
|
||||||
Severity Severity
|
Severity Severity
|
||||||
Rules RulesConfig `toml:"rule"`
|
Rules RulesConfig `toml:"rule"`
|
||||||
|
2
main.go
2
main.go
@ -27,7 +27,7 @@ func main() {
|
|||||||
|
|
||||||
lintingRules := getLintingRules(config)
|
lintingRules := getLintingRules(config)
|
||||||
|
|
||||||
failures, err := revive.Lint(files, lintingRules, config.Rules)
|
failures, err := revive.Lint(files, lintingRules, *config)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
|
@ -58,10 +58,10 @@ var rules = []lint.Rule{
|
|||||||
|
|
||||||
func TestVarDeclaration(t *testing.T) {
|
func TestVarDeclaration(t *testing.T) {
|
||||||
testRule(t, "cyclomatic", &rule.CyclomaticRule{}, &lint.RuleConfig{
|
testRule(t, "cyclomatic", &rule.CyclomaticRule{}, &lint.RuleConfig{
|
||||||
Arguments: []string{"1"},
|
Arguments: []interface{}{int64(1)},
|
||||||
})
|
})
|
||||||
testRule(t, "cyclomatic-2", &rule.CyclomaticRule{}, &lint.RuleConfig{
|
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())
|
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 {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user