mirror of
				https://github.com/mgechev/revive.git
				synced 2025-10-30 23:37:49 +02:00 
			
		
		
		
	var-naming: handle possible panic (#1405)
* var-naming: handle possible panic * Update rule/var_naming.go Co-authored-by: ccoVeille <3875889+ccoVeille@users.noreply.github.com> * fix test * update error message --------- Co-authored-by: ccoVeille <3875889+ccoVeille@users.noreply.github.com>
This commit is contained in:
		| @@ -87,11 +87,15 @@ func (r *VarNamingRule) Configure(arguments lint.Arguments) error { | ||||
| 				if !ok { | ||||
| 					return fmt.Errorf("invalid third argument to the var-naming rule. Expecting extraBadPackageNames of type slice of strings, but %T", v) | ||||
| 				} | ||||
| 				for _, name := range extraBadPackageNames { | ||||
| 				for i, name := range extraBadPackageNames { | ||||
| 					if r.extraBadPackageNames == nil { | ||||
| 						r.extraBadPackageNames = map[string]struct{}{} | ||||
| 					} | ||||
| 					r.extraBadPackageNames[strings.ToLower(name.(string))] = struct{}{} | ||||
| 					n, ok := name.(string) | ||||
| 					if !ok { | ||||
| 						return fmt.Errorf("invalid third argument to the var-naming rule: expected element %d of extraBadPackageNames to be a string, but got %v(%T)", i, name, name) | ||||
| 					} | ||||
| 					r.extraBadPackageNames[strings.ToLower(n)] = struct{}{} | ||||
| 				} | ||||
| 			} | ||||
| 		} | ||||
|   | ||||
| @@ -117,6 +117,11 @@ func TestVarNamingRule_Configure(t *testing.T) { | ||||
| 			arguments: lint.Arguments{[]any{""}, []any{""}, []any{map[string]any{"extraBadPackageNames": []int{1}}}}, | ||||
| 			wantErr:   errors.New("invalid third argument to the var-naming rule. Expecting extraBadPackageNames of type slice of strings, but []int"), | ||||
| 		}, | ||||
| 		{ | ||||
| 			name:      "invalid third argument value type for extraBadPackageNames", | ||||
| 			arguments: lint.Arguments{[]any{""}, []any{""}, []any{map[string]any{"extraBadPackageNames": []any{"helpers", 5}}}}, | ||||
| 			wantErr:   errors.New("invalid third argument to the var-naming rule: expected element 1 of extraBadPackageNames to be a string, but got 5(int)"), | ||||
| 		}, | ||||
| 	} | ||||
|  | ||||
| 	for _, tt := range tests { | ||||
|   | ||||
		Reference in New Issue
	
	Block a user