github.com/verrazzano/verrazzano@v1.7.1/make/quality.mk (about)

     1  # Copyright (C) 2020, 2023, Oracle and/or its affiliates.
     2  # Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl.
     3  
     4  GO ?= CGO_ENABLED=0 GO111MODULE=on GOPRIVATE=github.com/verrazzano go
     5  GO_LDFLAGS ?= -extldflags -static -X main.buildVersion=${BUILDVERSION} -X main.buildDate=${BUILDDATE}
     6  
     7  #
     8  #  Code quality targets
     9  #
    10  ##@ Linting and coverage
    11  
    12  GOLANGCI_LINT_VERSION=1.55.2
    13  
    14  .PHONY: check
    15  check: golangci-lint word-linter url-linter ## run all linters
    16  
    17  .PHONY: golangci-lint
    18  golangci-lint: check-golangci-lint
    19  	golangci-lint --color never run --max-same-issues 25 --timeout 300s --exclude "unused" --exclude "dot-imports" --exclude "aliasing" --exclude "indent-error-flow" --exclude "superfluous-else" --exclude "appends" --exclude "empty-block"
    20  # replace after fixing the errors
    21  #golangci-lint --color never run --max-same-issues 25 --timeout 300s
    22  
    23  .PHONY: check-golangci-lint
    24  check-golangci-lint: install-golangci-lint ## run Go linters
    25  	@{ \
    26  		set -eu ; \
    27  		ACTUAL_GOLANGCI_LINT_VERSION=$$(golangci-lint version --format short | sed -e 's%^v%%') ; \
    28  		if [ "$${ACTUAL_GOLANGCI_LINT_VERSION}" != "${GOLANGCI_LINT_VERSION}" ] ; then \
    29  			echo "Bad golangci-lint version $${ACTUAL_GOLANGCI_LINT_VERSION}, please install ${GOLANGCI_LINT_VERSION}" ; \
    30  			exit 1 ; \
    31  		fi ; \
    32  	}
    33  
    34  # find or download golangci-lint
    35  .PHONY: install-golangci-lint
    36  install-golangci-lint: ## install golangci-lint
    37  	@{ \
    38  		set -eu ; \
    39  		if ! command -v golangci-lint ; then \
    40  			curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $$(go env GOPATH)/bin v${GOLANGCI_LINT_VERSION} ; \
    41  		fi; \
    42  	}
    43  
    44  # search for internal words that should not be in the repo
    45  # check fails if res from http req is not successful (200)
    46  # the actual command being executed in bash is "curl -sL https://bit.ly/3iIUcdL | grep -v '^\s*\(#\|$\)' | ..."
    47  # additional "$" is to escape literal value in makefile
    48  .PHONY: word-linter
    49  word-linter: ## check for use of 'bad' words
    50  	curl -sL -o /dev/null -w "%{http_code}" https://bit.ly/3iIUcdL | grep -q '200'
    51  	! curl -sL https://bit.ly/3iIUcdL | grep -v '^\s*\(#\|$$\)' | grep -f /dev/stdin -r *
    52  
    53  .PHONY: url-linter
    54  url-linter: ## check for invalid URLs
    55  	go run ${TOOLS_DIR}/url_linter/url_linter.go
    56  
    57  .PHONY: coverage
    58  coverage:  ## test code coverage
    59  	${SCRIPT_DIR}/coverage.sh html