Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/itsamirhn/whyvarscope
Golang variable scope linter
https://github.com/itsamirhn/whyvarscope
Last synced: 4 months ago
JSON representation
Golang variable scope linter
- Host: GitHub
- URL: https://github.com/itsamirhn/whyvarscope
- Owner: itsamirhn
- License: mit
- Created: 2024-06-03T14:13:50.000Z (8 months ago)
- Default Branch: main
- Last Pushed: 2024-08-15T08:32:45.000Z (6 months ago)
- Last Synced: 2024-08-15T10:08:20.173Z (6 months ago)
- Language: Go
- Homepage:
- Size: 32.2 KB
- Stars: 3
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# WhyVarScope
A go linter to check if you can avoid using variable scope inside if statements.
## Example
```go
package mainfunc zero() int {
return 0
}func main() {
if o := zero(); o > 0 { // Why to use o here?
println("o is greater than 0")
}
}
```## Install
go install github.com/itsamirhn/whyvarscope/cmd/whyvarscope@latest
# Usage
whyvarscope uses [`singlechecker`](https://pkg.go.dev/golang.org/x/tools/go/analysis/singlechecker) package to run:```
whyvarscope: Check for unnecessary variable scopeUsage: whyvarscope [-flag] [package]
Flags:
-V print version and exit
-all
no effect (deprecated)
-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
-source
no effect (deprecated)
-tags string
no effect (deprecated)
-test
indicates whether test files should be analyzed, too (default true)
-trace string
write trace log to this file
-v no effect (deprecated)
```