Skip to content
This repository has been archived by the owner on Jun 28, 2024. It is now read-only.

Commit

Permalink
Merge pull request #1407 from chavafg/topic/linter-backport-1.6
Browse files Browse the repository at this point in the history
backport: lint: Switch golang linter to golangci-lint
  • Loading branch information
chavafg authored Apr 4, 2019
2 parents 61f1d0d + d676140 commit 47f563c
Show file tree
Hide file tree
Showing 10 changed files with 58 additions and 89 deletions.
35 changes: 35 additions & 0 deletions .ci/.golangci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# Copyright (c) 2017 Intel Corporation
#
# SPDX-License-Identifier: Apache-2.0

run:
concurrency: 4
deadline: 600s
skip-dirs:
- vendor
# Ignore auto-generated protobuf code.
skip-files:
- ".*\\.pb\\.go$"

linters:
disable-all: true
enable:
- deadcode
- gocyclo
- gofmt
- golint
- gosimple
- govet
- ineffassign
- maligned
- misspell
- staticcheck
- structcheck
- typecheck
- unconvert
- unused
- varcheck

linters-settings:
gocyclo:
min_complexity: 15
66 changes: 5 additions & 61 deletions .ci/static-checks.sh
Original file line number Diff line number Diff line change
Expand Up @@ -209,77 +209,21 @@ check_go()
# No packages to test
[ -z "$go_packages" ] && return

local linter="gometalinter"
local linter="golangci-lint"

# Run golang checks
if [ ! "$(command -v $linter)" ]
then
info "Installing ${linter}"

local linter_url="github.com/alecthomas/gometalinter"
go get -d "$linter_url"

# Pin to known good version.
#
# This project changes a lot but we don't want newly-added
# linter checks to break valid PR code.
#
local linter_version=$(get_version "externals.gometalinter.version")
local linter_url=$(get_test_version "externals.golangci-lint.url")
local linter_version=$(get_test_version "externals.golangci-lint.version")

info "Forcing ${linter} version ${linter_version}"

(cd "$GOPATH/src/$linter_url" && git checkout "$linter_version" && go install)
eval "$linter" --install --vendor
fi

# Ignore vendor directories
# Note: There is also a "--vendor" flag which claims to do what we want, but
# it doesn't work :(
local linter_args="--exclude=\"\\bvendor/.*\""

# Check test code too
linter_args+=" --tests"

# Ignore auto-generated protobuf code.
#
# Note that "--exclude=" patterns are *not* anchored meaning this will apply
# anywhere in the tree.
linter_args+=" --exclude=\".*\.pb\.go\""

# When running the linters in a CI environment we need to disable them all
# by default and then explicitly enable the ones we are care about. This is
# necessary since *if* gometalinter adds a new linter, that linter may cause
# the CI build to fail when it really shouldn't. However, when this script is
# run locally, all linters should be run to allow the developer to review any
# failures (and potentially decide whether we need to explicitly enable a new
# linter in the CI).
#
# Developers may set KATA_DEV_MODE to any value for the same behaviour.
[ "$CI" = true ] || [ -n "$KATA_DEV_MODE" ] && linter_args+=" --disable-all"

[ "$TRAVIS_GO_VERSION" != "tip" ] && linter_args+=" --enable=gofmt"

if [ "$(uname -s)" == "Linux" ]; then
linter_args+=" --concurrency=$(nproc)"
elif [ "$(uname -s)" == "Darwin" ]; then
linter_args+=" --concurrency=$(sysctl -n hw.activecpu)"
build_version ${linter_url} "" ${linter_version}
fi

linter_args+=" --enable=misspell"
linter_args+=" --enable=vet"
linter_args+=" --enable=ineffassign"
linter_args+=" --enable=gocyclo"
linter_args+=" --cyclo-over=15"
linter_args+=" --enable=golint"
linter_args+=" --deadline=600s"
linter_args+=" --enable=structcheck"
linter_args+=" --enable=unused"
linter_args+=" --enable=staticcheck"
linter_args+=" --enable=maligned"
linter_args+=" --enable=varcheck"
linter_args+=" --enable=unconvert"

