Skip to content

Commit

Permalink
Add a golangci-lint hook (#93)
Browse files Browse the repository at this point in the history
  • Loading branch information
robmorgan committed Mar 31, 2023
1 parent ae4a77b commit 5341f38
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 6 deletions.
4 changes: 1 addition & 3 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@ jobs:
unit_test:
machine:
enabled: true
image: ubuntu-2004:202111-02
resource_class: small
image: ubuntu-2204:2023.02.1
steps:
- checkout
- run:
Expand All @@ -16,7 +15,6 @@ jobs:
pip install tox
tox
workflows:
version: 2
test:
Expand Down
9 changes: 9 additions & 0 deletions .pre-commit-hooks.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,15 @@
files: \.go$
exclude: vendor\/.*$

- id: golangci-lint
name: golangci-lint
description: golangci-lint is a Go linters aggregator
entry: hooks/golangci-lint.sh
language: script
language: script
files: \.go$
require_serial: true

- id: yapf
name: yapf
description: yapf (Yet Another Python Formatter) is a python formatter from Google
Expand Down
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ supported hooks are:
* **shellcheck**: Run [`shellcheck`](https://www.shellcheck.net/) to lint files that contain a bash [shebang](https://en.wikipedia.org/wiki/Shebang_(Unix)).
* **gofmt**: Automatically run `gofmt` on all Golang code (`*.go` files).
* **goimports**: Automatically run `goimports` on all Golang code (`*.go` files).
* **golint**: Automatically run `golint` on all Golang code (`*.go` files).
* **golint**: Automatically run `golint` on all Golang code (`*.go` files). [**DEPRECATED**]: Please use `golangci-lint` below.
* **golangci-lint**: Automatically run `golangci-lint` on all Golang code (`*.go` files).
* **yapf**: Automatically run [`yapf`](https://github.com/google/yapf) on all python code (`*.py` files).
* **helmlint** Automatically run [`helm lint`](https://helm.sh/docs/helm/helm_lint/) on your Helm chart files. [See caveats here](#helm-lint-caveats).
* **markdown-link-check** Automatically run [markdown-link-check](https://github.com/tcort/markdown-link-check) on
Expand Down
21 changes: 21 additions & 0 deletions hooks/golangci-lint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#!/usr/bin/env bash

set -e

# OSX GUI apps do not pick up environment variables the same way as Terminal apps and there are no easy solutions,
# especially as Apple changes the GUI app behavior every release (see https://stackoverflow.com/q/135688/483528). As a
# workaround to allow GitHub Desktop to work, add this (hopefully harmless) setting here.
original_path=$PATH
export PATH=$PATH:/usr/local/bin

# Store and return last failure from fmt so this can validate every directory passed before exiting
FMT_ERROR=0

for file in "$@"; do
golangci-lint run --new-from-rev HEAD "$file" || FMT_ERROR=$?
done

# reset path to the original value
export PATH=$original_path

exit ${FMT_ERROR}
2 changes: 1 addition & 1 deletion test/.python-version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
2.7.18:3.9.7
2.7.18:3.11.1
2 changes: 1 addition & 1 deletion test/tox.ini
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tox]
skipsdist = True
envlist = py27,py39
envlist = py27,py311

[testenv]
deps =
Expand Down

0 comments on commit 5341f38

Please sign in to comment.