mirror of
https://github.com/mgechev/revive.git
synced 2025-01-24 03:47:45 +02:00
Merge pull request #78 from xuri/miscellaneous
Fix rule name in README, and format code.
This commit is contained in:
commit
e9013628d7
@ -41,6 +41,8 @@ Here's how `revive` is different from `golint`:
|
|||||||
- [Custom Configuration](#custom-configuration)
|
- [Custom Configuration](#custom-configuration)
|
||||||
- [Recommended Configuration](#recommended-configuration)
|
- [Recommended Configuration](#recommended-configuration)
|
||||||
- [Available Rules](#available-rules)
|
- [Available Rules](#available-rules)
|
||||||
|
- [Configurable rules](#configurable-rules)
|
||||||
|
- [`var-naming`](#var-naming)
|
||||||
- [Available Formatters](#available-formatters)
|
- [Available Formatters](#available-formatters)
|
||||||
- [Friendly](#friendly)
|
- [Friendly](#friendly)
|
||||||
- [Stylish](#stylish)
|
- [Stylish](#stylish)
|
||||||
@ -51,7 +53,7 @@ Here's how `revive` is different from `golint`:
|
|||||||
- [Custom Formatter](#custom-formatter)
|
- [Custom Formatter](#custom-formatter)
|
||||||
- [Speed Comparison](#speed-comparison)
|
- [Speed Comparison](#speed-comparison)
|
||||||
- [golint](#golint)
|
- [golint](#golint)
|
||||||
- [revive](#revive-1)
|
- [revive](#revive)
|
||||||
- [Contributors](#contributors)
|
- [Contributors](#contributors)
|
||||||
- [License](#license)
|
- [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 |
|
| `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 |
|
| `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 |
|
| `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 |
|
| `atomic` | n/a | Check for common mistaken usages of the `sync/atomic` package | no | no |
|
||||||
|
|
||||||
## Configurable rules
|
## Configurable rules
|
||||||
|
@ -68,8 +68,8 @@ var allRules = append([]lint.Rule{
|
|||||||
&rule.FunctionResultsLimitRule{},
|
&rule.FunctionResultsLimitRule{},
|
||||||
&rule.MaxPublicStructsRule{},
|
&rule.MaxPublicStructsRule{},
|
||||||
&rule.RangeValInClosureRule{},
|
&rule.RangeValInClosureRule{},
|
||||||
&rule.WaitGroupByCopyRule{},
|
&rule.WaitGroupByValueRule{},
|
||||||
&rule.AtomicRule{},
|
&rule.AtomicRule{},
|
||||||
}, defaultRules...)
|
}, defaultRules...)
|
||||||
|
|
||||||
var allFormatters = []lint.Formatter{
|
var allFormatters = []lint.Formatter{
|
||||||
|
@ -1,36 +1,37 @@
|
|||||||
package rule
|
package rule
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/mgechev/revive/lint"
|
|
||||||
"go/ast"
|
"go/ast"
|
||||||
|
|
||||||
|
"github.com/mgechev/revive/lint"
|
||||||
)
|
)
|
||||||
|
|
||||||
// WaitGroupByCopyRule lints sync.WaitGroup passed by copy in functions.
|
// WaitGroupByValueRule lints sync.WaitGroup passed by copy in functions.
|
||||||
type WaitGroupByCopyRule struct{}
|
type WaitGroupByValueRule struct{}
|
||||||
|
|
||||||
// Apply applies the rule to given file.
|
// 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
|
var failures []lint.Failure
|
||||||
|
|
||||||
onFailure := func(failure lint.Failure) {
|
onFailure := func(failure lint.Failure) {
|
||||||
failures = append(failures, failure)
|
failures = append(failures, failure)
|
||||||
}
|
}
|
||||||
|
|
||||||
w := lintWaitGroupByCopyRule{onFailure: onFailure}
|
w := lintWaitGroupByValueRule{onFailure: onFailure}
|
||||||
ast.Walk(w, file.AST)
|
ast.Walk(w, file.AST)
|
||||||
return failures
|
return failures
|
||||||
}
|
}
|
||||||
|
|
||||||
// Name returns the rule name.
|
// Name returns the rule name.
|
||||||
func (r *WaitGroupByCopyRule) Name() string {
|
func (r *WaitGroupByValueRule) Name() string {
|
||||||
return "waitgroup-by-copy"
|
return "waitgroup-by-value"
|
||||||
}
|
}
|
||||||
|
|
||||||
type lintWaitGroupByCopyRule struct {
|
type lintWaitGroupByValueRule struct {
|
||||||
onFailure func(lint.Failure)
|
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
|
// look for function declarations
|
||||||
fd, ok := node.(*ast.FuncDecl)
|
fd, ok := node.(*ast.FuncDecl)
|
||||||
if !ok {
|
if !ok {
|
||||||
@ -53,7 +54,7 @@ func (w lintWaitGroupByCopyRule) Visit(node ast.Node) ast.Visitor {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (lintWaitGroupByCopyRule) isWaitGroup(ft ast.Expr) bool {
|
func (lintWaitGroupByValueRule) isWaitGroup(ft ast.Expr) bool {
|
||||||
se, ok := ft.(*ast.SelectorExpr)
|
se, ok := ft.(*ast.SelectorExpr)
|
||||||
if !ok {
|
if !ok {
|
||||||
return false
|
return false
|
@ -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{})
|
|
||||||
}
|
|
11
test/waitgroup-by-value_test.go
Normal file
11
test/waitgroup-by-value_test.go
Normal 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{})
|
||||||
|
}
|
@ -14,3 +14,5 @@
|
|||||||
[rule.indent-error-flow]
|
[rule.indent-error-flow]
|
||||||
[rule.empty-block]
|
[rule.empty-block]
|
||||||
[rule.range-val-in-closure]
|
[rule.range-val-in-closure]
|
||||||
|
[rule.waitgroup-by-value]
|
||||||
|
[rule.atomic]
|
||||||
|
Loading…
x
Reference in New Issue
Block a user