info "$linter args: '$linter_args'"
local linter_args="run -c ${cidir}/.golangci.yml"

# Non-option arguments other than "./..." are
# considered to be directories by $linter, not package names.
Expand Down
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ language: go
go_import_path: github.com/kata-containers/tests

go:
- "1.10.x"
- "1.11.x"
- stable

env:
Expand Down
2 changes: 1 addition & 1 deletion cmd/checkmetrics/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ func processMetricsBaseline(context *cli.Context) (err error) {
default:
{
log.Warnf("Unknown type [%s] for metric [%s]", m.Type, m.Name)
summary = (&metricsCheck{}).genErrorLine(false, m.Name, "Unsupported Type", fmt.Sprintf("%s", m.Type))
summary = (&metricsCheck{}).genErrorLine(false, m.Name, "Unsupported Type", fmt.Sprint(m.Type))
fails++
}
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/log-parser/display.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ func (d *DisplayHandlers) Get() []string {
formats = append(formats, f)
}

sort.Sort(sort.StringSlice(formats))
sort.Strings(formats)

return formats
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/log-parser/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ func showSummary(entries *LogEntries, files []string) {
counts[file] = count
}

sort.Sort(sort.StringSlice(files))
sort.Strings(files)

recordCount := entries.Len()
fileCount := len(files)
Expand Down
2 changes: 1 addition & 1 deletion integration/docker/cgroups_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ type cgroupType string

const (
cgroupCPU cgroupType = "cpu"
cgroupCpuset = "cpuset"
cgroupCpuset cgroupType = "cpuset"
)

const (
Expand Down
24 changes: 4 additions & 20 deletions integration/docker/docker.go
Original file line number Diff line number Diff line change
Expand Up @@ -279,11 +279,7 @@ func IsRunningDockerContainer(name string) bool {

output := strings.TrimSpace(stdout)
tests.LogIfFail("container running: " + output)
if output == "false" {
return false
}

return true
return !(output == "false")
}

// ExistDockerContainer returns true if any of next cases is true:
Expand Down Expand Up @@ -341,31 +337,19 @@ func ExistDockerContainer(name string) bool {
// RemoveDockerContainer removes a container using docker rm -f
func RemoveDockerContainer(name string) bool {
_, _, exitCode := dockerRm("-f", name)
if exitCode != 0 {
return false
}

return true
return (exitCode == 0)
}

// StopDockerContainer stops a container
func StopDockerContainer(name string) bool {
_, _, exitCode := dockerStop(name)
if exitCode != 0 {
return false
}

return true
return (exitCode == 0)
}

// KillDockerContainer kills a container
func KillDockerContainer(name string) bool {
_, _, exitCode := dockerKill(name)
if exitCode != 0 {
return false
}

return true
return (exitCode == 0)
}

func randomDockerName() string {
Expand Down
4 changes: 1 addition & 3 deletions integration/docker/run_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,9 +112,7 @@ var _ = Describe("run", func() {

dockerArgs = append(dockerArgs, "--rm", "--name", id, Image, "stat")

for _, lf := range loopFiles {
dockerArgs = append(dockerArgs, lf)
}
dockerArgs = append(dockerArgs, loopFiles...)
})

AfterEach(func() {
Expand Down
8 changes: 8 additions & 0 deletions versions.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -48,3 +48,11 @@ externals:
description: "cri-o dependency used for building documentation"
url: "https://github.com/cpuguy83/go-md2man"
version: "v1.0.8"

golangci-lint:
description: "utility to run various golang linters"
url: "github.com/golangci/golangci-lint"
# Using HEAD for now as v1.15.0 does not compile with golang 1.12+. Will be
# pegged to the next release once it comes out.
# https://github.com/kata-containers/tests/issues/1329
version: "HEAD"

0 comments on commit 47f563c

Please sign in to comment.