https://github.com/vitrun/sanus
A collection of Go Vet-style linters to make programs sound and healthy
https://github.com/vitrun/sanus
analysis go golang vet
Last synced: 5 months ago
JSON representation
A collection of Go Vet-style linters to make programs sound and healthy
- Host: GitHub
- URL: https://github.com/vitrun/sanus
- Owner: vitrun
- License: mit
- Created: 2020-08-06T15:23:42.000Z (almost 6 years ago)
- Default Branch: master
- Last Pushed: 2020-08-07T07:22:04.000Z (almost 6 years ago)
- Last Synced: 2024-06-20T05:20:44.014Z (almost 2 years ago)
- Topics: analysis, go, golang, vet
- Language: Go
- Homepage:
- Size: 6.84 KB
- Stars: 2
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# SANUS
[](https://github.com/vitrun/sanus/actions/)
[](https://goreportcard.com/report/github.com/vitrun/sanus)
A collection of Go Vet-style linters to make program sanus ([ˈsaː.nus], sound in body, healthy; sound in mind, sane).
- panicable. Check for possible panics that would result in program exit.
## Panicable
`Panicable` finds goroutines that have no `defer` or `recover` statements. Once they panic, not necessarily though, the whole program is endangered.
These patterns while be identified:
**pattern 1**
```go
func main() {
go func() { // no defer
panic("I'm paniced")
}()
}
```
**pattern 2**
```go
func a() {
go func() { // no recover
defer func() {
}()
panic("doomed")
}()
}
```
Methods are supported:
```go
type S struct{}
func (s *S) foo() {
go func() { // no defer
println("foo")
}()
}
```
## Install
Specify the cmd to install, `panicable` for example:
```
go get github.com/vitrun/sanus/cmd/panicable
```
This will install `panicable` to `$GOPATH/bin`, so make sure that it is included in your `$PATH` environment variable.
## Usage
Run cmd on current package like this:
```
$ panicable .
```
Or supply multiple packages, separated by spaces:
```
$ panicable example/cmd example/util strings
```
To check a package and, recursively, all its imports, use `./...`:
```
$ panicable net/...
```
all cmds in sanus accept the same flags as `go vet`:
```
Flags:
-V print version and exit
-c int
display offending line with this many lines of context (default -1)
-cpuprofile string
write CPU profile to this file
-debug string
debug flags, any subset of "fpstv"
-fix
apply all suggested fixes
-flags
print analyzer flags in JSON
-json
emit JSON output
-memprofile string
write memory profile to this file
-trace string
write trace log to this file
```
## Development
To get the source code and compile/test specific cmd, run this:
```
$ git clone https://github.com/vitrun/sanus
$ cd sanus/panicable
$ go build -o panicable ./cmd/panicable
$ go test -v
```
`sanus` uses the testing infrastructure from `golang.org/x/tools/go/analysis/analysistest`. To add a test case, add new package in related `testdata/src`.
In the test case source files, add annotation comments to the lines that should be reported (or not). The comments must
look like this:
```
func main() {
go func() { // want "no defer"
panic("I'm paniced")
}()
}
```
Annotations that indicate a line that should be reported must begin with a `want` followed by the desired message .
Since `sanus` is built upon the Go Vet standard infrastructure, you can import the passes into your own Go Vet-based linter.