Skip to content

Commit

Permalink
engine:refactor - improving engine code and performance (#60)
Browse files Browse the repository at this point in the history
This commit contains a complete engine refactoring and includes some
breaking changes. The use of the engine has been simplified to just one
function called Run, this function will receive a context, project path
that must be analyzed and a slice of rules. These rules are defined by
a generic interface and each one have your own implementation, that will
make it easy to add other types of analysis in the future, such as semantic.
Various performance and code improvements have also been made, which
dramatically improved code quality and analysis time.

Signed-off-by: Nathan Martins <nathan.martins@zup.com.br>
  • Loading branch information
nathanmartinszup authored Jan 17, 2022
1 parent a8a6ece commit 0f12809
Show file tree
Hide file tree
Showing 28 changed files with 915 additions and 2,355 deletions.
2 changes: 1 addition & 1 deletion .github/CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
# GitHub code owners
# See https://github.com/blog/2392-introducing-code-owners
* @wiliansilvazup @nathannascimentozup @igorreiszup @lucasbrunozup @nathanmartinszup
* @wiliansilvazup @matheusalcantarazup @lucasbrunozup @nathanmartinszup @iancardosozup
30 changes: 16 additions & 14 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
# See the License for the specific language governing permissions and
# limitations under the License.


linters-settings:
depguard:
list-type: blacklist
Expand Down Expand Up @@ -46,8 +45,6 @@ linters-settings:
min-complexity: 5
goimports:
local-prefixes: github.com/ZupIT/horusec-engine
golint:
min-confidence: 0
gomnd:
settings:
mnd:
Expand All @@ -71,7 +68,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 @@ -94,7 +91,6 @@ linters:
- gocyclo
- gofmt
- goimports
- golint
- gomnd
- goprintffuncname
- gosec
Expand All @@ -116,22 +112,26 @@ linters:
- unused
- varcheck
- whitespace
- gci
- gofumpt
- testpackage
- wsl
- nlreturn
- nestif
- gocognit
- errorlint
- revive

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

issues:
exclude-rules:
Expand All @@ -140,11 +140,13 @@ exclude-rules:
source: "^// "

run:
skip-dirs-use-default: true
skip-dirs:
- vendor/
- text/examples/
- tmp
- tmp/
- e2e/
- examples/
skip-files:
- .*_test.go
- .*_mock.go
- .*_mock.go
- ".*tmp.*"
42 changes: 20 additions & 22 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,23 +1,18 @@
GO ?= go
GOFMT ?= gofmt
GO_FILES ?= $$(find . -name '*.go' | grep -v vendor)
GOLANG_CI_LINT ?= ./bin/golangci-lint
GO_FILES ?= $$(find . -name '*.go' | grep -v vendor | grep -v /examples/)
GOLANG_CI_LINT ?= golangci-lint
GO_IMPORTS ?= goimports
GO_IMPORTS_LOCAL ?= github.com/ZupIT/horusec-engine
HORUSEC ?= horusec
GO_FUMPT ?= gofumpt
GO_GCI ?= gci
ADDLICENSE ?= addlicense
GO_LIST_TO_TEST ?= $$(go list ./... | grep -v /text/examples/)

fmt:
$(GOFMT) -w $(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@latest
$(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 66.3 .
Expand All @@ -26,13 +21,16 @@ test:
$(GO) clean -testcache
$(GO) test -v $(GO_LIST_TO_TEST) -race -timeout=5m -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
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)

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

security:
ifeq (, $(shell which $(HORUSEC)))
Expand All @@ -42,12 +40,12 @@ security:
$(HORUSEC) start -p="./" -e="true"
endif

pipeline: fmt fix-imports lint test coverage security

license:
$(GO) get -u github.com/google/addlicense
$(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
$(GO) install github.com/google/addlicense@latest
@$(ADDLICENSE) -f ./copyright.txt $(shell find -regex '.*\.\(go\|js\|ts\|yml\|yaml\|sh\|dockerfile\)')

pipeline: format license-fix lint test coverage security
2 changes: 1 addition & 1 deletion copyright.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Copyright 2020 ZUP IT SERVICOS EM TECNOLOGIA E INOVACAO SA
Copyright 2022 ZUP IT SERVICOS EM TECNOLOGIA E INOVACAO SA

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand Down
Loading

0 comments on commit 0f12809

Please sign in to comment.