Skip to content

Commit

Permalink
Enable Go linters
Browse files Browse the repository at this point in the history
  • Loading branch information
nakabonne committed Nov 1, 2020
1 parent abf439d commit 2fb4de7
Show file tree
Hide file tree
Showing 2 changed files with 86 additions and 11 deletions.
71 changes: 71 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
run:
issues-exit-code: 0

linters:
disable-all: true
enable:
- staticcheck
- gosimple
- ineffassign
- errcheck
- misspell
- unparam
- gofmt
- goimports
- deadcode
- nestif
- govet
- golint
- prealloc
- depguard
- dogsled
- dupl
- goconst
- gocritic
- gocyclo
- goprintffuncname
- gosec
- nakedret
- rowserrcheck
- scopelint
- structcheck
- stylecheck
- typecheck
- unconvert
- varcheck
- exhaustive
- exportloopref
- goerr113
- gofumpt
- unused

run:
tests: false

issues:
exclude-rules:
- linters:
- goerr113
text: "err113: do not define dynamic errors"
- linters:
- exhaustive
text: "missing cases in switch of type keyboard.Key"

linters-settings:
dupl:
threshold: 100
funlen:
lines: 100
statements: 50
goconst:
min-len: 2
min-occurrences: 2
goimports:
local-prefixes: github.com/nakabonne/gosivy
golint:
min-confidence: 0.3
maligned:
suggest-new: true
misspell:
locale: US

26 changes: 15 additions & 11 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,11 @@ func main() {
if err != nil {
os.Exit(0)
}
os.Exit(c.run(flagSet.Args()))
code := c.run(flagSet.Args())
if code != 0 {
c.usage()
os.Exit(code)
}
}

func parseFlags(stdout, stderr io.Writer) (*cli, error) {
Expand All @@ -84,13 +88,6 @@ func parseFlags(stdout, stderr io.Writer) (*cli, error) {
return c, nil
}

func (c *cli) validate() error {
if c.scrapeInterval < time.Second {
return fmt.Errorf(`"--scrape-interval" must be >= 1s`)
}
return nil
}

func (c *cli) run(args []string) int {
if c.version {
fmt.Fprintf(c.stderr, "version=%s, commit=%s, buildDate=%s, os=%s, arch=%s\n", version, commit, date, runtime.GOOS, runtime.GOARCH)
Expand All @@ -108,11 +105,12 @@ func (c *cli) run(args []string) int {
c.listProcesses()
return 0
}

// Try to run diagnoser
var addr *net.TCPAddr
if len(args) <= 0 {
if len(args) == 0 {
// TODO: Make sure to use the process where the agent runs on.
addr = &net.TCPAddr{}
return 0
} else {
var err error
addr, err = targetToAddr(args[0])
Expand All @@ -123,12 +121,18 @@ func (c *cli) run(args []string) int {
}
if err := diagnoser.Run(addr, c.scrapeInterval); err != nil {
fmt.Fprintf(c.stderr, "failed to start diagnoser: %s\n", err.Error())
c.usage()
return 1
}
return 0
}

func (c *cli) validate() error {
if c.scrapeInterval < time.Second {
return fmt.Errorf(`"--scrape-interval" must be >= 1s`)
}
return nil
}

// targetToAddr parses the target string (pid or host:port),
// and converts it into the address of a TCP end point.
func targetToAddr(target string) (*net.TCPAddr, error) {
Expand Down

0 comments on commit 2fb4de7

Please sign in to comment.