From e9cd3319cf14b3d9484c4e6d7aa5040509a81653 Mon Sep 17 00:00:00 2001 From: Sorin Sbarnea Date: Tue, 7 Jan 2020 20:46:18 +0000 Subject: Enable pre-commit tool linting This should help use keep the codebase more consistent, and avoid sevel whitespace related issues, or bad file permissions. pre-commit allows us to easily introduce other linters in follow-ups, like bashate. Note: pre-commit tool does *not* install any git-hooks. Making commits will will call the tool unless you deliverately tell it to install the hooks. Signed-off-by: Sorin Sbarnea --- .pre-commit-config.yaml | 12 ++++++++++++ API.md | 0 Makefile | 9 ++++++++- contrib/gate/Dockerfile | 1 + contrib/snapcraft/.editorconfig | 2 +- docs/source/Commands.rst | 2 +- docs/source/network.rst | 2 +- docs/source/volume.rst | 2 +- test/install/.gitignore | 2 +- test/install/README.md | 2 +- test/trust_set_test.json | 2 +- 11 files changed, 28 insertions(+), 8 deletions(-) create mode 100644 .pre-commit-config.yaml mode change 100755 => 100644 API.md diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml new file mode 100644 index 000000000..4de8e4c12 --- /dev/null +++ b/.pre-commit-config.yaml @@ -0,0 +1,12 @@ +--- +exclude: ^vendor/ +repos: + - repo: https://github.com/pre-commit/pre-commit-hooks.git + rev: v2.4.0 + hooks: + - id: end-of-file-fixer + - id: trailing-whitespace + - id: mixed-line-ending + - id: check-byte-order-marker + - id: check-executables-have-shebangs + - id: check-merge-conflict diff --git a/API.md b/API.md old mode 100755 new mode 100644 diff --git a/Makefile b/Makefile index 5d3405387..a018e05b4 100644 --- a/Makefile +++ b/Makefile @@ -32,8 +32,10 @@ BUILDTAGS ?= \ exclude_graphdriver_devicemapper \ seccomp \ varlink -PYTHON ?= $(shell command -v python python3|head -n1) +PYTHON ?= $(shell command -v python3 python|head -n1) PKG_MANAGER ?= $(shell command -v dnf yum|head -n1) +# ~/.local/bin is not in PATH on all systems +PRE_COMMIT = $(shell command -v bin/venv/bin/pre-commit ~/.local/bin/pre-commit pre-commit | head -n1) SOURCES = $(shell find . -name "*.go") @@ -149,6 +151,11 @@ endif touch $@ lint: golangci-lint +ifeq ($(PRE_COMMIT),) + @echo "FATAL: pre-commit was not found, check https://pre-commit.com/ about installing it." >&2 + @exit 2 +endif + $(PRE_COMMIT) run -a golangci-lint: .gopathok varlink_generate .install.golangci-lint $(GOBIN)/golangci-lint run --tests=false --skip-files swagger.go diff --git a/contrib/gate/Dockerfile b/contrib/gate/Dockerfile index 1939d7ad1..d1e0b967b 100644 --- a/contrib/gate/Dockerfile +++ b/contrib/gate/Dockerfile @@ -48,6 +48,7 @@ WORKDIR $GOSRC RUN set -x && \ make install.tools && \ install -D -m 755 $GOSRC/contrib/gate/entrypoint.sh /usr/local/bin/ && \ + python3 -m pip install pre-commit && \ rm -rf "$GOSRC" # Install cni config diff --git a/contrib/snapcraft/.editorconfig b/contrib/snapcraft/.editorconfig index 1749b2d4c..89bc6dc80 100644 --- a/contrib/snapcraft/.editorconfig +++ b/contrib/snapcraft/.editorconfig @@ -14,4 +14,4 @@ indent_size = 2 end_of_line = lf charset = utf-8 trim_trailing_whitespace = true -insert_final_newline = true \ No newline at end of file +insert_final_newline = true diff --git a/docs/source/Commands.rst b/docs/source/Commands.rst index 276a9c4fb..028f03429 100644 --- a/docs/source/Commands.rst +++ b/docs/source/Commands.rst @@ -104,4 +104,4 @@ Commands :doc:`volume ` Manage volumes -:doc:`wait ` Block on one or more containers \ No newline at end of file +:doc:`wait ` Block on one or more containers diff --git a/docs/source/network.rst b/docs/source/network.rst index c1c53bc34..d96e00a7d 100644 --- a/docs/source/network.rst +++ b/docs/source/network.rst @@ -7,4 +7,4 @@ Network :doc:`ls ` network list -:doc:`rm ` network rm \ No newline at end of file +:doc:`rm ` network rm diff --git a/docs/source/volume.rst b/docs/source/volume.rst index 43fe87054..a966feafd 100644 --- a/docs/source/volume.rst +++ b/docs/source/volume.rst @@ -8,4 +8,4 @@ Volume :doc:`prune ` Remove all unused volumes -:doc:`rm ` Remove one or more volumes \ No newline at end of file +:doc:`rm ` Remove one or more volumes diff --git a/test/install/.gitignore b/test/install/.gitignore index 0a948f916..fc29e5c69 100644 --- a/test/install/.gitignore +++ b/test/install/.gitignore @@ -1 +1 @@ -rpms/ \ No newline at end of file +rpms/ diff --git a/test/install/README.md b/test/install/README.md index 21e5ab26d..7150314a6 100644 --- a/test/install/README.md +++ b/test/install/README.md @@ -8,4 +8,4 @@ make -f .copr/Makefile srpm outdir=test/install/rpms make -f .copr/Makefile build_binary outdir=test/install/rpms ``` -Then, run a container image build using the Dockerfiles in this directory. \ No newline at end of file +Then, run a container image build using the Dockerfiles in this directory. diff --git a/test/trust_set_test.json b/test/trust_set_test.json index 661e65922..f1fdf779c 100644 --- a/test/trust_set_test.json +++ b/test/trust_set_test.json @@ -5,4 +5,4 @@ } ], "transports": null -} \ No newline at end of file +} -- cgit v1.2.3-54-g00ecf