-
-
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
9 changed files
with
118 additions
and
6 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,26 @@ | ||
package golinters | ||
|
||
import ( | ||
"github.com/nishanths/predeclared/passes/predeclared" | ||
"golang.org/x/tools/go/analysis" | ||
|
||
"github.com/golangci/golangci-lint/pkg/config" | ||
"github.com/golangci/golangci-lint/pkg/golinters/goanalysis" | ||
) | ||
|
||
func NewPredeclared(settings *config.PredeclaredSettings) *goanalysis.Linter { | ||
a := predeclared.Analyzer | ||
|
||
var cfg map[string]map[string]interface{} | ||
if settings != nil { | ||
cfg = map[string]map[string]interface{}{ | ||
a.Name: { | ||
predeclared.IgnoreFlag: settings.Ignore, | ||
predeclared.QualifiedFlag: settings.Qualified, | ||
}, | ||
} | ||
} | ||
|
||
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,4 @@ | ||
linters-settings: | ||
predeclared: | ||
ignore: "real,recover" | ||
q: 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,27 @@ | ||
//args: -Epredeclared | ||
package testdata | ||
|
||
func hello() { | ||
var real int // ERROR "variable real has same name as predeclared identifier" | ||
a := A{} | ||
copy := Clone(a) // ERROR "variable copy has same name as predeclared identifier" | ||
|
||
// suppress any "declared but not used" errors | ||
_ = real | ||
_ = a | ||
_ = copy | ||
} | ||
|
||
type A struct { | ||
true bool | ||
foo int | ||
} | ||
|
||
func Clone(a A) A { | ||
return A{ | ||
true: a.true, | ||
foo: a.foo, | ||
} | ||
} | ||
|
||
func recover() {} // ERROR "function recover has same name as predeclared identifier" |
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,28 @@ | ||
//args: -Epredeclared | ||
//config_path: testdata/configs/predeclared.yml | ||
package testdata | ||
|
||
func hello() { | ||
var real int | ||
a := A{} | ||
copy := Clone(a) // ERROR "variable copy has same name as predeclared identifier" | ||
|
||
// suppress any "declared but not used" errors | ||
_ = real | ||
_ = a | ||
_ = copy | ||
} | ||
|
||
type A struct { | ||
true bool // ERROR "field true has same name as predeclared identifier" | ||
foo int | ||
} | ||
|
||
func Clone(a A) A { | ||
return A{ | ||
true: a.true, | ||
foo: a.foo, | ||
} | ||
} | ||
|
||
func recover() {} |