Skip to content

Commit 4d78ac2

Browse files
authored
feat: Adds support for staticcheck (#18)
1 parent 1fde58e commit 4d78ac2

7 files changed

+114
-1
lines changed

.pre-commit-hooks.yaml

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -469,6 +469,72 @@
469469
description: "Run 'gosec [$ARGS] ./...' in repo root folder"
470470
pass_filenames: false
471471

472+
# ==============================================================================
473+
# go-staticcheck-mod
474+
# * Folder-Based
475+
# * Recursive
476+
# * Targets first parent folder with a go.mod file
477+
# * Executes if any .go files modified
478+
# * Executes if go.mod modified
479+
# ==============================================================================
480+
- id: go-staticcheck-mod
481+
name: 'go-staticcheck-mod'
482+
entry: go-staticcheck-mod.sh
483+
files: '(\.go$)|(\bgo\.mod$)'
484+
exclude: '(^|/)vendor/'
485+
language: 'script'
486+
description: "Run 'cd $(mod_root $FILE); staticcheck [$ARGS] ./...' for each staged .go file"
487+
pass_filenames: true
488+
require_serial: true
489+
490+
# ==============================================================================
491+
# go-staticcheck-pkg
492+
# * Folder-Based
493+
# * Targets folder containing staged file
494+
# * Executes if any .go files modified
495+
# ==============================================================================
496+
- id: go-staticcheck-pkg
497+
name: 'go-staticcheck-pkg'
498+
entry: go-staticcheck-pkg.sh
499+
types: [go]
500+
exclude: '(^|/)vendor/'
501+
language: 'script'
502+
description: "Run 'staticcheck [$ARGS] ./$(dirname $FILE)' for each staged .go file"
503+
pass_filenames: true
504+
require_serial: true
505+
506+
# ==============================================================================
507+
# go-staticcheck-repo-mod
508+
# * Repo-Based
509+
# * Recursive
510+
# * Targets ALL folders with a go.mod file
511+
# * Executes if any .go files modified
512+
# * Executes if go.mod modified
513+
# ==============================================================================
514+
- id: go-staticcheck-repo-mod
515+
name: 'go-staticcheck-repo-mod'
516+
entry: go-staticcheck-repo-mod.sh
517+
files: '(\.go$)|(\bgo\.mod$)'
518+
exclude: '(^|/)vendor/'
519+
language: 'script'
520+
description: "Run 'cd $(mod_root); staticcheck [$ARGS] ./...' for each module in the repo"
521+
pass_filenames: false
522+
523+
# ==============================================================================
524+
# go-staticcheck-repo-pkg
525+
# * Repo-Based
526+
# * Recursive
527+
# * Executes if any .go files modified
528+
# ==============================================================================
529+
- id: go-staticcheck-repo-pkg
530+
name: 'go-staticcheck-repo-pkg'
531+
entry: go-staticcheck-repo-pkg.sh
532+
types: [go]
533+
exclude: '(^|/)vendor/'
534+
language: 'script'
535+
description: "Run 'staticcheck [$ARGS] ./...' in repo root folder"
536+
pass_filenames: false
537+
472538
# ==============================================================================
473539
# go-test-mod
474540
# * Folder-Based

README.md

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,13 @@ You can copy/paste the following snippet into your `.pre-commit-config.yaml` fil
7272
- id: go-sec-repo-mod
7373
- id: go-sec-repo-pkg
7474
#
75+
# StaticCheck
76+
#
77+
- id: go-staticcheck-mod
78+
- id: go-staticcheck-pkg
79+
- id: go-staticcheck-repo-mod
80+
- id: go-staticcheck-repo-pkg
81+
#
7582
# Formatters
7683
#
7784
- id: go-fmt
@@ -257,6 +264,7 @@ This can be useful, for example, for hooks that display warnings, but don't gene
257264
- [go-test](#go-test)
258265
- [go-vet](#go-vet)
259266
- [go-sec](#go-sec)
267+
- [go-staticcheck](#go-staticcheck)
260268
- Formatters
261269
- [go-fmt](#go-fmt)
262270
- [go-fumpt](#go-fumpt)
@@ -323,7 +331,7 @@ Comes with Golang ( [golang.org](https://golang.org/) )
323331
- https://golang.org/cmd/go/#hdr-Test_packages
324332
- `go help test`
325333
326-
-----------
334+
----------
327335
### go-sec
328336
Inspects source code for security problems by scanning the Go AST.
329337
@@ -343,6 +351,26 @@ bingo install github.com/securego/gosec/v2/cmd/gosec
343351
- https://github.com/securego/gosec#usage
344352
- `gosec (no args)`
345353
354+
------------------
355+
### go-staticcheck
356+
A state of the art linter for the Go programming language. Using static analysis, it finds bugs and performance issues, offers simplifications, and enforces style rules.
357+
358+
| Hook ID | Description
359+
|---------------------------|------------
360+
| `go-staticcheck-mod` | Run `'cd $(mod_root $FILE); staticcheck [$ARGS] ./...'` for each staged .go file
361+
| `go-staticcheck-pkg` | Run `'staticcheck [$ARGS] ./$(dirname $FILE)'` for each staged .go file
362+
| `go-staticcheck-repo-mod` | Run `'cd $(mod_root); staticcheck [$ARGS] ./...'` for each module in the repo
363+
| `go-staticcheck-repo-pkg` | Run `'staticcheck [$ARGS] ./...'` in repo root folder
364+
365+
##### Install (via [bingo](https://github.com/TekWizely/bingo))
366+
```
367+
bingo install honnef.co/go/tools/cmd/staticcheck
368+
```
369+
370+
##### Help
371+
- https://staticcheck.io/
372+
- `staticcheck -h`
373+
346374
----------
347375
### go-vet
348376
Examines Go source code and reports suspicious constructs, such as

go-staticcheck-mod.sh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#!/usr/bin/env bash
2+
cmd=(staticcheck)
3+
. "$(dirname "${0}")/lib/cmd-mod.bash"

go-staticcheck-pkg.sh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#!/usr/bin/env bash
2+
cmd=(staticcheck)
3+
. "$(dirname "${0}")/lib/cmd-pkg.bash"

go-staticcheck-repo-mod.sh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#!/usr/bin/env bash
2+
cmd=(staticcheck)
3+
. "$(dirname "${0}")/lib/cmd-repo-mod.bash"

go-staticcheck-repo-pkg.sh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#!/usr/bin/env bash
2+
cmd=(staticcheck)
3+
. "$(dirname "${0}")/lib/cmd-repo-pkg.bash"

sample-config.yaml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,13 @@ repos:
120120
- id: go-sec-repo-mod
121121
- id: go-sec-repo-pkg
122122
#
123+
# StaticCheck
124+
#
125+
- id: go-staticcheck-mod
126+
- id: go-staticcheck-pkg
127+
- id: go-staticcheck-repo-mod
128+
- id: go-staticcheck-repo-pkg
129+
#
123130
# Formatters
124131
#
125132
- id: go-fmt

0 commit comments

Comments
 (0)