-
Notifications
You must be signed in to change notification settings - Fork 285
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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>
- Loading branch information
Showing
6 changed files
with
124 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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", | ||
}, | ||
}, | ||
}, | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters