mirror of
https://github.com/mgechev/revive.git
synced 2024-11-28 08:49:11 +02:00
af953e6189
* 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>
67 lines
1.4 KiB
Go
67 lines
1.4 KiB
Go
package test
|
|
|
|
import (
|
|
"flag"
|
|
"io/ioutil"
|
|
"path"
|
|
"regexp"
|
|
"testing"
|
|
|
|
"github.com/mgechev/revive/lint"
|
|
"github.com/mgechev/revive/rule"
|
|
)
|
|
|
|
var lintMatch = flag.String("lint.match", "", "restrict fixtures matches to this pattern")
|
|
|
|
var rules = []lint.Rule{
|
|
&rule.VarDeclarationsRule{},
|
|
&rule.PackageCommentsRule{},
|
|
&rule.DotImportsRule{},
|
|
&rule.BlankImportsRule{},
|
|
&rule.ExportedRule{},
|
|
&rule.VarNamingRule{},
|
|
&rule.IndentErrorFlowRule{},
|
|
&rule.RangeRule{},
|
|
&rule.ErrorfRule{},
|
|
&rule.ErrorNamingRule{},
|
|
&rule.ErrorStringsRule{},
|
|
&rule.ReceiverNamingRule{},
|
|
&rule.IncrementDecrementRule{},
|
|
&rule.ErrorReturnRule{},
|
|
&rule.UnexportedReturnRule{},
|
|
&rule.TimeNamingRule{},
|
|
&rule.ContextKeysType{},
|
|
}
|
|
|
|
func TestAll(t *testing.T) {
|
|
baseDir := "../testdata/golint/"
|
|
|
|
rx, err := regexp.Compile(*lintMatch)
|
|
if err != nil {
|
|
t.Fatalf("Bad -lint.match value %q: %v", *lintMatch, err)
|
|
}
|
|
|
|
fis, err := ioutil.ReadDir(baseDir)
|
|
if err != nil {
|
|
t.Fatalf("ioutil.ReadDir: %v", err)
|
|
}
|
|
if len(fis) == 0 {
|
|
t.Fatalf("no files in %v", baseDir)
|
|
}
|
|
for _, fi := range fis {
|
|
if !rx.MatchString(fi.Name()) {
|
|
continue
|
|
}
|
|
t.Run(fi.Name(), func(t *testing.T) {
|
|
src, err := ioutil.ReadFile(path.Join(baseDir, fi.Name()))
|
|
if err != nil {
|
|
t.Fatalf("Failed reading %s: %v", fi.Name(), err)
|
|
}
|
|
|
|
if err := assertFailures(t, baseDir, fi, src, rules, map[string]lint.RuleConfig{}); err != nil {
|
|
t.Errorf("Linting %s: %v", fi.Name(), err)
|
|
}
|
|
})
|
|
}
|
|
}
|