Skip to content

Commit 96509aa

Browse files
authored
feat: add golangci-lint configuration with pre-commit hooks to lint code (#116)
1 parent cdcfe25 commit 96509aa

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+148
-65
lines changed

.github/workflows/lint_pr_title.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,4 @@ jobs:
2121
steps:
2222
- uses: amannn/action-semantic-pull-request@e9fabac35e210fea40ca5b14c0da95a099eff26f # v5
2323
env:
24-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
24+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

.github/workflows/pr_ci.yml

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,18 @@ on:
1212
- ready_for_review
1313

1414
jobs:
15+
golangci:
16+
name: lint
17+
runs-on: ubuntu-latest
18+
steps:
19+
- uses: actions/checkout@v4
20+
- uses: actions/setup-go@v5
21+
with:
22+
go-version: stable
23+
- name: golangci-lint
24+
uses: golangci/golangci-lint-action@v6
25+
with:
26+
version: v1.59
1527
ci:
1628
name: Continuous integration
1729
runs-on: ubuntu-latest
@@ -21,15 +33,15 @@ jobs:
2133
- name: Set up Go
2234
uses: actions/setup-go@v5
2335
with:
24-
go-version: '1.21'
36+
go-version: "1.22"
2537

2638
- name: Download Go dependencies
2739
run: go get ./... && go mod tidy
2840

2941
- name: Check if all dependencies were commited
3042
shell: bash
3143
run: |
32-
if [ "$(git status --porcelain)" ]; then
44+
if [ "$(git status --porcelain)" ]; then
3345
git status
3446
exit 1
3547
else
@@ -51,7 +63,7 @@ jobs:
5163
- name: Set up Go
5264
uses: actions/setup-go@cdcb36043654635271a94b9a6d1392de5bb323a7 # v5
5365
with:
54-
go-version: '1.21'
66+
go-version: "1.22"
5567

5668
- name: Download Go dependencies
5769
run: go get ./... && go mod tidy

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,4 @@
1818
*.swp
1919

2020
# IDE
21-
.idea/
21+
.idea/

.golangci.yaml

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
linters:
2+
enable:
3+
- asasalint
4+
- copyloopvar
5+
- decorder
6+
- dogsled
7+
- errname
8+
- exhaustive
9+
- exportloopref
10+
- fatcontext
11+
- forcetypeassert
12+
- gci
13+
- ginkgolinter
14+
- gofmt
15+
- grouper
16+
- importas
17+
- makezero
18+
- nakedret
19+
- nilerr
20+
- nilnil
21+
- predeclared
22+
- sloglint
23+
#- wrapcheck # this one will be useful, but we have to fix a multitude of errors
24+
#- unparam # when fixed, probably already covered by revive/gocritic
25+
#- revive # too many errors, but useful, similar to gocritic, so probably choose one
26+
#- prealloc # enable when can
27+
#- nestif # enable once we clean up the code
28+
#- gofumpt # fix all files before we switch to gofumpt
29+
#- gocritic # too many failures for now
30+
#- goconst # once we rewrite string literals to consts
31+
#- gochecknoglobals # once we rewrite terraform codegen and drop global functions
32+
#- funlen # couple of functions over 60 lines
33+
#- err113 # disabled because of too many dynamic errors that don't wrap anything
34+
35+
linters-settings:
36+
gci:
37+
sections:
38+
- standard
39+
- default
40+
- prefix(github.com/paloaltonetworks/pan-os-codegen)
41+
issues:
42+
exclude-dirs:
43+
- generated/

.pre-commit-config.yaml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
repos:
2+
- repo: https://github.com/golangci/golangci-lint/
3+
rev: v1.59.1
4+
hooks:
5+
- id: golangci-lint
6+
- repo: https://github.com/pre-commit/pre-commit-hooks
7+
rev: v2.3.0
8+
hooks:
9+
- id: end-of-file-fixer
10+
- id: trailing-whitespace

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ The code have run login in `cmd/codegen` directory, to run it with default optio
3333
go run cmd/codegen/main.go
3434
```
3535
This command can be parametrizes using options:
36-
- `-t/-type` - operation type, default is to create both Terraform
36+
- `-t/-type` - operation type, default is to create both Terraform
3737
- `mktp` - create only Terraform provider
3838
- `mksdk` - create only PAN-OS SDK
3939
- `config` - specify path for the config file, default is `cmd/codegen/config.yaml`
@@ -47,4 +47,4 @@ example code:
4747
go run cmd/codegen/main.go -t mksdk
4848
cd ../generated/pango
4949
PANOS_HOSTNAME='***' PANOS_USERNAME='***' PANOS_PASSWORD='***' go run example/main.go
50-
```
50+
```

SUPPORT.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,4 @@ This template/script/solution is released “as-is”, with no warranty and no s
44
supported and Palo Alto Networks may contribute its expertise at its discretion. Palo Alto Networks, including through
55
its Authorized Support Centers (ASC) partners and backline support options, will not provide technical support or help
66
in using or troubleshooting this template/script/solution. The underlying product used by this template/script/solution
7-
will still be supported in accordance with the product’s applicable support policy and the customer’s entitlements.
7+
will still be supported in accordance with the product’s applicable support policy and the customer’s entitlements.

assets/pango/go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
module github.com/PaloAltoNetworks/pango
22

3-
go 1.21.4
3+
go 1.22
44

55
require (
66
github.com/onsi/ginkgo/v2 v2.19.0

assets/terraform/go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
module github.com/PaloAltoNetworks/terraform-provider-panos
22

3-
go 1.21.4
3+
go 1.22
44

55
require (
66
github.com/PaloAltoNetworks/pango v0.10.3-0.20240408115758-216d8509e7cf

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,4 @@ require (
1010
github.com/pmezard/go-difflib v1.0.0 // indirect
1111
)
1212

13-
go 1.21.4
13+
go 1.22.5

0 commit comments

Comments
 (0)