Skip to content

Commit

Permalink
analytic:chore - Update lint e make commands
Browse files Browse the repository at this point in the history
I'll open a pull request for each service updating its
make commands and already updating the project's lint.
The basis of the structure is to update all services to
use golang in version 1.17 and get `.golangci.yml` file
from horusec-devkit project and usage it here.
In this commit I updated the service `analytic`.

Signed-off-by: wilian <wilian.silva@zup.com.br>
Signed-off-by: Wilian Gabriel <wilian.silva@zup.com.br>
  • Loading branch information
wiliansilvazup committed Feb 21, 2022
1 parent 8d7f2de commit b28c579
Show file tree
Hide file tree
Showing 30 changed files with 282 additions and 362 deletions.
2 changes: 1 addition & 1 deletion .github/CODEOWNERS
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# GitHub code owners
# See https://github.com/blog/2392-introducing-code-owners
* @wiliansilvazup @lucasbrunozup @nathanmartinszup @iancardosozup @matheusalcantarazup
* @wiliansilvazup @lucasbrunozup @nathanmartinszup @iancardosozup @matheusalcantarazup @oliveirafelipezup

2 changes: 2 additions & 0 deletions .github/workflows/analytic-pipeline.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ jobs:
run: make coverage
- name: build
run: make build
- name: Check go mod tidy diff
run: if [ $(go mod tidy && git diff | wc -l) -gt 0 ]; then git diff && exit 1; fi
- name: security
env:
HORUSEC_CLI_REPOSITORY_AUTHORIZATION: ${{ secrets.HORUSEC_CLI_REPOSITORY_AUTHORIZATION }}
Expand Down
8 changes: 4 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,9 @@ stop-web:
docker rm -f horusec-all-in-one

license:
$(GO) get -u github.com/google/addlicense
@$(ADDLICENSE) -check -f ./copyright.txt $(shell find -not -path '*/manager/build*' -not -path '*/.git/*' -not -path '*/node_modules*' -regex '.*\.\(go\|js\|ts\|yml\|yaml\|sh\|dockerfile\)')
$(GO) install github.com/google/addlicense@latest
@$(ADDLICENSE) -check -f ./copyright.txt $(shell find -regex '.*\.\(go\|js\|ts\|yml\|yaml\|sh\|dockerfile\)')

license-fix:
$(GO) get -u github.com/google/addlicense
@$(ADDLICENSE) -f ./copyright.txt $(shell find -not -path '*/manager/build*' -not -path '*/.git/*' -not -path '*/node_modules*' -regex '.*\.\(go\|js\|ts\|yml\|yaml\|sh\|dockerfile\)')
$(GO) install github.com/google/addlicense@latest
@$(ADDLICENSE) -f ./copyright.txt $(shell find -regex '.*\.\(go\|js\|ts\|yml\|yaml\|sh\|dockerfile\)')
34 changes: 18 additions & 16 deletions analytic/.golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@
linters-settings:
depguard:
list-type: blacklist
packages:
packages-with-error-message:
dupl:
threshold: 100
funlen:
Expand Down Expand Up @@ -45,13 +43,15 @@ linters-settings:
min-complexity: 5
goimports:
local-prefixes: github.com/ZupIT/horusec-platform/analytic
golint:
min-confidence: 0
gomnd:
settings:
mnd:
# don't include the "operation" and "assign"
checks: argument,case,condition,return
checks:
- argument
- case
- condition
- return
govet:
check-shadowing: true
settings:
Expand All @@ -70,7 +70,7 @@ linters-settings:
nolintlint:
allow-leading-space: true # don't require machine-readable nolint directives (i.e. with no leading space)
allow-unused: false # report any unused nolint directives
require-explanation: false # don't require an explanation for nolint directives
require-explanation: true # don't require an explanation for nolint directives
require-specific: false # don't require nolint directives to be specific about which linter is being skipped

linters:
Expand All @@ -92,8 +92,8 @@ linters:
- gocritic
- gocyclo
- gofmt
- gofumpt
- goimports
- golint
- gomnd
- goprintffuncname
- gosec
Expand All @@ -114,25 +114,28 @@ linters:
- unparam
- unused
- varcheck
- testpackage
- whitespace
- wsl
- nlreturn
- nestif
- gocognit
- gci
- forbidigo
- errorlint
- revive

# don't enable:
# - asciicheck
# - scopelint
# - gochecknoglobals
# - gocognit
# - godot
# - godox
# - goerr113
# - interfacer
# - maligned
# - nestif
# - prealloc
# - testpackage
# - revive
# - wsl
# - goerr113

issues:
exclude-rules:
- linters:
- lll
Expand All @@ -144,7 +147,6 @@ run:
- examples/
- tmp
- e2e/
- cmd/migrate
skip-files:
- .*_test.go
- .*_mock.go
- .*_mock.go
40 changes: 20 additions & 20 deletions analytic/Makefile
Original file line number Diff line number Diff line change
@@ -1,36 +1,36 @@
GO ?= go
GOFMT ?= gofmt
GOLANG_CI_LINT ?= golangci-lint
GO_FILES ?= $$(find . -name '*.go' | grep -v vendor)
GOLANG_CI_LINT ?= ./bin/golangci-lint
GO_IMPORTS ?= goimports
GO_IMPORTS_LOCAL ?= github.com/ZupIT/horusec-platform/analytic
GO_IMPORTS_LOCAL ?= github.com/ZupIT/horusec-platform/analytic/
HORUSEC ?= horusec
IMAGE_NAME ?= horuszup/horusec-analytic:local
GO_FUMPT ?= gofumpt
GO_GCI ?= gci
GO_LIST_TO_TEST ?= $$(go list ./...)

fmt:
$(GOFMT) -w $(GO_FILES)
install-format-dependencies:
$(GO) install golang.org/x/tools/cmd/goimports@latest
$(GO) install mvdan.cc/gofumpt@latest
$(GO) install github.com/daixiang0/gci@v0.2.9

format: install-format-dependencies
$(GOFMT) -s -l -w $(GO_FILES)
$(GO_IMPORTS) -w -local $(GO_IMPORTS_LOCAL) $(GO_FILES)
$(GO_FUMPT) -l -w $(GO_FILES)
$(GO_GCI) -w -local $(GO_IMPORTS_LOCAL) $(GO_FILES)

lint:
ifeq ($(wildcard $(GOLANG_CI_LINT)), $(GOLANG_CI_LINT))
$(GOLANG_CI_LINT) run -v --timeout=5m -c .golangci.yml ./...
else
curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s latest
$(GOLANG_CI_LINT) run -v --timeout=5m -c .golangci.yml ./...
endif
$(GO) install github.com/golangci/golangci-lint/cmd/golangci-lint@v1.43.0
$(GOLANG_CI_LINT) run -v --timeout=5m -c .golangci.yml ./...

coverage:
curl -fsSL https://raw.githubusercontent.com/ZupIT/horusec-devkit/main/scripts/coverage.sh | bash -s 100 .

test:
$(GO) clean -testcache && $(GO) test -v ./... -timeout=2m -parallel=1 -failfast -short

fix-imports:
ifeq (, $(shell which $(GO_IMPORTS)))
$(GO) get -u golang.org/x/tools/cmd/goimports
$(GO_IMPORTS) -local $(GO_IMPORTS_LOCAL) -w $(GO_FILES)
else
$(GO_IMPORTS) -local $(GO_IMPORTS_LOCAL) -w $(GO_FILES)
endif
$(GO) clean -testcache
$(GO) test -v $(GO_LIST_TO_TEST) -race -timeout=5m -parallel=1 -failfast -short

security:
ifeq (, $(shell which $(HORUSEC)))
Expand All @@ -46,7 +46,7 @@ build:
update-swagger:
curl -fsSL https://raw.githubusercontent.com/ZupIT/horusec-devkit/main/scripts/update-swagger.sh | bash -s "./cmd/app/main.go" .

pipeline: fmt fix-imports lint test coverage build security
pipeline: format lint test coverage build security

docker-build: ## Build docker image with the analytic.
docker build -t ${IMAGE_NAME} -f ./deployments/dockerfiles/Dockerfile .
Loading

0 comments on commit b28c579

Please sign in to comment.