diff --git a/README.md b/README.md index b598fed..c932287 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/config.go b/config.go index 07b89ef..7c3424d 100644 --- a/config.go +++ b/config.go @@ -68,8 +68,8 @@ var allRules = append([]lint.Rule{ &rule.FunctionResultsLimitRule{}, &rule.MaxPublicStructsRule{}, &rule.RangeValInClosureRule{}, - &rule.WaitGroupByCopyRule{}, - &rule.AtomicRule{}, + &rule.WaitGroupByValueRule{}, + &rule.AtomicRule{}, }, defaultRules...) var allFormatters = []lint.Formatter{ diff --git a/fixtures/waitgroup-by-copy.go b/fixtures/waitgroup-by-value.go similarity index 100% rename from fixtures/waitgroup-by-copy.go rename to fixtures/waitgroup-by-value.go diff --git a/rule/waitgroup-by-copy.go b/rule/waitgroup-by-value.go similarity index 64% rename from rule/waitgroup-by-copy.go rename to rule/waitgroup-by-value.go index 665dba6..b869291 100644 --- a/rule/waitgroup-by-copy.go +++ b/rule/waitgroup-by-value.go @@ -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 diff --git a/test/waitgroup-by-copy_test.go b/test/waitgroup-by-copy_test.go deleted file mode 100644 index a5196ed..0000000 --- a/test/waitgroup-by-copy_test.go +++ /dev/null @@ -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{}) -} diff --git a/test/waitgroup-by-value_test.go b/test/waitgroup-by-value_test.go new file mode 100644 index 0000000..398ac9a --- /dev/null +++ b/test/waitgroup-by-value_test.go @@ -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{}) +} diff --git a/untyped.toml b/untyped.toml index ce5a7bf..b7ee1d2 100644 --- a/untyped.toml +++ b/untyped.toml @@ -14,3 +14,5 @@ [rule.indent-error-flow] [rule.empty-block] [rule.range-val-in-closure] +[rule.waitgroup-by-value] +[rule.atomic]