mirror of
https://github.com/mgechev/revive.git
synced 2025-12-07 23:02:44 +02:00
Allow whitelist for the context parameter check (#616)
* Allow a whitelist for the context parameter check This allows users to configure a set of types that may appear before `context.Context`. Notably, I think this rule is useful for allowing the `*testing.T` type to come before `context.Context`, though there may be other uses (such as putting a tracer before it, etc). See #605 for a little more context on this. Fixes #605 * Save a level of indentation in context-as-arg validation We can unindent if we make the above check more specific * refactoring taking into account chavacava's review Co-authored-by: chavacava <salvadorcavadini+github@gmail.com>
This commit is contained in:
19
test/context-as-argument_test.go
Normal file
19
test/context-as-argument_test.go
Normal file
@@ -0,0 +1,19 @@
|
||||
package test
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/mgechev/revive/lint"
|
||||
"github.com/mgechev/revive/rule"
|
||||
)
|
||||
|
||||
func TestContextAsArgument(t *testing.T) {
|
||||
testRule(t, "context-as-argument", &rule.ContextAsArgumentRule{}, &lint.RuleConfig{
|
||||
Arguments: []interface{}{
|
||||
map[string]interface{}{
|
||||
"allowTypesBefore": "AllowedBeforeType,AllowedBeforeStruct,*AllowedBeforePtrStruct,*testing.T",
|
||||
},
|
||||
},
|
||||
},
|
||||
)
|
||||
}
|
||||
Reference in New Issue
Block a user