mirror of
				https://github.com/mgechev/revive.git
				synced 2025-10-30 23:37:49 +02:00 
			
		
		
		
	Rename rule name waitgroup-by-copy to waitgroup-by-value
This commit is contained in:
		| @@ -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-copy`   |  n/a   | Warns on functions taking sync.WaitGroup as a by-copy 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 | ||||
|   | ||||
| @@ -68,7 +68,7 @@ var allRules = append([]lint.Rule{ | ||||
| 	&rule.FunctionResultsLimitRule{}, | ||||
| 	&rule.MaxPublicStructsRule{}, | ||||
| 	&rule.RangeValInClosureRule{}, | ||||
| 	&rule.WaitGroupByCopyRule{}, | ||||
| 	&rule.WaitGroupByValueRule{}, | ||||
| 	&rule.AtomicRule{}, | ||||
| }, defaultRules...) | ||||
|  | ||||
|   | ||||
| @@ -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 | ||||
| @@ -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,5 +14,5 @@ | ||||
| [rule.indent-error-flow] | ||||
| [rule.empty-block] | ||||
| [rule.range-val-in-closure] | ||||
| [rule.waitgroup-by-copy] | ||||
| [rule.waitgroup-by-value] | ||||
| [rule.atomic] | ||||
|   | ||||
		Reference in New Issue
	
	Block a user