Skip to content

Commit 5341f38

Browse files
authored
Add a golangci-lint hook (#93)
1 parent ae4a77b commit 5341f38

6 files changed

Lines changed: 35 additions & 6 deletions

File tree

.circleci/config.yml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,7 @@ jobs:
44
unit_test:
55
machine:
66
enabled: true
7-
image: ubuntu-2004:202111-02
8-
resource_class: small
7+
image: ubuntu-2204:2023.02.1
98
steps:
109
- checkout
1110
- run:
@@ -16,7 +15,6 @@ jobs:
1615
pip install tox
1716
tox
1817
19-
2018
workflows:
2119
version: 2
2220
test:

.pre-commit-hooks.yaml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,15 @@
7676
files: \.go$
7777
exclude: vendor\/.*$
7878

79+
- id: golangci-lint
80+
name: golangci-lint
81+
description: golangci-lint is a Go linters aggregator
82+
entry: hooks/golangci-lint.sh
83+
language: script
84+
language: script
85+
files: \.go$
86+
require_serial: true
87+
7988
- id: yapf
8089
name: yapf
8190
description: yapf (Yet Another Python Formatter) is a python formatter from Google

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@ supported hooks are:
1313
* **shellcheck**: Run [`shellcheck`](https://www.shellcheck.net/) to lint files that contain a bash [shebang](https://en.wikipedia.org/wiki/Shebang_(Unix)).
1414
* **gofmt**: Automatically run `gofmt` on all Golang code (`*.go` files).
1515
* **goimports**: Automatically run `goimports` on all Golang code (`*.go` files).
16-
* **golint**: Automatically run `golint` on all Golang code (`*.go` files).
16+
* **golint**: Automatically run `golint` on all Golang code (`*.go` files). [**DEPRECATED**]: Please use `golangci-lint` below.
17+
* **golangci-lint**: Automatically run `golangci-lint` on all Golang code (`*.go` files).
1718
* **yapf**: Automatically run [`yapf`](https://github.com/google/yapf) on all python code (`*.py` files).
1819
* **helmlint** Automatically run [`helm lint`](https://helm.sh/docs/helm/helm_lint/) on your Helm chart files. [See caveats here](#helm-lint-caveats).
1920
* **markdown-link-check** Automatically run [markdown-link-check](https://github.com/tcort/markdown-link-check) on

hooks/golangci-lint.sh

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#!/usr/bin/env bash
2+
3+
set -e
4+
5+
# OSX GUI apps do not pick up environment variables the same way as Terminal apps and there are no easy solutions,
6+
# especially as Apple changes the GUI app behavior every release (see https://stackoverflow.com/q/135688/483528). As a
7+
# workaround to allow GitHub Desktop to work, add this (hopefully harmless) setting here.
8+
original_path=$PATH
9+
export PATH=$PATH:/usr/local/bin
10+
11+
# Store and return last failure from fmt so this can validate every directory passed before exiting
12+
FMT_ERROR=0
13+
14+
for file in "$@"; do
15+
golangci-lint run --new-from-rev HEAD "$file" || FMT_ERROR=$?
16+
done
17+
18+
# reset path to the original value
19+
export PATH=$original_path
20+
21+
exit ${FMT_ERROR}

test/.python-version

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
2.7.18:3.9.7
1+
2.7.18:3.11.1

test/tox.ini

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[tox]
22
skipsdist = True
3-
envlist = py27,py39
3+
envlist = py27,py311
44

55
[testenv]
66
deps =

0 commit comments

Comments
 (0)