Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixing static analysis issues #30

Open
edupo opened this issue Mar 27, 2018 · 2 comments
Open

Fixing static analysis issues #30

edupo opened this issue Mar 27, 2018 · 2 comments
Labels

Comments

@edupo
Copy link

edupo commented Mar 27, 2018

Running all the static analysis tools described here makes lots and lots of warnings and errors.

Some minor and some major (e.g.: cyclomatic complexity of some docker functions is very high, a big refactoring needs to be done.)

I'm not sure how to tackle this one, but I just add this as a reminder.

@lucymhdavies
Copy link

lucymhdavies commented Apr 8, 2018

Current issues:

$ megacheck ./...
docker.go:221:20: os.Kill cannot be trapped (did you mean syscall.SIGTERM?) (SA1016)
docker.go:257:3: should check returned error before deferring hijack.Conn.Close() (SA5001)
docker.go:48:2: field running is unused (U1000)
The command "megacheck ./..." exited with 1.

Were easily fixed

0.01s$ gocyclo -over 19 $GO_FILES
22 cali (*DockerClient).StartContainer ./docker.go:191:1
The command "gocyclo -over 19 $GO_FILES" exited with 1.

^ like you say in #18 (comment), this is gonna be a hard one to fix, but I'll take a look at what you've got on your fork.

Disabling this one for now.

We definitely need to refactor this function.

0.26s$ golint -set_exit_status $(go list ./...)
/home/travis/gopath/src/github.com/skybet/cali/cli.go:14:2: don't use ALL_CAPS in Go names; use CamelCase
/home/travis/gopath/src/github.com/skybet/cali/cli.go:14:2: exported const EXIT_CODE_RUNTIME_ERROR should have comment (or a comment on this block) or be unexported
/home/travis/gopath/src/github.com/skybet/cali/cli.go:15:2: don't use ALL_CAPS in Go names; use CamelCase
/home/travis/gopath/src/github.com/skybet/cali/command.go:11:1: comment on exported type Command should be of the form "Command ..." (with optional leading article)
/home/travis/gopath/src/github.com/skybet/cali/docker.go:24:2: struct field Id should be ID
/home/travis/gopath/src/github.com/skybet/cali/docker.go:36:2: struct field Id should be ID
/home/travis/gopath/src/github.com/skybet/cali/docker.go:51:1: comment on exported method DockerClient.InitDocker should be of the form "InitDocker ..."
/home/travis/gopath/src/github.com/skybet/cali/docker.go:112:1: comment on exported method DockerClient.AddEnv should be of the form "AddEnv ..."
/home/travis/gopath/src/github.com/skybet/cali/git.go:33:1: comment on exported method Git.Checkout should be of the form "Checkout ..."
/home/travis/gopath/src/github.com/skybet/cali/git.go:54:9: if block ends with a return statement, so drop this else and outdent its block
/home/travis/gopath/src/github.com/skybet/cali/git.go:90:1: exported method Git.Pull should have comment or be unexported
/home/travis/gopath/src/github.com/skybet/cali/git.go:143:6: func repoNameFromUrl should be repoNameFromURL
Found 12 lint suggestions; failing.
The command "golint -set_exit_status $(go list ./...)" exited with 1.

All fairly simple too.

@lucymhdavies
Copy link

Wasn't actually too hard to deal with the gocyclo issue afterall.

In #46 I split out the code to run a container in non-interactive (and non-TTY) mode, into a method startContainerNonInteractive, which resulted in StartContainer becoming exactly 19 lines!

But then I had to add something to make it slightly longer.

I could do the same thing to split out another startContainerInteractive (and split out other parts of StartContainer too)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants