-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
267 additions
and
0 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,33 @@ | ||
package golinters | ||
|
||
import ( | ||
"github.com/sivchari/tenv" | ||
"golang.org/x/tools/go/analysis" | ||
|
||
"github.com/golangci/golangci-lint/pkg/config" | ||
"github.com/golangci/golangci-lint/pkg/golinters/goanalysis" | ||
) | ||
|
||
func NewTenv(settings *config.TenvSettings) *goanalysis.Linter { | ||
a := tenv.Analyzer | ||
|
||
analyzers := []*analysis.Analyzer{ | ||
a, | ||
} | ||
|
||
var cfg map[string]map[string]interface{} | ||
if settings != nil { | ||
cfg = map[string]map[string]interface{}{ | ||
a.Name: { | ||
tenv.A: settings.All, | ||
}, | ||
} | ||
} | ||
|
||
return goanalysis.NewLinter( | ||
a.Name, | ||
a.Doc, | ||
analyzers, | ||
cfg, | ||
).WithLoadMode(goanalysis.LoadModeSyntax) | ||
} |
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,3 @@ | ||
linters-settings: | ||
tenv: | ||
all: true |
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,48 @@ | ||
// args: -Etenv | ||
// config_path: testdata/configs/tenv_all.yml | ||
package testdata | ||
|
||
import ( | ||
"os" | ||
"testing" | ||
) | ||
|
||
var ( | ||
e = os.Setenv("a", "b") // never seen | ||
) | ||
|
||
func setup() { | ||
os.Setenv("a", "b") // never seen | ||
err := os.Setenv("a", "b") // never seen | ||
_ = err | ||
if err := os.Setenv("a", "b"); err != nil { // never seen | ||
_ = err | ||
} | ||
} | ||
|
||
func TestF(t *testing.T) { | ||
os.Setenv("a", "b") // ERROR "os\\.Setenv\\(\\) can be replaced by `t\\.Setenv\\(\\)` in TestF" | ||
err := os.Setenv("a", "b") // ERROR "os\\.Setenv\\(\\) can be replaced by `t\\.Setenv\\(\\)` in TestF" | ||
_ = err | ||
if err := os.Setenv("a", "b"); err != nil { // ERROR "os\\.Setenv\\(\\) can be replaced by `t\\.Setenv\\(\\)` in TestF" | ||
_ = err | ||
} | ||
} | ||
|
||
func BenchmarkF(b *testing.B) { | ||
os.Setenv("a", "b") // ERROR "os\\.Setenv\\(\\) can be replaced by `b\\.Setenv\\(\\)` in BenchmarkF" | ||
err := os.Setenv("a", "b") // ERROR "os\\.Setenv\\(\\) can be replaced by `b\\.Setenv\\(\\)` in BenchmarkF" | ||
_ = err | ||
if err := os.Setenv("a", "b"); err != nil { // ERROR "os\\.Setenv\\(\\) can be replaced by `b\\.Setenv\\(\\)` in BenchmarkF" | ||
_ = err | ||
} | ||
} | ||
|
||
func testTB(tb testing.TB) { | ||
os.Setenv("a", "b") // ERROR "os\\.Setenv\\(\\) can be replaced by `tb\\.Setenv\\(\\)` in testTB" | ||
err := os.Setenv("a", "b") // ERROR "os\\.Setenv\\(\\) can be replaced by `tb\\.Setenv\\(\\)` in testTB" | ||
_ = err | ||
if err := os.Setenv("a", "b"); err != nil { // ERROR "os\\.Setenv\\(\\) can be replaced by `tb\\.Setenv\\(\\)` in testTB" | ||
_ = err | ||
} | ||
} |
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,48 @@ | ||
// args: -Etenv | ||
// config_path: testdata/configs/tenv_all.yml | ||
package testdata | ||
|
||
import ( | ||
"os" | ||
"testing" | ||
) | ||
|
||
var ( | ||
e = os.Setenv("a", "b") // never seen | ||
) | ||
|
||
func setup() { | ||
os.Setenv("a", "b") // never seen | ||
err := os.Setenv("a", "b") // never seen | ||
_ = err | ||
if err := os.Setenv("a", "b"); err != nil { // never seen | ||
_ = err | ||
} | ||
} | ||
|
||
func TestF(t *testing.T) { | ||
os.Setenv("a", "b") // ERROR "os\\.Setenv\\(\\) can be replaced by `t\\.Setenv\\(\\)` in TestF" | ||
err := os.Setenv("a", "b") // ERROR "os\\.Setenv\\(\\) can be replaced by `t\\.Setenv\\(\\)` in TestF" | ||
_ = err | ||
if err := os.Setenv("a", "b"); err != nil { // ERROR "os\\.Setenv\\(\\) can be replaced by `t\\.Setenv\\(\\)` in TestF" | ||
_ = err | ||
} | ||
} | ||
|
||
func BenchmarkF(b *testing.B) { | ||
os.Setenv("a", "b") // ERROR "os\\.Setenv\\(\\) can be replaced by `b\\.Setenv\\(\\)` in BenchmarkF" | ||
err := os.Setenv("a", "b") // ERROR "os\\.Setenv\\(\\) can be replaced by `b\\.Setenv\\(\\)` in BenchmarkF" | ||
_ = err | ||
if err := os.Setenv("a", "b"); err != nil { // ERROR "os\\.Setenv\\(\\) can be replaced by `b\\.Setenv\\(\\)` in BenchmarkF" | ||
_ = err | ||
} | ||
} | ||
|
||
func testTB(tb testing.TB) { | ||
os.Setenv("a", "b") // ERROR "os\\.Setenv\\(\\) can be replaced by `tb\\.Setenv\\(\\)` in testTB" | ||
err := os.Setenv("a", "b") // ERROR "os\\.Setenv\\(\\) can be replaced by `tb\\.Setenv\\(\\)` in testTB" | ||
_ = err | ||
if err := os.Setenv("a", "b"); err != nil { // ERROR "os\\.Setenv\\(\\) can be replaced by `tb\\.Setenv\\(\\)` in testTB" | ||
_ = err | ||
} | ||
} |
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,48 @@ | ||
// args: -Etenv | ||
// config_path: testdata/configs/tenv_all.yml | ||
package testdata | ||
|
||
import ( | ||
"os" | ||
"testing" | ||
) | ||
|
||
var ( | ||
e = os.Setenv("a", "b") // never seen | ||
) | ||
|
||
func setup() { | ||
os.Setenv("a", "b") // ERROR "os\\.Setenv\\(\\) can be replaced by `testing\\.Setenv\\(\\)` in setup" | ||
err := os.Setenv("a", "b") // ERROR "os\\.Setenv\\(\\) can be replaced by `testing\\.Setenv\\(\\)` in setup" | ||
_ = err | ||
if err := os.Setenv("a", "b"); err != nil { // ERROR "os\\.Setenv\\(\\) can be replaced by `testing\\.Setenv\\(\\)` in setup" | ||
_ = err | ||
} | ||
} | ||
|
||
func TestF(t *testing.T) { | ||
os.Setenv("a", "b") // ERROR "os\\.Setenv\\(\\) can be replaced by `t\\.Setenv\\(\\)` in TestF" | ||
err := os.Setenv("a", "b") // ERROR "os\\.Setenv\\(\\) can be replaced by `t\\.Setenv\\(\\)` in TestF" | ||
_ = err | ||
if err := os.Setenv("a", "b"); err != nil { // ERROR "os\\.Setenv\\(\\) can be replaced by `t\\.Setenv\\(\\)` in TestF" | ||
_ = err | ||
} | ||
} | ||
|
||
func BenchmarkF(b *testing.B) { | ||
os.Setenv("a", "b") // ERROR "os\\.Setenv\\(\\) can be replaced by `b\\.Setenv\\(\\)` in BenchmarkF" | ||
err := os.Setenv("a", "b") // ERROR "os\\.Setenv\\(\\) can be replaced by `b\\.Setenv\\(\\)` in BenchmarkF" | ||
_ = err | ||
if err := os.Setenv("a", "b"); err != nil { // ERROR "os\\.Setenv\\(\\) can be replaced by `b\\.Setenv\\(\\)` in BenchmarkF" | ||
_ = err | ||
} | ||
} | ||
|
||
func testTB(tb testing.TB) { | ||
os.Setenv("a", "b") // ERROR "os\\.Setenv\\(\\) can be replaced by `tb\\.Setenv\\(\\)` in testTB" | ||
err := os.Setenv("a", "b") // ERROR "os\\.Setenv\\(\\) can be replaced by `tb\\.Setenv\\(\\)` in testTB" | ||
_ = err | ||
if err := os.Setenv("a", "b"); err != nil { // ERROR "os\\.Setenv\\(\\) can be replaced by `tb\\.Setenv\\(\\)` in testTB" | ||
_ = err | ||
} | ||
} |
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,47 @@ | ||
// args: -Etenv | ||
package testdata | ||
|
||
import ( | ||
"os" | ||
"testing" | ||
) | ||
|
||
var ( | ||
e = os.Setenv("a", "b") // never seen | ||
) | ||
|
||
func setup() { | ||
os.Setenv("a", "b") // OK | ||
err := os.Setenv("a", "b") // OK | ||
_ = err | ||
if err := os.Setenv("a", "b"); err != nil { // OK | ||
_ = err | ||
} | ||
} | ||
|
||
func TestF(t *testing.T) { | ||
os.Setenv("a", "b") // ERROR "os\\.Setenv\\(\\) can be replaced by `t\\.Setenv\\(\\)` in TestF" | ||
err := os.Setenv("a", "b") // ERROR "os\\.Setenv\\(\\) can be replaced by `t\\.Setenv\\(\\)` in TestF" | ||
_ = err | ||
if err := os.Setenv("a", "b"); err != nil { // ERROR "os\\.Setenv\\(\\) can be replaced by `t\\.Setenv\\(\\)` in TestF" | ||
_ = err | ||
} | ||
} | ||
|
||
func BenchmarkF(b *testing.B) { | ||
os.Setenv("a", "b") // ERROR "os\\.Setenv\\(\\) can be replaced by `b\\.Setenv\\(\\)` in BenchmarkF" | ||
err := os.Setenv("a", "b") // ERROR "os\\.Setenv\\(\\) can be replaced by `b\\.Setenv\\(\\)` in BenchmarkF" | ||
_ = err | ||
if err := os.Setenv("a", "b"); err != nil { // ERROR "os\\.Setenv\\(\\) can be replaced by `b\\.Setenv\\(\\)` in BenchmarkF" | ||
_ = err | ||
} | ||
} | ||
|
||
func testTB(tb testing.TB) { | ||
os.Setenv("a", "b") // ERROR "os\\.Setenv\\(\\) can be replaced by `tb\\.Setenv\\(\\)` in testTB" | ||
err := os.Setenv("a", "b") // ERROR "os\\.Setenv\\(\\) can be replaced by `tb\\.Setenv\\(\\)` in testTB" | ||
_ = err | ||
if err := os.Setenv("a", "b"); err != nil { // ERROR "os\\.Setenv\\(\\) can be replaced by `tb\\.Setenv\\(\\)` in testTB" | ||
_ = err | ||
} | ||
} |