Skip to content

Commit

Permalink
Merge pull request #29 from mineiros-io/thiesen/add-terradoc
Browse files Browse the repository at this point in the history
feat: add terradoc
  • Loading branch information
soerenmartius authored Apr 5, 2022
2 parents ac23228 + 03b12e8 commit 4f7c07d
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 3 deletions.
21 changes: 21 additions & 0 deletions .pre-commit-hooks.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -115,3 +115,24 @@
.+\.vendor\/.*$|
.+\.terraform\/.*$|
)$
# ---------------------------------------------------------------------------------------------------------------------
# Terradoc specific hooks
# ---------------------------------------------------------------------------------------------------------------------

- id: terradoc-fmt
name: Terradoc fmt
description: The terradoc fmt command is used to rewrite Terradoc input files to a canonical format and style. This command applies a subset of the Terraform language style conventions, along with other minor adjustments for readability similarly to the corresponding terraform hook.
entry: pre_commit_hooks/terradoc/fmt.sh
language: script
args:
- README.tfdoc.hcl

- id: terradoc-generate
name: Terradoc generate
description: The terradoc generate command is used to generate documentation files from a Terradoc input file.
entry: pre_commit_hooks/terradoc/generate.sh
language: script
args:
- README.tfdoc.hcl
- README.md
16 changes: 13 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,9 @@ Currently, the following hooks are supported:
It's fast: on average 5 times faster than gometalinter. It's easy to integrate and use, has nice output and has a
minimum number of false positives. An example configuration can be found in
[.golangci.example.yml](https://github.com/mineiros-io/pre-commit-hooks/blob/master/.golangci.example.yml).

#### The following hooks can be configured through golangci-lint and are therefore redundant when golangci-lint is being used

- [gofmt](https://golang.org/cmd/gofmt/): Go fmt is a tool that automatically formats Go `*.go` files to canonical
format and style.
- [goimports](https://godoc.org/golang.org/x/tools/cmd/goimports): The goimports command updates import lines in Go
Expand All @@ -74,6 +74,13 @@ Currently, the following hooks are supported:
- [shellcheck](https://github.com/koalaman/shellcheck): ShellCheck is a GPLv3 tool that gives warnings and suggestions
for bash/sh shell scripts.

### Terradoc

- terradoc-fmt: The terradoc fmt command is used to rewrite
Terradoc configuration `*tfdoc.hcl` files to a canonical format and style.
- terradoc-generate: The terradoc generates a documentation file from
Terradoc configuration `*tfdoc.hcl` files

## Installation & Dependencies

1. Install [pre-commit](https://pre-commit.com/). E.g. `brew install pre-commit`
Expand All @@ -87,7 +94,8 @@ Currently, the following hooks are supported:
go \
golangci/tap/golangci-lint \
shellcheck && \
npm install -g markdown-link-check
npm install -g markdown-link-check && \
go install github.com/mineiros-io/terradoc/cmd/terradoc@latest
```

## Usage
Expand All @@ -108,6 +116,8 @@ repos:
- id: markdown-link-check
args: [-p] # When adding the -p flag, markdown-link-check will always with an exit code 0, even if dead links are found
- id: shellcheck
- id: terradoc-fmt
- id: terradoc-generate

# The following hooks are redundant when golangci-lint is being. Our recommendation is to use golangci-lint
# as the main linter for go since it enables you to run all available linters in parallel.
Expand Down
11 changes: 11 additions & 0 deletions pre_commit_hooks/terradoc/fmt.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/usr/bin/env bash

set -e

if ! command -v terradoc >/dev/null 2>&1; then
echo >&2 "terradoc is not available on this system."
echo >&2 "Please install it by running 'go install github.com/mineiros-io/terradoc/cmd/terradoc@latest'"
exit 1
fi

terradoc fmt $1 -w
11 changes: 11 additions & 0 deletions pre_commit_hooks/terradoc/generate.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/usr/bin/env bash

set -e

if ! command -v terradoc >/dev/null 2>&1; then
echo >&2 "terradoc is not available on this system."
echo >&2 "Please install it by running 'go install github.com/mineiros-io/terradoc/cmd/terradoc@latest'"
exit 1
fi

terradoc generate $1 -o $2

0 comments on commit 4f7c07d

Please sign in to comment.