Skip to content

Commit 77aa9d1

Browse files
Add dev linter makefile target (#2254)
* Add dev linter makefile target (make lint) * Refacootry lint script to have the dev and the ci ones that the dev one has all checks and then, the ci just that ones that we could solve the issues already.
1 parent 7cc38cc commit 77aa9d1

File tree

4 files changed

+57
-37
lines changed

4 files changed

+57
-37
lines changed

.travis.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -125,16 +125,16 @@ jobs:
125125
name: Subcommands on Kubernetes
126126
script: make test-subcommand
127127

128-
# Run the unit, sanity, markdown, coverage and linter tests
128+
# Run the unit, sanity and markdown tests
129129
- stage: test
130130
name: Unit, Sanity, and Markdown Tests
131131
before_install:
132132
- go get github.com/mattn/goveralls
133133
script:
134-
- make test-sanity test-unit test-markdown test-linter
134+
- make test-sanity test-unit test-markdown
135135
- $GOPATH/bin/goveralls -service=travis-ci -coverprofile=coverage.out -repotoken=$COVERALLS_TOKEN
136136
after_success: echo 'Tests Passed'
137-
after_failure: echo 'Failure in unit, sanity, markdown, coverage or linter test'
137+
after_failure: echo 'Failure in unit, sanity and markdown tests'
138138

139139
# Build and deploy ansible-operator docker image
140140
- <<: *deploy

Makefile

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ install: ## Build & install the Operator SDK CLI binary
5858
$(BUILD_PATH)
5959

6060
# Code management.
61-
.PHONY: format tidy clean cli-doc
61+
.PHONY: format tidy clean cli-doc lint
6262

6363
format: ## Format the source code
6464
$(Q)go fmt $(PKGS)
@@ -69,6 +69,9 @@ tidy: ## Update dependencies
6969
clean: ## Clean up the build artifacts
7070
$(Q)rm -rf build
7171

72+
lint: ## Run golangci-lint with all checks enabled (development purpose only)
73+
./hack/tests/check-lint.sh dev
74+
7275
##############################
7376
# Generate Artifacts #
7477
##############################
@@ -170,18 +173,16 @@ image-push-scorecard-proxy:
170173
##@ Tests
171174

172175
# Static tests.
173-
.PHONY: test test-markdown test-sanity test-unit test-linter
176+
.PHONY: test test-markdown test-sanity test-unit
174177

175178
test: test-unit ## Run the tests
176179

177-
test-linter: ## Run golangci-lint for the project
178-
./hack/go-linter.sh
179-
180180
test-markdown test/markdown:
181181
./hack/ci/marker
182182

183183
test-sanity test/sanity: tidy build/operator-sdk
184184
./hack/tests/sanity-check.sh
185+
./hack/tests/check-lint.sh ci
185186

186187
TEST_PKGS:=$(shell go list ./... | grep -v -P 'github.com/operator-framework/operator-sdk/(hack|test/e2e)')
187188
test-unit test/unit: ## Run the unit tests

hack/go-linter.sh

Lines changed: 0 additions & 29 deletions
This file was deleted.

hack/tests/check-lint.sh

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
#!/usr/bin/env bash
2+
set -e
3+
4+
source ./hack/common.sh
5+
6+
DEV_LINTERS=(
7+
##todo(camilamacedo86): The following checks requires fixes in the code.
8+
##todo(camilamacedo86): they should be enabled and added in the CI
9+
"--enable=golint"
10+
"--enable=gocyclo"
11+
"--enable=lll"
12+
"--enable=gosec" # NOT add this one to CI since was defined that it should be optional for now at least.
13+
)
14+
15+
subcommand=$1
16+
case $subcommand in
17+
"dev")
18+
##todo(camilamacedo86): It should be removed when all linter checks be enabled
19+
header_text "Checking the project with all linters (dev)"
20+
LINTERS=${DEV_LINTERS[@]}
21+
;;
22+
"ci")
23+
header_text "Checking the project with the linters enabled for the ci"
24+
;;
25+
*)
26+
echo "Must pass 'dev' or 'ci' argument"
27+
exit 1
28+
esac
29+
30+
fetch_go_linter
31+
32+
header_text "Running golangci-lint"
33+
golangci-lint run --disable-all \
34+
--deadline 5m \
35+
--enable=nakedret \
36+
--enable=interfacer \
37+
--enable=varcheck \
38+
--enable=deadcode \
39+
--enable=structcheck \
40+
--enable=misspell \
41+
--enable=maligned \
42+
--enable=ineffassign \
43+
--enable=goconst \
44+
--enable=goimports \
45+
--enable=errcheck \
46+
--enable=dupl \
47+
--enable=unparam \
48+
${LINTERS[@]}

0 commit comments

Comments
 (0)