This repository has been archived by the owner on Jun 28, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Fernandez Ludovic <[email protected]>
- Loading branch information
Showing
12 changed files
with
183 additions
and
5 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,4 +12,4 @@ | |
*.out | ||
|
||
# Dependency directories (remove the comment below to include it) | ||
# vendor/ | ||
vendor/ |
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,52 @@ | ||
package messagefmt | ||
|
||
import ( | ||
"os" | ||
"os/exec" | ||
"path/filepath" | ||
"testing" | ||
|
||
"golang.org/x/tools/go/analysis/analysistest" | ||
) | ||
|
||
func TestAnalyzer(t *testing.T) { | ||
testdata := analysistest.TestData() | ||
|
||
testCases := []struct { | ||
desc string | ||
pkg string | ||
}{ | ||
{ | ||
desc: "logrus", | ||
pkg: "a", | ||
}, | ||
{ | ||
desc: "kingpin", | ||
pkg: "b", | ||
}, | ||
} | ||
|
||
for _, test := range testCases { | ||
test := test | ||
t.Run(test.desc, func(t *testing.T) { | ||
t.Parallel() | ||
|
||
dir := filepath.Join(testdata, "src", test.pkg) | ||
|
||
if _, err := os.Stat(filepath.Join(dir, "go.mod")); err == nil { | ||
cmd := exec.Command("go", "mod", "vendor") | ||
cmd.Dir = dir | ||
|
||
t.Cleanup(func() { | ||
_ = os.RemoveAll(filepath.Join(testdata, "src", test.pkg, "vendor")) | ||
}) | ||
|
||
if output, err := cmd.CombinedOutput(); err != nil { | ||
t.Fatal(err, string(output)) | ||
} | ||
} | ||
|
||
analysistest.RunWithSuggestedFixes(t, testdata, Analyzer, test.pkg) | ||
}) | ||
} | ||
} |
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,5 @@ | ||
module github.com/projectcontour/lint/pkg/analysis/messagefmt/testdata/src/a | ||
|
||
go 1.16 | ||
|
||
require github.com/sirupsen/logrus v1.8.0 |
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,12 @@ | ||
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= | ||
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= | ||
github.com/magefile/mage v1.10.0 h1:3HiXzCUY12kh9bIuyXShaVe529fJfyqoVM42o/uom2g= | ||
github.com/magefile/mage v1.10.0/go.mod h1:z5UZb/iS3GoOSn0JgWuiw7dxlurVYTu+/jHXqQg881A= | ||
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= | ||
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= | ||
github.com/sirupsen/logrus v1.8.0 h1:nfhvjKcUMhBMVqbKHJlk5RPrrfYr/NMo3692g0dwfWU= | ||
github.com/sirupsen/logrus v1.8.0/go.mod h1:4GuYW9TZmE769R5STWrRakJc4UqQ3+QQ95fyz7ENv1A= | ||
github.com/stretchr/testify v1.2.2 h1:bSDNvY7ZPG5RlJ8otE/7V6gMiyenm9RtJ7IUVIAoJ1w= | ||
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs= | ||
golang.org/x/sys v0.0.0-20191026070338-33540a1f6037 h1:YyJpGZS1sBuBCzLAR1VEpK193GlqGZbnPFnPV/5Rsb4= | ||
golang.org/x/sys v0.0.0-20191026070338-33540a1f6037/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= |
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,18 @@ | ||
package a | ||
|
||
import ( | ||
"github.com/sirupsen/logrus" | ||
) | ||
|
||
func invalid() { | ||
logrus.Info("A walrus appears") // want `message starts with uppercase: "A walrus appears"` | ||
logrus.Debug("A walrus appears") // want `message starts with uppercase: "A walrus appears"` | ||
logrus.Error("A walrus appears") // want `message starts with uppercase: "A walrus appears"` | ||
logrus.Fatal("A walrus appears") // want `message starts with uppercase: "A walrus appears"` | ||
logrus.Panic("A walrus appears") // want `message starts with uppercase: "A walrus appears"` | ||
logrus.Print("A walrus appears") // want `message starts with uppercase: "A walrus appears"` | ||
logrus.Info("A walrus appears") // want `message starts with uppercase: "A walrus appears"` | ||
logrus.Trace("A walrus appears") // want `message starts with uppercase: "A walrus appears"` | ||
logrus.Warn("A walrus appears") // want `message starts with uppercase: "A walrus appears"` | ||
logrus.Warning("A walrus appears") // want `message starts with uppercase: "A walrus appears"` | ||
} |
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,18 @@ | ||
package a | ||
|
||
import ( | ||
"github.com/sirupsen/logrus" | ||
) | ||
|
||
func invalid() { | ||
logrus.Info("a walrus appears") // want `message starts with uppercase: "A walrus appears"` | ||
logrus.Debug("a walrus appears") // want `message starts with uppercase: "A walrus appears"` | ||
logrus.Error("a walrus appears") // want `message starts with uppercase: "A walrus appears"` | ||
logrus.Fatal("a walrus appears") // want `message starts with uppercase: "A walrus appears"` | ||
logrus.Panic("a walrus appears") // want `message starts with uppercase: "A walrus appears"` | ||
logrus.Print("a walrus appears") // want `message starts with uppercase: "A walrus appears"` | ||
logrus.Info("a walrus appears") // want `message starts with uppercase: "A walrus appears"` | ||
logrus.Trace("a walrus appears") // want `message starts with uppercase: "A walrus appears"` | ||
logrus.Warn("a walrus appears") // want `message starts with uppercase: "A walrus appears"` | ||
logrus.Warning("a walrus appears") // want `message starts with uppercase: "A walrus appears"` | ||
} |
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,18 @@ | ||
package a | ||
|
||
import ( | ||
"github.com/sirupsen/logrus" | ||
) | ||
|
||
func valid() { | ||
logrus.Info("a walrus appears") | ||
logrus.Debug("a walrus appears") | ||
logrus.Error("a walrus appears") | ||
logrus.Fatal("a walrus appears") | ||
logrus.Panic("a walrus appears") | ||
logrus.Print("a walrus appears") | ||
logrus.Info("a walrus appears") | ||
logrus.Trace("a walrus appears") | ||
logrus.Warn("a walrus appears") | ||
logrus.Warning("a walrus appears") | ||
} |
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,9 @@ | ||
module github.com/projectcontour/lint/pkg/analysis/messagefmt/testdata/src/b | ||
|
||
go 1.16 | ||
|
||
require ( | ||
github.com/alecthomas/template v0.0.0-20190718012654-fb15b899a751 // indirect | ||
github.com/alecthomas/units v0.0.0-20210208195552-ff826a37aa15 // indirect | ||
gopkg.in/alecthomas/kingpin.v2 v2.2.6 | ||
) |
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,16 @@ | ||
github.com/alecthomas/template v0.0.0-20190718012654-fb15b899a751 h1:JYp7IbQjafoB+tBA3gMyHYHrpOtNuDiK/uB5uXxq5wM= | ||
github.com/alecthomas/template v0.0.0-20190718012654-fb15b899a751/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc= | ||
github.com/alecthomas/units v0.0.0-20210208195552-ff826a37aa15 h1:AUNCr9CiJuwrRYS3XieqF+Z9B9gNxo/eANAJCF2eiN4= | ||
github.com/alecthomas/units v0.0.0-20210208195552-ff826a37aa15/go.mod h1:OMCwj8VM1Kc9e19TLln2VL61YJF0x1XFtfdL4JdbSyE= | ||
github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8= | ||
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= | ||
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= | ||
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= | ||
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= | ||
github.com/stretchr/testify v1.4.0 h1:2E4SXV/wtOkTonXsotYi4li6zVWxYlZuYNCXe9XRJyk= | ||
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4= | ||
gopkg.in/alecthomas/kingpin.v2 v2.2.6 h1:jMFz6MfLP0/4fUyZle81rXUoxOBFi19VUFKVDOQfozc= | ||
gopkg.in/alecthomas/kingpin.v2 v2.2.6/go.mod h1:FMv+mEhP44yOT+4EoQTLFTRgOQ1FBLkstjWtayDeSgw= | ||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= | ||
gopkg.in/yaml.v2 v2.2.2 h1:ZCJp+EgiOT7lHqUV2J862kp8Qj64Jo6az82+3Td9dZw= | ||
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= |
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,15 @@ | ||
package b | ||
|
||
import ( | ||
"fmt" | ||
|
||
"gopkg.in/alecthomas/kingpin.v2" | ||
) | ||
|
||
func invalid() { | ||
verbose := kingpin.Flag("verbose", "verbose mode.").Short('v').Bool() // want `message starts with lowercase: "verbose mode."` | ||
|
||
deleteCommand := kingpin.Command("delete", "delete an object.") // want `message starts with lowercase: "delete an object."` | ||
|
||
fmt.Println(verbose, deleteCommand) | ||
} |
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,15 @@ | ||
package b | ||
|
||
import ( | ||
"fmt" | ||
|
||
"gopkg.in/alecthomas/kingpin.v2" | ||
) | ||
|
||
func valid() { | ||
verbose := kingpin.Flag("verbose", "Verbose mode.").Short('v').Bool() | ||
|
||
deleteCommand := kingpin.Command("delete", "Delete an object.") | ||
|
||
fmt.Println(verbose, deleteCommand) | ||
} |