1
0
mirror of https://github.com/mgechev/revive.git synced 2025-01-10 03:17:11 +02:00

Merge pull request #78 from xuri/miscellaneous

Fix rule name in README, and format code.
This commit is contained in:
SalvadorC 2018-10-03 14:55:27 +02:00 committed by GitHub
commit e9013628d7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 30 additions and 25 deletions

View File

@ -41,6 +41,8 @@ Here's how `revive` is different from `golint`:
- [Custom Configuration](#custom-configuration)
- [Recommended Configuration](#recommended-configuration)
- [Available Rules](#available-rules)
- [Configurable rules](#configurable-rules)
- [`var-naming`](#var-naming)
- [Available Formatters](#available-formatters)
- [Friendly](#friendly)
- [Stylish](#stylish)
@ -51,7 +53,7 @@ Here's how `revive` is different from `golint`:
- [Custom Formatter](#custom-formatter)
- [Speed Comparison](#speed-comparison)
- [golint](#golint)
- [revive](#revive-1)
- [revive](#revive)
- [Contributors](#contributors)
- [License](#license)
@ -272,7 +274,7 @@ List of all available rules. The rules ported from `golint` are left unchanged a
| `function-result-limit` | int | Specifies the maximum number of results a function can return | no | no |
| `imports-blacklist` | []string | Disallows importing the specified packages | no | no |
| `range-val-in-closure`| n/a | Warns if range value is used in a closure dispatched as goroutine| no | no |
| `waitgroup-by-value `| n/a | Warns on functions taking sync.WaitGroup as a by-value parameter | no | no |
| `waitgroup-by-value` | n/a | Warns on functions taking sync.WaitGroup as a by-value parameter | no | no |
| `atomic` | n/a | Check for common mistaken usages of the `sync/atomic` package | no | no |
## Configurable rules

View File

@ -68,7 +68,7 @@ var allRules = append([]lint.Rule{
&rule.FunctionResultsLimitRule{},
&rule.MaxPublicStructsRule{},
&rule.RangeValInClosureRule{},
&rule.WaitGroupByCopyRule{},
&rule.WaitGroupByValueRule{},
&rule.AtomicRule{},
}, defaultRules...)

View File

@ -1,36 +1,37 @@
package rule
import (
"github.com/mgechev/revive/lint"
"go/ast"
"github.com/mgechev/revive/lint"
)
// WaitGroupByCopyRule lints sync.WaitGroup passed by copy in functions.
type WaitGroupByCopyRule struct{}
// WaitGroupByValueRule lints sync.WaitGroup passed by copy in functions.
type WaitGroupByValueRule struct{}
// Apply applies the rule to given file.
func (r *WaitGroupByCopyRule) Apply(file *lint.File, _ lint.Arguments) []lint.Failure {
func (r *WaitGroupByValueRule) Apply(file *lint.File, _ lint.Arguments) []lint.Failure {
var failures []lint.Failure
onFailure := func(failure lint.Failure) {
failures = append(failures, failure)
}
w := lintWaitGroupByCopyRule{onFailure: onFailure}
w := lintWaitGroupByValueRule{onFailure: onFailure}
ast.Walk(w, file.AST)
return failures
}
// Name returns the rule name.
func (r *WaitGroupByCopyRule) Name() string {
return "waitgroup-by-copy"
func (r *WaitGroupByValueRule) Name() string {
return "waitgroup-by-value"
}
type lintWaitGroupByCopyRule struct {
type lintWaitGroupByValueRule struct {
onFailure func(lint.Failure)
}
func (w lintWaitGroupByCopyRule) Visit(node ast.Node) ast.Visitor {
func (w lintWaitGroupByValueRule) Visit(node ast.Node) ast.Visitor {
// look for function declarations
fd, ok := node.(*ast.FuncDecl)
if !ok {
@ -53,7 +54,7 @@ func (w lintWaitGroupByCopyRule) Visit(node ast.Node) ast.Visitor {
return nil
}
func (lintWaitGroupByCopyRule) isWaitGroup(ft ast.Expr) bool {
func (lintWaitGroupByValueRule) isWaitGroup(ft ast.Expr) bool {
se, ok := ft.(*ast.SelectorExpr)
if !ok {
return false

View File

@ -1,11 +0,0 @@
package test
import (
"testing"
"github.com/mgechev/revive/rule"
)
func TestWaitGroupByCopy(t *testing.T) {
testRule(t, "waitgroup-by-copy", &rule.WaitGroupByCopyRule{})
}

View File

@ -0,0 +1,11 @@
package test
import (
"testing"
"github.com/mgechev/revive/rule"
)
func TestWaitGroupByValue(t *testing.T) {
testRule(t, "waitgroup-by-value", &rule.WaitGroupByValueRule{})
}

View File

@ -14,3 +14,5 @@
[rule.indent-error-flow]
[rule.empty-block]
[rule.range-val-in-closure]
[rule.waitgroup-by-value]
[rule.atomic]