Skip to content

Commit 03770b1

Browse files
authored
feat(structslop): add support for structslop (#21)
Learn More: * https://github.com/orijtech/structslop Co-Authors: * Adam Babik : https://github.com/adambabik * TekWizely : https://github.com/TekWizely
1 parent bd69b81 commit 03770b1

File tree

7 files changed

+120
-0
lines changed

7 files changed

+120
-0
lines changed

.pre-commit-hooks.yaml

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -542,6 +542,72 @@
542542
description: "Run 'staticcheck [$ARGS] ./...' in repo root folder"
543543
pass_filenames: false
544544

545+
# ==============================================================================
546+
# go-structslop-mod
547+
# * Folder-Based
548+
# * Recursive
549+
# * Targets first parent folder with a go.mod file
550+
# * Executes if any .go files modified
551+
# * Executes if go.mod modified
552+
# ==============================================================================
553+
- id: go-structslop-mod
554+
name: 'go-structslop-mod'
555+
entry: go-structslop-mod.sh
556+
files: '(\.go$)|(\bgo\.mod$)'
557+
exclude: '(^|/)vendor/'
558+
language: 'script'
559+
description: "Run 'cd $(mod_root $FILE); structslop [$ARGS] ./...' for each staged .go file"
560+
pass_filenames: true
561+
require_serial: true
562+
563+
# ==============================================================================
564+
# go-structslop-pkg
565+
# * Folder-Based
566+
# * Targets folder containing staged file
567+
# * Executes if any .go files modified
568+
# ==============================================================================
569+
- id: go-structslop-pkg
570+
name: 'go-structslop-pkg'
571+
entry: go-structslop-pkg.sh
572+
types: [go]
573+
exclude: '(^|/)vendor/'
574+
language: 'script'
575+
description: "Run 'structslop [$ARGS] ./$(dirname $FILE)' for each staged .go file"
576+
pass_filenames: true
577+
require_serial: true
578+
579+
# ==============================================================================
580+
# go-structslop-repo-mod
581+
# * Repo-Based
582+
# * Recursive
583+
# * Targets ALL folders with a go.mod file
584+
# * Executes if any .go files modified
585+
# * Executes if go.mod modified
586+
# ==============================================================================
587+
- id: go-structslop-repo-mod
588+
name: 'go-structslop-repo-mod'
589+
entry: go-structslop-repo-mod.sh
590+
files: '(\.go$)|(\bgo\.mod$)'
591+
exclude: '(^|/)vendor/'
592+
language: 'script'
593+
description: "Run 'cd $(mod_root); structslop [$ARGS] ./...' for each module in the repo"
594+
pass_filenames: false
595+
596+
# ==============================================================================
597+
# go-structslop-repo-pkg
598+
# * Repo-Based
599+
# * Recursive
600+
# * Executes if any .go files modified
601+
# ==============================================================================
602+
- id: go-structslop-repo-pkg
603+
name: 'go-structslop-repo-pkg'
604+
entry: go-structslop-repo-pkg.sh
605+
types: [go]
606+
exclude: '(^|/)vendor/'
607+
language: 'script'
608+
description: "Run 'structslop [$ARGS] ./...' in repo root folder"
609+
pass_filenames: false
610+
545611
# ==============================================================================
546612
# go-test-mod
547613
# * Folder-Based

README.md

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,13 @@ You can copy/paste the following snippet into your `.pre-commit-config.yaml` fil
7979
- id: go-staticcheck-repo-mod
8080
- id: go-staticcheck-repo-pkg
8181
#
82+
# StructSlop
83+
#
84+
- id: go-structslop-mod
85+
- id: go-structslop-pkg
86+
- id: go-structslop-repo-mod
87+
- id: go-structslop-repo-pkg
88+
#
8289
# Formatters
8390
#
8491
- id: go-fmt
@@ -265,6 +272,7 @@ This can be useful, for example, for hooks that display warnings, but don't gene
265272
- [go-vet](#go-vet)
266273
- [go-sec](#go-sec)
267274
- [go-staticcheck](#go-staticcheck)
275+
- [go-structslop](#go-structslop)
268276
- Formatters
269277
- [go-fmt](#go-fmt)
270278
- [go-fumpt](#go-fumpt)
@@ -371,6 +379,33 @@ bingo install honnef.co/go/tools/cmd/staticcheck
371379
- https://staticcheck.io/
372380
- `staticcheck -h`
373381
382+
-----------------
383+
### go-structslop
384+
Recommends struct field rearrangements to provide for maximum space/allocation efficiency.
385+
386+
- Can modify files (see `-apply`)
387+
388+
| Hook ID | Description
389+
|--------------------------|------------
390+
| `go-structslop-mod` | Run `'cd $(mod_root $FILE); structslop [$ARGS] ./...'` for each staged .go file
391+
| `go-structslop-pkg` | Run `'structslop [$ARGS] ./$(dirname $FILE)'` for each staged .go file
392+
| `go-structslop-repo-mod` | Run `'cd $(mod_root); structslop [$ARGS] ./...'` for each module in the repo
393+
| `go-structslop-repo-pkg` | Run `'structslop [$ARGS] ./...'` in repo root folder
394+
395+
##### Install (via [bingo](https://github.com/TekWizely/bingo))
396+
```
397+
bingo install github.com/orijtech/structslop/cmd/structslop
398+
```
399+
400+
##### Useful Args
401+
```
402+
-apply : apply suggested fixes
403+
```
404+
405+
##### Help
406+
- https://github.com/orijtech/structslop#usage
407+
- `structslop -h`
408+
374409
----------
375410
### go-vet
376411
Examines Go source code and reports suspicious constructs, such as

go-structslop-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=(structslop)
3+
. "$(dirname "${0}")/lib/cmd-mod.bash"

go-structslop-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=(structslop)
3+
. "$(dirname "${0}")/lib/cmd-pkg.bash"

go-structslop-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=(structslop)
3+
. "$(dirname "${0}")/lib/cmd-repo-mod.bash"

go-structslop-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=(structslop)
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
@@ -127,6 +127,13 @@ repos:
127127
- id: go-staticcheck-repo-mod
128128
- id: go-staticcheck-repo-pkg
129129
#
130+
# StructSlop
131+
#
132+
- id: go-structslop-mod
133+
- id: go-structslop-pkg
134+
- id: go-structslop-repo-mod
135+
- id: go-structslop-repo-pkg
136+
#
130137
# Formatters
131138
#
132139
- id: go-fmt

0 commit comments

Comments
 (0)