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

Migrate gometalinter to golangci lint #138

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
run:
concurrency: 2
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the default behavior, i.e. when we don't specify concurrency?

timeout: 5m
skip-dirs:
- pkg/cloud/digitalocean/actuators/machine/machinesetup
- pkg/apis

linters:
disable-all: true
enable:
- vet
- golint
- varcheck
- structcheck
- gosimple
- unused
- errcheck
Comment on lines +11 to +17
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking at other CAPI projects, they enable a bit more linters. Is it possible to enable those here too?

2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ This document contains guidelines for contributing to the `cluster-api-provider-

## Code Style Guidelines

In order for the pull request to get accepted the code must pass `gofmt`, `govet` and `gometalinter` checks. You can run all checks by invoking `make check`.
In order for the pull request to get accepted the code must pass `gofmt`, `govet` and `golangci-lint` checks. You can run all checks by invoking `make check`.

## Dependency Management

Expand Down
21 changes: 18 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,17 @@ NAME = cluster-api-do-controller
TAG = v1.0.0-alpha.1
DEV_TAG = v1.0.0-alpha.1

# Directories.
TOOLS_DIR := hack/tools
TOOLS_BIN_DIR := $(TOOLS_DIR)/bin
BIN_DIR := bin

# Binaries.
GOLANGCI_LINT := $(TOOLS_BIN_DIR)/golangci-lint

all: depend generate compile images

check: depend gofmt vet gometalinter
check: depend gofmt vet lint

depend: ## Sync vendor directory by running dep ensure
$$GOPATH/bin/dep version || go get -u github.com/golang/dep/cmd/dep
Expand Down Expand Up @@ -69,8 +77,15 @@ gofmt: ## Go fmt your code
vet: ## Apply go vet to all go files
go vet ./...

lint: ## Run gometalinter on all go files
gometalinter --config gometalinter.json ./... --deadline 20m
# Temporarily needed until dep gets replaced by go modules
$(GOLANGCI_LINT): export GO111MODULE=on
# Temporarily needed until golangci-lint version can be bumped
$(GOLANGCI_LINT): export GOPROXY=direct
$(GOLANGCI_LINT): $(TOOLS_DIR)/go.mod ## Build golangci-lint from tools folder.
cd $(TOOLS_DIR); go build -tags=tools -o $(BIN_DIR)/golangci-lint github.com/golangci/golangci-lint/cmd/golangci-lint

lint: $(GOLANGCI_LINT) ## Run golangci-lint on all go files
$(GOLANGCI_LINT) run --config .golangci.yml ./...

.PHONY: help
help: ## Show help messages for make targets
Expand Down
26 changes: 0 additions & 26 deletions gometalinter.json

This file was deleted.

5 changes: 5 additions & 0 deletions hack/tools/go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
module sigs.k8s.io/cluster-api-provider-digitalocean/hack/tools
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems to be in the scope of #137. Is this PR supposed to supersede #137?


go 1.11

require github.com/golangci/golangci-lint v1.15.0
170 changes: 170 additions & 0 deletions hack/tools/go.sum

Large diffs are not rendered by default.

24 changes: 24 additions & 0 deletions hack/tools/tools.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// +build tools

/*
Copyright 2019 The Kubernetes Authors.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

// This package imports things required by build scripts, to force `go mod` to see them as dependencies
package tools

import (
_ "github.com/golangci/golangci-lint/cmd/golangci-lint"
)