Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/qawatake/nilnop
Linter: nilnop detects nil is passed to a function that does nothing for nil
https://github.com/qawatake/nilnop
go golang linter staticanalysis
Last synced: 25 days ago
JSON representation
Linter: nilnop detects nil is passed to a function that does nothing for nil
- Host: GitHub
- URL: https://github.com/qawatake/nilnop
- Owner: qawatake
- License: mit
- Created: 2023-11-10T11:11:28.000Z (about 1 year ago)
- Default Branch: main
- Last Pushed: 2023-11-11T04:12:42.000Z (about 1 year ago)
- Last Synced: 2024-10-29T12:56:10.483Z (2 months ago)
- Topics: go, golang, linter, staticanalysis
- Language: Go
- Homepage: https://pkg.go.dev/github.com/qawatake/nilnop
- Size: 37.1 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# nilnop
[![Go Reference](https://pkg.go.dev/badge/github.com/qawatake/nilnop.svg)](https://pkg.go.dev/github.com/qawatake/nilnop)
[![test](https://github.com/qawatake/nilnop/actions/workflows/test.yaml/badge.svg)](https://github.com/qawatake/nilnop/actions/workflows/test.yaml)Linter `nilnop` detects nil is passed to a function that does nothing for nil.
```go
func f() (err error) {
reportError(err) // <- nil is passed to reportError
err = errors.New("new error")
reportError(err) // ok because err is not nil
return err
}// reportError panics if err is not nil.
func reportError(err error) {
if err != nil {
panic(err)
}
}
```You can try an example by running `make run.example`.
## How to use
Build your `nilnop` binary by writing `main.go` like below.
```go
package mainimport (
"github.com/qawatake/nilnop"
"golang.org/x/tools/go/analysis/unitchecker"
)func main() {
unitchecker.Main(
nilnop.NewAnalyzer(
nilnop.Target{
PkgPath: "github.com/qawatake/nilnop/internal/example",
FuncName: "reportError",
ArgPos: 0,
},
),
)
}
```Then, run `go vet` with your `nilnop` binary.
```sh
go vet -vettool=/path/to/your/nilnop ./...
```