Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/qawatake/notany
Linter: notany limits possible types for arguments of any type.
https://github.com/qawatake/notany
go golang linter staticanalysis
Last synced: 7 days ago
JSON representation
Linter: notany limits possible types for arguments of any type.
- Host: GitHub
- URL: https://github.com/qawatake/notany
- Owner: qawatake
- License: mit
- Created: 2023-10-21T10:24:40.000Z (about 1 year ago)
- Default Branch: main
- Last Pushed: 2023-11-09T11:58:56.000Z (about 1 year ago)
- Last Synced: 2024-10-29T12:56:34.509Z (about 2 months ago)
- Topics: go, golang, linter, staticanalysis
- Language: Go
- Homepage: https://pkg.go.dev/github.com/qawatake/notany
- Size: 85 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# notany
[![Go Reference](https://pkg.go.dev/badge/github.com/qawatake/notany.svg)](https://pkg.go.dev/github.com/qawatake/notany)
[![test](https://github.com/qawatake/notany/actions/workflows/test.yaml/badge.svg)](https://github.com/qawatake/notany/actions/workflows/test.yaml)
[![codecov](https://codecov.io/gh/qawatake/notany/graph/badge.svg?token=mjocIOzSRm)](https://codecov.io/gh/qawatake/notany)Linter `notany` limits possible types for arguments of any type.
```go
// arg must be string, fmt.Stringer, or AllowedType.
func FuncWithAnyTypeArg(arg any) {
// ...
}type AllowedType struct{}
``````go
func main() {
pkg.FuncWithAnyTypeArg("ok") // ok
pkg.FuncWithAnyTypeArg(time.Now()) // ok because time.Time implements fmt.Stringer
pkg.FuncWithAnyTypeArg(AllowedType{}) // ok
pkg.FuncWithAnyTypeArg(1.0) // <- float64 is not allowed
pkg.FuncWithAnyTypeArg(true) // <- bool is not allowed
}
```## How to use
Build your `notany` binary by writing `main.go` like below.
```go
package mainimport (
"github.com/qawatake/notany"
"golang.org/x/tools/go/analysis/unitchecker"
)func main() {
unitchecker.Main(
notany.NewAnalyzer(
notany.Target{
PkgPath: "pkg/in/which/target/func/is/defined",
FuncName: "FuncWithAnyTypeArg",
ArgPos: 1,
Allowed: []notany.Allowed{
{
PkgPath: "",
TypeName: "int",
},
{
PkgPath: "fmt",
TypeName: "Stringer",
},
{
PkgPath: "pkg/in/which/allowed/type/is/defined",
TypeName: "AllowedType",
},
},
},
),
)
}
```Then, run `go vet` with your `notany` binary.
```sh
go vet -vettool=/path/to/your/notany ./...
```