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
1 parent
77962e9
commit 58809c3
Showing
9 changed files
with
88 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,32 @@ | ||
package golinters | ||
|
||
import ( | ||
"fmt" | ||
"strings" | ||
|
||
"github.com/curioswitch/go-reassign" | ||
"golang.org/x/tools/go/analysis" | ||
|
||
"github.com/golangci/golangci-lint/pkg/config" | ||
"github.com/golangci/golangci-lint/pkg/golinters/goanalysis" | ||
) | ||
|
||
func NewReassign(settings *config.ReassignSettings) *goanalysis.Linter { | ||
a := reassign.NewAnalyzer() | ||
|
||
var cfg map[string]map[string]interface{} | ||
if settings != nil && len(settings.Patterns) > 0 { | ||
cfg = map[string]map[string]interface{}{ | ||
a.Name: { | ||
reassign.FlagPattern: fmt.Sprintf("^(%s)$", strings.Join(settings.Patterns, "|")), | ||
}, | ||
} | ||
} | ||
|
||
return goanalysis.NewLinter( | ||
a.Name, | ||
a.Doc, | ||
[]*analysis.Analyzer{a}, | ||
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,5 @@ | ||
linters-settings: | ||
reassign: | ||
patterns: | ||
- DefaultClient | ||
- DefaultTransport |
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,13 @@ | ||
//golangcitest:args -Ereassign | ||
package testdata | ||
|
||
import ( | ||
"io" | ||
"net/http" | ||
) | ||
|
||
func reassignTest() { | ||
http.DefaultClient = nil | ||
http.DefaultTransport = nil | ||
io.EOF = nil // want `reassigning variable EOF in other package io` | ||
} |
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,14 @@ | ||
//golangcitest:args -Ereassign | ||
//golangcitest:config_path testdata/configs/reassign_patterns.yml | ||
package testdata | ||
|
||
import ( | ||
"io" | ||
"net/http" | ||
) | ||
|
||
func reassignTestPatterns() { | ||
http.DefaultClient = nil // want `reassigning variable DefaultClient in other package http` | ||
http.DefaultTransport = nil // want `reassigning variable DefaultTransport in other package http` | ||
io.EOF = nil | ||
} |