Skip to content

Commit

Permalink
lint: add make target lint
Browse files Browse the repository at this point in the history
Adds the lint make target and the initial .golangci-lint configuration.

Also it adds //nolint directive to some of the files

Signed-off-by: Daniel Hiller <[email protected]>
  • Loading branch information
dhiller committed Dec 12, 2024
1 parent e5af80c commit 911aa34
Show file tree
Hide file tree
Showing 5 changed files with 72 additions and 5 deletions.
14 changes: 14 additions & 0 deletions .golangci.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
linters:
# initially we disable all linters, since this is an old code base with quite a lot of issues
disable-all: true
enable:
- gocyclo
# - staticcheck
# - unused
# - ineffassign
# - govet
# - gosimple
# - errcheck
#linters-settings:
# gocyclo:
# min-complexity: 10
27 changes: 25 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,28 @@ querier := robots/cmd/release-querier
kubevirtci := robots/cmd/kubevirtci-bumper
bazelbin := bazelisk

.PHONY: all clean deps-update gazelle-update-repos update-labels $(limiter) $(flake-report-writer) $(querier) $(kubevirtci) $(flake-issue-creator)
ifndef GOLANGCI_LINT_VERSION
GOLANGCI_LINT_VERSION=v1.62.2
export GOLANGCI_LINT_VERSION
endif
ifndef ARTIFACTS
ARTIFACTS=/tmp/artifacts
export ARTIFACTS
endif
ifndef COVERAGE_OUTPUT_PATH
COVERAGE_OUTPUT_PATH=${ARTIFACTS}/coverage.html
export COVERAGE_OUTPUT_PATH
endif

.PHONY: all make-artifacts-dir clean deps-update gazelle-update-repos update-labels install-metrics-binaries lint $(limiter) $(flake-report-writer) $(querier) $(kubevirtci) $(flake-issue-creator)
all: deps-update $(limiter) $(flake-report-writer) $(querier) $(kubevirtci) $(flake-issue-creator)

clean:
make-artifacts-dir:
mkdir -p ${ARTIFACTS}

clean: install-metrics-binaries
$(bazelbin) clean
golangci-lint cache clean

$(limiter) $(flake-report-writer) $(querier) $(kubevirtci) $(flake-issue-creator): deps-update
$(MAKE) --directory=$@
Expand Down Expand Up @@ -40,3 +57,9 @@ test:

update-labels:
./hack/labels/update.sh

install-metrics-binaries:
if ! command -V golangci-lint; then curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b ${GOPATH}/bin ${GOLANGCI_LINT_VERSION} ; fi

lint: install-metrics-binaries
./hack/lint.sh
30 changes: 30 additions & 0 deletions hack/lint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#!/usr/bin/env bash
#
# This file is part of the KubeVirt project
#
# 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.
#
# Copyright the KubeVirt Authors.
#
#

set -e
set -u
set -o pipefail

golangci-lint --version
golangci-lint run

if [ $(git grep '//nolint' -- '**/*.go' | wc -l) -gt 0 ]; then
echo 'WARNING: nolint directive detected';
fi
4 changes: 2 additions & 2 deletions releng/release-tool/release-tool.go
Original file line number Diff line number Diff line change
Expand Up @@ -772,7 +772,7 @@ func (r *releaseData) getReleases() ([]*github.RepositoryRelease, error) {
return r.allReleases, nil
}

func (r *releaseData) autoDetectData(autoReleaseCadance string, autoPromoteAfterDays int) error {
func (r *releaseData) autoDetectData(autoReleaseCadance string, autoPromoteAfterDays int) error { //nolint:gocyclo

log.Printf("Attempting to auto detect release for %s/%s", r.org, r.repo)

Expand Down Expand Up @@ -975,7 +975,7 @@ func (r *releaseData) autoDetectData(autoReleaseCadance string, autoPromoteAfter
return nil
}

func (r *releaseData) verifyTag() error {
func (r *releaseData) verifyTag() error { //nolint:gocyclo
// must be a valid semver version
tagSemver, err := semver.NewVersion(r.tag)
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion robots/pkg/kubevirt/cmd/get/support-matrix.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ type SupportMatrixTemplateData struct {
MapK6tToK8sVersions map[string]map[string]bool
}

func GenerateMarkdownForSupportMatrix(_ *cobra.Command, _ []string) error {
func GenerateMarkdownForSupportMatrix(_ *cobra.Command, _ []string) error { //nolint:gocyclo
if err := getSupportMatrixOpts.validateOptions(); err != nil {
return fmt.Errorf("failed to validate options: %v", err)
}
Expand Down

0 comments on commit 911aa34

Please sign in to comment.