Commit 084542a0 by Arve Knudsen Committed by GitHub

Chore: Consolidate on golangci-lint (#25834)

Signed-off-by: Arve Knudsen <arve.knudsen@gmail.com>
parent 10715a1c
......@@ -813,18 +813,19 @@ jobs:
name: Install Go linters
command: |
pushd /tmp
curl -fLO https://github.com/golangci/golangci-lint/releases/download/v1.24.0/golangci-lint-1.24.0-linux-amd64.tar.gz
echo 241ca454102e909de04957ff8a5754c757cefa255758b3e1fba8a4533d19d179 \
golangci-lint-1.24.0-linux-amd64.tar.gz | sha256sum --check --strict --status
tar -xf golangci-lint-1.24.0-linux-amd64.tar.gz
sudo mv golangci-lint-1.24.0-linux-amd64/golangci-lint /usr/local/bin/
VERSION=1.27.0
curl -fLO https://github.com/golangci/golangci-lint/releases/download/v${VERSION}/golangci-lint-${VERSION}-linux-amd64.tar.gz
echo 8d345e4e88520e21c113d81978e89ad77fc5b13bfdf20e5bca86b83fc4261272 \
golangci-lint-${VERSION}-linux-amd64.tar.gz | sha256sum --check --strict --status
tar -xf golangci-lint-${VERSION}-linux-amd64.tar.gz
sudo mv golangci-lint-${VERSION}-linux-amd64/golangci-lint /usr/local/bin/
popd
make scripts/go/bin/revive scripts/go/bin/gosec
make scripts/go/bin/revive
- run:
name: Lint Go
command: |
go vet ./pkg/...
golangci-lint run -v -j 4 --config scripts/go/configs/ci/.golangci.yml -E deadcode -E gofmt \
# To save memory, run in two batches
golangci-lint run -v -j 4 --config scripts/go/configs/ci/.golangci.yml -E vet -E deadcode -E gofmt \
-E gosimple -E ineffassign -E structcheck -E typecheck ./pkg/...
golangci-lint run -v -j 4 --config scripts/go/configs/ci/.golangci.yml -E unconvert -E unused \
-E varcheck -E goconst -E errcheck -E staticcheck ./pkg/...
......@@ -836,9 +837,6 @@ jobs:
./pkg/services/provisioning/dashboards/... \
./pkg/plugins/backendplugin/...
./scripts/go/bin/gosec -quiet -exclude=G104,G107,G108,G201,G202,G204,G301,G304,G401,G402,G501 \
-conf=./scripts/go/configs/gosec.json ./pkg/...
test-frontend:
executor: node
steps:
......
......@@ -4,7 +4,7 @@
-include local/Makefile
.PHONY: all deps-go deps-js deps build-go build-server build-cli build-js build build-docker-dev build-docker-full lint-go gosec revive golangci-lint go-vet test-go test-js test run run-frontend clean devenv devenv-down revive-strict protobuf help
.PHONY: all deps-go deps-js deps build-go build-server build-cli build-js build build-docker-dev build-docker-full lint-go revive golangci-lint test-go test-js test run run-frontend clean devenv devenv-down revive-strict protobuf help
GO = GO111MODULE=on go
GO_FILES ?= ./pkg/...
......@@ -102,23 +102,7 @@ golangci-lint: scripts/go/bin/golangci-lint
--config ./scripts/go/configs/.golangci.yml \
$(GO_FILES)
scripts/go/bin/gosec: scripts/go/go.mod
@cd scripts/go; \
$(GO) build -o ./bin/gosec github.com/securego/gosec/cmd/gosec
# TODO recheck the rules and leave only necessary exclusions
gosec: scripts/go/bin/gosec
@echo "lint via gosec"
@scripts/go/bin/gosec -quiet \
-exclude=G104,G107,G108,G201,G202,G204,G301,G304,G401,G402,G501 \
-conf=./scripts/go/configs/gosec.json \
$(GO_FILES)
go-vet:
@echo "lint via go vet"
@$(GO) vet $(GO_FILES)
lint-go: go-vet golangci-lint revive revive-strict gosec ## Run all code checks for backend.
lint-go: golangci-lint revive revive-strict # Run all code checks for backend.
# with disabled SC1071 we are ignored some TCL,Expect `/usr/bin/env expect` scripts
shellcheck: $(SH_FILES) ## Run checks for shell scripts.
......
......@@ -163,7 +163,8 @@ func supportsCurrentArch(version *models.Version) bool {
}
func latestSupportedVersion(plugin *models.Plugin) *models.Version {
for _, ver := range plugin.Versions {
for _, v := range plugin.Versions {
ver := v
if supportsCurrentArch(&ver) {
return &ver
}
......
......@@ -13,7 +13,8 @@ func (cmd Command) listRemoteCommand(c utils.CommandLine) error {
return err
}
for _, plugin := range plugin.Plugins {
for _, p := range plugin.Plugins {
plugin := p
if len(plugin.Versions) > 0 {
ver := latestSupportedVersion(&plugin)
if ver != nil {
......
......@@ -35,14 +35,16 @@ func (cmd Command) upgradeAllCommand(c utils.CommandLine) error {
pluginsToUpgrade := make([]models.InstalledPlugin, 0)
for _, localPlugin := range localPlugins {
for _, remotePlugin := range remotePlugins.Plugins {
if localPlugin.Id == remotePlugin.Id {
for _, p := range remotePlugins.Plugins {
remotePlugin := p
if localPlugin.Id != remotePlugin.Id {
continue
}
if shouldUpgrade(localPlugin.Info.Version, &remotePlugin) {
pluginsToUpgrade = append(pluginsToUpgrade, localPlugin)
}
}
}
}
for _, p := range pluginsToUpgrade {
logger.Infof("Updating %v \n", p.Id)
......
......@@ -21,8 +21,9 @@ func TestVersionComparison(t *testing.T) {
}
for k, v := range upgradeablePlugins {
val := v
t.Run(fmt.Sprintf("for %s should be true", k), func(t *testing.T) {
assert.True(t, shouldUpgrade(k, &v))
assert.True(t, shouldUpgrade(k, &val))
})
}
})
......@@ -39,8 +40,9 @@ func TestVersionComparison(t *testing.T) {
}
for k, v := range shouldNotUpgrade {
val := v
t.Run(fmt.Sprintf("for %s should be false", k), func(t *testing.T) {
assert.False(t, shouldUpgrade(k, &v))
assert.False(t, shouldUpgrade(k, &val))
})
}
})
......
......@@ -292,7 +292,8 @@ func TestAccountDataAccess(t *testing.T) {
func testHelperUpdateDashboardAcl(dashboardId int64, items ...models.DashboardAcl) error {
cmd := models.UpdateDashboardAclCommand{DashboardId: dashboardId}
for _, item := range items {
for _, i := range items {
item := i
item.Created = time.Now()
item.Updated = time.Now()
cmd.Items = append(cmd.Items, &item)
......
......@@ -4,6 +4,8 @@ run:
linters:
disable-all: true
enable:
- gosec
- vet
- deadcode
- gofmt
- gosimple
......@@ -23,3 +25,33 @@ linters-settings:
min-len: 5
# minimal occurrences count to trigger, 3 by default
min-occurrences: 5
issues:
exclude-rules:
- linters:
- gosec
text: G108
- linters:
- gosec
text: G110
- linters:
- gosec
text: G201
- linters:
- gosec
text: G202
- linters:
- gosec
text: G306
- linters:
- gosec
text: G401
- linters:
- gosec
text: G402
- linters:
- gosec
text: G501
- linters:
- gosec
text: G501
......@@ -10,3 +10,30 @@ linters-settings:
min-len: 5
# minimal occurrences count to trigger, 3 by default
min-occurrences: 5
issues:
exclude-rules:
- linters:
- gosec
text: G108
- linters:
- gosec
text: G110
- linters:
- gosec
text: G201
- linters:
- gosec
text: G202
- linters:
- gosec
text: G306
- linters:
- gosec
text: G401
- linters:
- gosec
text: G402
- linters:
- gosec
text: G501
{
"G302": "0660",
"G301": "0755"
}
......@@ -3,12 +3,15 @@ module github.com/grafana/grafana/scripts/go
go 1.14
require (
github.com/golangci/golangci-lint v1.24.0
github.com/mgechev/revive v0.0.0-20190917153825-40564c5052ae
github.com/securego/gosec v0.0.0-20200103095621-79fbf3af8d83
github.com/golangci/golangci-lint v1.27.0
github.com/mattn/go-colorable v0.1.6 // indirect
github.com/mattn/go-runewidth v0.0.9 // indirect
github.com/mgechev/revive v1.0.2
github.com/unknwon/bra v0.0.0-20190805204333-bb0929b6cca0
github.com/unknwon/com v1.0.1 // indirect
github.com/unknwon/log v0.0.0-20150304194804-e617c87089d3 // indirect
github.com/urfave/cli v1.20.0 // indirect
golang.org/x/sys v0.0.0-20200622214017-ed371f2e16b4 // indirect
golang.org/x/tools v0.0.0-20200624225443-88f3c62a19ff // indirect
gopkg.in/fsnotify/fsnotify.v1 v1.4.7 // indirect
)
......@@ -5,6 +5,5 @@ package main
import (
_ "github.com/golangci/golangci-lint/cmd/golangci-lint"
_ "github.com/mgechev/revive"
_ "github.com/securego/gosec"
_ "github.com/unknwon/bra"
)
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment