Skip to content

Commit

Permalink
feat(hooks): add gomarkdoc local hook (#5)
Browse files Browse the repository at this point in the history
* feat(hooks): add gomarkdoc local hook

* docs: document gomarkdoc, add license
  • Loading branch information
shakefu authored Sep 17, 2021
1 parent 8679887 commit be3e0b3
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 1 deletion.
6 changes: 6 additions & 0 deletions .pre-commit-hooks.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -77,3 +77,9 @@
entry: hooks/golang/golangci-lint.sh
language: script
files: \.go$
- id: gomarkdoc
name: "gomarkdoc: Create autogenerated documentation files"
description: "Runs `gomarkdoc` to create a README.md for each package"
entry: hooks/golang/gomarkdoc.sh
language: script
files: \.go$
7 changes: 6 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ open source projects.
- [hadolint/hadolint](https://github.com/hadolint/hadolint) - [GPLv3](https://github.com/hadolint/hadolint/blob/master/LICENSE)
- [fzipp/gocyclo](https://github.com/fzipp/gocyclo) - [BSD](https://github.com/fzipp/gocyclo/blob/main/LICENSE)
- [dnephin/pre-commit-golang](https://github.com/dnephin/pre-commit-golang) - [MIT](https://github.com/dnephin/pre-commit-golang/blob/master/LICENSE)

- [princjef/gomarkdoc](https://github.com/princjef/gomarkdoc)

## Installation

Expand All @@ -31,6 +31,7 @@ be installed](https://golang.org/doc/install) to run successfully:
- go-mod-tidy
- go-vet
- go-fmt
- gomarkdoc

The remaining hooks all run in containers, so require [Docker
installed](https://docs.docker.com/get-docker/) to run successfully:
Expand All @@ -55,6 +56,7 @@ repos:
- id: go-mod-tidy
- id: go-vet
- id: go-fmt
- id: gomarkdoc
- id: gocyclo
- id: goimports
- id: gofmt
Expand Down Expand Up @@ -84,6 +86,7 @@ The following hooks are available:
- **go-mod-tidy** (_requires golang_) - Clean up `go.mod` and `go.sum`
- **go-vet** (_requires golang_) - Additional checks not performed by compilation
- **go-fmt** (_requires golang_) - Original style formatter, local version
- **gomarkdoc** (_requires golang, gomarkdoc_) - Generate documentation from packages

**Docker**

Expand All @@ -104,6 +107,7 @@ repos:
- id: go-build # Check compilation
- id: golangci-lint # Lint everything
- id: go-test-unit # Run unit tests
- id: gomarkdoc # Generate documenation
```

## Contributing
Expand Down Expand Up @@ -166,3 +170,4 @@ For changes, see the
- https://medium.com/analytics-vidhya/dockerizing-a-rest-api-in-python-less-than-9-mb-and-based-on-scratch-image-ef0ee3ad3f0a
- https://goinbigdata.com/goimports-vs-gofmt/
- https://github.com/JonathonReinhart/staticx

8 changes: 8 additions & 0 deletions hooks/golang/gomarkdoc.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/bin/dash
#
# Capture and print stdout, since gofmt doesn't use proper exit codes
#
set -e

output="$(gomarkdoc --output '{{.Dir}}/README.md' ./...)"
[ -z "$output" ]
21 changes: 21 additions & 0 deletions licenses/MIT-gomarkdoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2019 Jeff Principe

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

0 comments on commit be3e0b3

Please sign in to comment.