[CI] Add more checks (#43)
This commit is contained in:
15
vendor/honnef.co/go/tools/cmd/gosimple/README.md
vendored
Normal file
15
vendor/honnef.co/go/tools/cmd/gosimple/README.md
vendored
Normal file
@ -0,0 +1,15 @@
|
||||
# gosimple
|
||||
|
||||
_gosimple_ is a linter for Go source code that specialises on
|
||||
simplifying code.
|
||||
|
||||
## Installation
|
||||
|
||||
Gosimple requires Go 1.6 or later.
|
||||
|
||||
go get honnef.co/go/tools/cmd/gosimple
|
||||
|
||||
## Documentation
|
||||
|
||||
Detailed documentation can be found on
|
||||
[staticcheck.io](https://staticcheck.io/docs/gosimple).
|
21
vendor/honnef.co/go/tools/cmd/gosimple/gosimple.go
vendored
Normal file
21
vendor/honnef.co/go/tools/cmd/gosimple/gosimple.go
vendored
Normal file
@ -0,0 +1,21 @@
|
||||
// gosimple detects code that could be rewritten in a simpler way.
|
||||
package main // import "honnef.co/go/tools/cmd/gosimple"
|
||||
import (
|
||||
"os"
|
||||
|
||||
"honnef.co/go/tools/lint/lintutil"
|
||||
"honnef.co/go/tools/simple"
|
||||
)
|
||||
|
||||
func main() {
|
||||
fs := lintutil.FlagSet("gosimple")
|
||||
gen := fs.Bool("generated", false, "Check generated code")
|
||||
fs.Parse(os.Args[1:])
|
||||
c := simple.NewChecker()
|
||||
c.CheckGenerated = *gen
|
||||
cfg := lintutil.CheckerConfig{
|
||||
Checker: c,
|
||||
ExitNonZero: true,
|
||||
}
|
||||
lintutil.ProcessFlagSet([]lintutil.CheckerConfig{cfg}, fs)
|
||||
}
|
131
vendor/honnef.co/go/tools/cmd/unused/README.md
vendored
Normal file
131
vendor/honnef.co/go/tools/cmd/unused/README.md
vendored
Normal file
@ -0,0 +1,131 @@
|
||||
# unused
|
||||
|
||||
_unused_ checks Go code for unused constants, variables, functions and
|
||||
types.
|
||||
|
||||
## Install
|
||||
|
||||
go get honnef.co/go/tools/cmd/unused
|
||||
|
||||
## Usage
|
||||
|
||||
unused -help
|
||||
|
||||
## Usage Tips
|
||||
|
||||
- When running _unused_ on multiple packages, it will first try to
|
||||
check them all at once, because that's faster. If any of the
|
||||
packages don't compile, however, _unused_ will check each package
|
||||
individually.
|
||||
|
||||
The first step can, depending on the number of packages, use a lot
|
||||
of memory. For the entire standard library, it uses roughly 800 MB.
|
||||
For a GOPATH with thousands of packages, it can quickly use several
|
||||
gigabytes. If that is an issue, consider using something like this
|
||||
instead:
|
||||
|
||||
```
|
||||
for pkg in $(go list your_selection); do unused "$pkg"; done
|
||||
```
|
||||
|
||||
This will effectively skip the first step and always check every
|
||||
package individually.
|
||||
|
||||
## What counts as used/unused?
|
||||
|
||||
_unused_ checks for unused constants, functions, types and optionally
|
||||
struct fields. They will be considered used or unused under the
|
||||
following conditions:
|
||||
|
||||
- Unexported package-level objects will be reported as unused if there
|
||||
are no explicit references to them.
|
||||
|
||||
- Unexported methods will be reported as unused if there are no
|
||||
explicit references to them and if they don't implement any
|
||||
interfaces.
|
||||
|
||||
- The `main` function is considered as used if it's in the `main`
|
||||
package.
|
||||
|
||||
- `init` functions are always considered as used.
|
||||
|
||||
- Exported objects in function scope are treated like unexported
|
||||
objects.
|
||||
|
||||
- Exported functions in tests are treated like unexported functions,
|
||||
unless they're test, benchmark or example functions.
|
||||
|
||||
- Struct fields will be considered as unused if there are no explicit
|
||||
references to them. Unkeyed composite literals with >=1 elements
|
||||
mark all fields of the struct as used.
|
||||
|
||||
- Neither the checks for methods nor for struct fields are aware of
|
||||
the reflect package and may thus produce false positives.
|
||||
|
||||
## Whole program analysis
|
||||
|
||||
Optionally via the `-exported` flag, _unused_ can analyse all
|
||||
arguments as a single program and report unused exported identifiers.
|
||||
This can be useful for checking "internal" packages, or large software
|
||||
projects that do not export an API to the public, but use exported
|
||||
methods between components.
|
||||
|
||||
Do note that in the whole-program analysis, all arguments must
|
||||
type-check. It is not possible to check packages individually in this
|
||||
mode.
|
||||
|
||||
## Examples
|
||||
|
||||
```
|
||||
$ time unused cmd/go
|
||||
/usr/lib/go/src/cmd/go/build.go:1327:6: func hasString is unused
|
||||
/usr/lib/go/src/cmd/go/build.go:2328:6: func toolVerify is unused
|
||||
/usr/lib/go/src/cmd/go/generate.go:375:21: func identLength is unused
|
||||
/usr/lib/go/src/cmd/go/get.go:474:5: var goTag is unused
|
||||
/usr/lib/go/src/cmd/go/get.go:513:6: func cmpGoVersion is unused
|
||||
/usr/lib/go/src/cmd/go/go_test.go:426:23: func grepCountStdout is unused
|
||||
/usr/lib/go/src/cmd/go/go_test.go:432:23: func grepCountStderr is unused
|
||||
/usr/lib/go/src/cmd/go/main.go:406:5: var logf is unused
|
||||
/usr/lib/go/src/cmd/go/main.go:431:6: func runOut is unused
|
||||
/usr/lib/go/src/cmd/go/pkg.go:91:2: field forceBuild is unused
|
||||
/usr/lib/go/src/cmd/go/pkg.go:688:2: const toRoot is unused
|
||||
/usr/lib/go/src/cmd/go/testflag.go:278:6: func setIntFlag is unused
|
||||
unused cmd/go 3.33s user 0.25s system 447% cpu 0.799 total
|
||||
```
|
||||
|
||||
```
|
||||
$ time unused $(go list github.com/prometheus/prometheus/... | grep -v /vendor/)
|
||||
/home/dominikh/prj/src/github.com/prometheus/prometheus/promql/engine_test.go:11:5: var noop is unused
|
||||
/home/dominikh/prj/src/github.com/prometheus/prometheus/retrieval/discovery/dns.go:39:2: const interval is unused
|
||||
/home/dominikh/prj/src/github.com/prometheus/prometheus/retrieval/discovery/dns.go:69:2: field m is unused
|
||||
/home/dominikh/prj/src/github.com/prometheus/prometheus/retrieval/discovery/nerve.go:31:2: const nerveNodePrefix is unused
|
||||
/home/dominikh/prj/src/github.com/prometheus/prometheus/retrieval/discovery/serverset.go:33:2: const serversetNodePrefix is unused
|
||||
/home/dominikh/prj/src/github.com/prometheus/prometheus/retrieval/scrape.go:41:2: const ingestedSamplesCap is unused
|
||||
/home/dominikh/prj/src/github.com/prometheus/prometheus/retrieval/scrape.go:49:2: var errSkippedScrape is unused
|
||||
/home/dominikh/prj/src/github.com/prometheus/prometheus/retrieval/targetmanager.go:184:2: field providers is unused
|
||||
/home/dominikh/prj/src/github.com/prometheus/prometheus/storage/local/delta.go:394:2: field error is unused
|
||||
/home/dominikh/prj/src/github.com/prometheus/prometheus/storage/local/delta.go:398:3: field error is unused
|
||||
/home/dominikh/prj/src/github.com/prometheus/prometheus/storage/local/doubledelta.go:500:2: field error is unused
|
||||
/home/dominikh/prj/src/github.com/prometheus/prometheus/storage/local/doubledelta.go:504:3: field error is unused
|
||||
/home/dominikh/prj/src/github.com/prometheus/prometheus/storage/remote/opentsdb/client.go:40:2: var illegalCharsRE is unused
|
||||
/home/dominikh/prj/src/github.com/prometheus/prometheus/util/stats/timer.go:56:2: field child is unused
|
||||
/home/dominikh/prj/src/github.com/prometheus/prometheus/util/treecache/treecache.go:25:2: field zkEvents is unused
|
||||
unused $(go list github.com/prometheus/prometheus/... | grep -v /vendor/) 5.70s user 0.43s system 535% cpu 1.142 total
|
||||
```
|
||||
|
||||
```
|
||||
$ time unused -exported github.com/kr/pretty/...
|
||||
/home/dominikh/prj/src/github.com/kr/pretty/formatter.go:14:2: const limit is unused
|
||||
/home/dominikh/prj/src/github.com/kr/pretty/formatter.go:322:6: func tryDeepEqual is unused
|
||||
/home/dominikh/prj/src/github.com/kr/pretty/pretty.go:20:6: func Errorf is unused
|
||||
/home/dominikh/prj/src/github.com/kr/pretty/pretty.go:28:6: func Fprintf is unused
|
||||
/home/dominikh/prj/src/github.com/kr/pretty/pretty.go:37:6: func Log is unused
|
||||
/home/dominikh/prj/src/github.com/kr/pretty/pretty.go:45:6: func Logf is unused
|
||||
/home/dominikh/prj/src/github.com/kr/pretty/pretty.go:54:6: func Logln is unused
|
||||
/home/dominikh/prj/src/github.com/kr/pretty/pretty.go:63:6: func Print is unused
|
||||
/home/dominikh/prj/src/github.com/kr/pretty/pretty.go:71:6: func Printf is unused
|
||||
/home/dominikh/prj/src/github.com/kr/pretty/pretty.go:80:6: func Println is unused
|
||||
/home/dominikh/prj/src/github.com/kr/pretty/pretty.go:88:6: func Sprintf is unused
|
||||
/home/dominikh/prj/src/github.com/kr/pretty/pretty.go:92:6: func wrap is unused
|
||||
unused -exported github.com/kr/pretty/... 1.23s user 0.19s system 253% cpu 0.558 total
|
||||
```
|
78
vendor/honnef.co/go/tools/cmd/unused/main.go
vendored
Normal file
78
vendor/honnef.co/go/tools/cmd/unused/main.go
vendored
Normal file
@ -0,0 +1,78 @@
|
||||
// unused reports unused identifiers (types, functions, ...) in your
|
||||
// code.
|
||||
package main // import "honnef.co/go/tools/cmd/unused"
|
||||
|
||||
import (
|
||||
"log"
|
||||
"os"
|
||||
|
||||
"honnef.co/go/tools/lint/lintutil"
|
||||
"honnef.co/go/tools/unused"
|
||||
)
|
||||
|
||||
var (
|
||||
fConstants bool
|
||||
fFields bool
|
||||
fFunctions bool
|
||||
fTypes bool
|
||||
fVariables bool
|
||||
fDebug string
|
||||
fWholeProgram bool
|
||||
fReflection bool
|
||||
)
|
||||
|
||||
func newChecker(mode unused.CheckMode) *unused.Checker {
|
||||
checker := unused.NewChecker(mode)
|
||||
|
||||
if fDebug != "" {
|
||||
debug, err := os.Create(fDebug)
|
||||
if err != nil {
|
||||
log.Fatal("couldn't open debug file:", err)
|
||||
}
|
||||
checker.Debug = debug
|
||||
}
|
||||
|
||||
checker.WholeProgram = fWholeProgram
|
||||
checker.ConsiderReflection = fReflection
|
||||
return checker
|
||||
}
|
||||
|
||||
func main() {
|
||||
log.SetFlags(0)
|
||||
|
||||
fs := lintutil.FlagSet("unused")
|
||||
fs.BoolVar(&fConstants, "consts", true, "Report unused constants")
|
||||
fs.BoolVar(&fFields, "fields", true, "Report unused fields")
|
||||
fs.BoolVar(&fFunctions, "funcs", true, "Report unused functions and methods")
|
||||
fs.BoolVar(&fTypes, "types", true, "Report unused types")
|
||||
fs.BoolVar(&fVariables, "vars", true, "Report unused variables")
|
||||
fs.StringVar(&fDebug, "debug", "", "Write a debug graph to `file`. Existing files will be overwritten.")
|
||||
fs.BoolVar(&fWholeProgram, "exported", false, "Treat arguments as a program and report unused exported identifiers")
|
||||
fs.BoolVar(&fReflection, "reflect", true, "Consider identifiers as used when it's likely they'll be accessed via reflection")
|
||||
fs.Parse(os.Args[1:])
|
||||
|
||||
var mode unused.CheckMode
|
||||
if fConstants {
|
||||
mode |= unused.CheckConstants
|
||||
}
|
||||
if fFields {
|
||||
mode |= unused.CheckFields
|
||||
}
|
||||
if fFunctions {
|
||||
mode |= unused.CheckFunctions
|
||||
}
|
||||
if fTypes {
|
||||
mode |= unused.CheckTypes
|
||||
}
|
||||
if fVariables {
|
||||
mode |= unused.CheckVariables
|
||||
}
|
||||
|
||||
checker := newChecker(mode)
|
||||
l := unused.NewLintChecker(checker)
|
||||
cfg := lintutil.CheckerConfig{
|
||||
Checker: l,
|
||||
ExitNonZero: true,
|
||||
}
|
||||
lintutil.ProcessFlagSet([]lintutil.CheckerConfig{cfg}, fs)
|
||||
}
|
Reference in New Issue
Block a user