Skip to content

Commit

Permalink
feat(structslop): add support for structslop (#21)
Browse files Browse the repository at this point in the history
  • Loading branch information
adambabik authored Dec 31, 2021
1 parent bd69b81 commit 03770b1
Show file tree
Hide file tree
Showing 7 changed files with 120 additions and 0 deletions.
66 changes: 66 additions & 0 deletions .pre-commit-hooks.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -542,6 +542,72 @@
description: "Run 'staticcheck [$ARGS] ./...' in repo root folder"
pass_filenames: false

# ==============================================================================
# go-structslop-mod
# * Folder-Based
# * Recursive
# * Targets first parent folder with a go.mod file
# * Executes if any .go files modified
# * Executes if go.mod modified
# ==============================================================================
- id: go-structslop-mod
name: 'go-structslop-mod'
entry: go-structslop-mod.sh
files: '(\.go$)|(\bgo\.mod$)'
exclude: '(^|/)vendor/'
language: 'script'
description: "Run 'cd $(mod_root $FILE); structslop [$ARGS] ./...' for each staged .go file"
pass_filenames: true
require_serial: true

# ==============================================================================
# go-structslop-pkg
# * Folder-Based
# * Targets folder containing staged file
# * Executes if any .go files modified
# ==============================================================================
- id: go-structslop-pkg
name: 'go-structslop-pkg'
entry: go-structslop-pkg.sh
types: [go]
exclude: '(^|/)vendor/'
language: 'script'
description: "Run 'structslop [$ARGS] ./$(dirname $FILE)' for each staged .go file"
pass_filenames: true
require_serial: true

# ==============================================================================
# go-structslop-repo-mod
# * Repo-Based
# * Recursive
# * Targets ALL folders with a go.mod file
# * Executes if any .go files modified
# * Executes if go.mod modified
# ==============================================================================
- id: go-structslop-repo-mod
name: 'go-structslop-repo-mod'
entry: go-structslop-repo-mod.sh
files: '(\.go$)|(\bgo\.mod$)'
exclude: '(^|/)vendor/'
language: 'script'
description: "Run 'cd $(mod_root); structslop [$ARGS] ./...' for each module in the repo"
pass_filenames: false

# ==============================================================================
# go-structslop-repo-pkg
# * Repo-Based
# * Recursive
# * Executes if any .go files modified
# ==============================================================================
- id: go-structslop-repo-pkg
name: 'go-structslop-repo-pkg'
entry: go-structslop-repo-pkg.sh
types: [go]
exclude: '(^|/)vendor/'
language: 'script'
description: "Run 'structslop [$ARGS] ./...' in repo root folder"
pass_filenames: false

# ==============================================================================
# go-test-mod
# * Folder-Based
Expand Down
35 changes: 35 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,13 @@ You can copy/paste the following snippet into your `.pre-commit-config.yaml` fil
- id: go-staticcheck-repo-mod
- id: go-staticcheck-repo-pkg
#
# StructSlop
#
- id: go-structslop-mod
- id: go-structslop-pkg
- id: go-structslop-repo-mod
- id: go-structslop-repo-pkg
#
# Formatters
#
- id: go-fmt
Expand Down Expand Up @@ -265,6 +272,7 @@ This can be useful, for example, for hooks that display warnings, but don't gene
- [go-vet](#go-vet)
- [go-sec](#go-sec)
- [go-staticcheck](#go-staticcheck)
- [go-structslop](#go-structslop)
- Formatters
- [go-fmt](#go-fmt)
- [go-fumpt](#go-fumpt)
Expand Down Expand Up @@ -371,6 +379,33 @@ bingo install honnef.co/go/tools/cmd/staticcheck
- https://staticcheck.io/
- `staticcheck -h`
-----------------
### go-structslop
Recommends struct field rearrangements to provide for maximum space/allocation efficiency.
- Can modify files (see `-apply`)
| Hook ID | Description
|--------------------------|------------
| `go-structslop-mod` | Run `'cd $(mod_root $FILE); structslop [$ARGS] ./...'` for each staged .go file
| `go-structslop-pkg` | Run `'structslop [$ARGS] ./$(dirname $FILE)'` for each staged .go file
| `go-structslop-repo-mod` | Run `'cd $(mod_root); structslop [$ARGS] ./...'` for each module in the repo
| `go-structslop-repo-pkg` | Run `'structslop [$ARGS] ./...'` in repo root folder
##### Install (via [bingo](https://github.com/TekWizely/bingo))
```
bingo install github.com/orijtech/structslop/cmd/structslop
```
##### Useful Args
```
-apply : apply suggested fixes
```
##### Help
- https://github.com/orijtech/structslop#usage
- `structslop -h`
----------
### go-vet
Examines Go source code and reports suspicious constructs, such as
Expand Down
3 changes: 3 additions & 0 deletions go-structslop-mod.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/usr/bin/env bash
cmd=(structslop)
. "$(dirname "${0}")/lib/cmd-mod.bash"
3 changes: 3 additions & 0 deletions go-structslop-pkg.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/usr/bin/env bash
cmd=(structslop)
. "$(dirname "${0}")/lib/cmd-pkg.bash"
3 changes: 3 additions & 0 deletions go-structslop-repo-mod.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/usr/bin/env bash
cmd=(structslop)
. "$(dirname "${0}")/lib/cmd-repo-mod.bash"
3 changes: 3 additions & 0 deletions go-structslop-repo-pkg.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/usr/bin/env bash
cmd=(structslop)
. "$(dirname "${0}")/lib/cmd-repo-pkg.bash"
7 changes: 7 additions & 0 deletions sample-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,13 @@ repos:
- id: go-staticcheck-repo-mod
- id: go-staticcheck-repo-pkg
#
# StructSlop
#
- id: go-structslop-mod
- id: go-structslop-pkg
- id: go-structslop-repo-mod
- id: go-structslop-repo-pkg
#
# Formatters
#
- id: go-fmt
Expand Down

0 comments on commit 03770b1

Please sign in to comment.