Setup pre-commit lint hook

Squashed commit of the following:

commit 02591b74c184faf7f7156e95cf05a78fb0ea22a7
Merge: 4057c8ae a32c1f2e
Author: ArtemBaskal <a.baskal@adguard.com>
Date:   Wed Jul 15 12:36:20 2020 +0300

    Merge branch 'master' into feature/git-hooks

commit 4057c8ae117dfb5de493769dbf1577c8d59035a4
Author: ArtemBaskal <a.baskal@adguard.com>
Date:   Tue Jul 14 20:04:38 2020 +0300

    Review changes

commit 2400ab77d9e0e3f7b62b0ffd64aeccf369ff84cd
Author: ArtemBaskal <a.baskal@adguard.com>
Date:   Tue Jul 14 16:27:14 2020 +0300

    Add lint-js and lint-go to .PHONY

commit 8a4efc2cb4f2d53ebea4b88b8182e4c1eb7812eb
Author: ArtemBaskal <a.baskal@adguard.com>
Date:   Tue Jul 14 15:47:14 2020 +0300

    Run linter only if corresponding file extension is changed

commit 8e2e110e9c9c3f865503cf3c0cd3e31dd4579b71
Author: ArtemBaskal <a.baskal@adguard.com>
Date:   Mon Jul 13 19:07:42 2020 +0300

    Setup pre-commit lint hooks
This commit is contained in:
Artem Baskal 2020-07-15 12:49:08 +03:00
parent a32c1f2ee0
commit 38366ba801
3 changed files with 29 additions and 6 deletions

12
.githooks/pre-commit Executable file
View File

@ -0,0 +1,12 @@
#!/bin/bash
set -e;
git diff --cached --name-only | grep -q '.js$' && make lint-js;
found=0
git diff --cached --name-only | grep -q '.go$' && found=1
if [ $found == 1 ]; then
make lint-go || exit 1
go test ./... || exit 1
fi
exit 0;

View File

@ -88,9 +88,12 @@ ifndef DOCKER_IMAGE_NAME
$(error DOCKER_IMAGE_NAME value is not set)
endif
.PHONY: all build client client-watch docker lint test dependencies clean release docker-multi-arch
.PHONY: all build client client-watch docker lint lint-js lint-go test dependencies clean release docker-multi-arch
all: build
init:
git config core.hooksPath .githooks
build: dependencies client
PATH=$(GOPATH)/bin:$(PATH) go generate ./...
CGO_ENABLED=0 go build -ldflags="-s -w -X main.version=$(VERSION) -X main.channel=$(CHANNEL) -X main.goarm=$(GOARM)"
@ -116,11 +119,16 @@ docker:
@echo Now you can run the docker image:
@echo docker run --name "adguard-home" -p 53:53/tcp -p 53:53/udp -p 80:80/tcp -p 443:443/tcp -p 853:853/tcp -p 3000:3000/tcp $(DOCKER_IMAGE_NAME)
lint:
@echo Running linters
golangci-lint run ./...
lint: lint-js lint-go
lint-js:
@echo Running js linter
npm --prefix client run lint
lint-go:
@echo Running go linter
golangci-lint run
test:
@echo Running unit-tests
go test -race -v -bench=. -coverprofile=coverage.txt -covermode=atomic ./...
@ -223,4 +231,4 @@ define write_version_file
# Finish
echo "}" >> $(DIST_DIR)/version.json
endef
endef

View File

@ -150,11 +150,14 @@ Is there a chance to handle this in the future? DNS will never be enough to do t
### Prerequisites
Run `make init` to prepare the development environment.
You will need this to build AdGuard Home:
* [go](https://golang.org/dl/) v1.14 or later.
* [node.js](https://nodejs.org/en/download/) v10 or later.
* [golangci-lint](https://github.com/golangci/golangci-lint)
### Building
Open Terminal and execute these commands: