Skip to content
This repository was archived by the owner on Oct 7, 2021. It is now read-only.

Commit 3584fcc

Browse files
committed
Initial commit of plugin-sdk for terraform-docs
Signed-off-by: Khosrow Moossavi <[email protected]>
1 parent a055b7e commit 3584fcc

25 files changed

+2004
-1
lines changed

.github/workflows/validate.yml

+102
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
name: validate
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
pull_request: {}
8+
workflow_dispatch: {}
9+
10+
env:
11+
GO_VERSION: '1.15'
12+
13+
jobs:
14+
verify:
15+
runs-on: ubuntu-latest
16+
if: "!contains(github.event.head_commit.message, '[ci skip]')"
17+
steps:
18+
- name: Set up Go
19+
uses: actions/setup-go@v2
20+
with:
21+
go-version: ${{ env.GO_VERSION }}
22+
id: go
23+
24+
- name: Check out code into the Go module directory
25+
uses: actions/checkout@v2
26+
27+
- name: Verify 'vendor' dependencies
28+
run: make vendor verify
29+
30+
checkfmt:
31+
runs-on: ubuntu-latest
32+
if: "!contains(github.event.head_commit.message, '[ci skip]')"
33+
steps:
34+
- name: Set up Go
35+
uses: actions/setup-go@v2
36+
with:
37+
go-version: ${{ env.GO_VERSION }}
38+
id: go
39+
40+
- name: Check out code into the Go module directory
41+
uses: actions/checkout@v2
42+
43+
- name: Check formatting of go files
44+
run: |
45+
export PATH=$PATH:$(go env GOPATH)/bin
46+
make goimports checkfmt
47+
48+
lint:
49+
runs-on: ubuntu-latest
50+
if: "!contains(github.event.head_commit.message, '[ci skip]')"
51+
steps:
52+
- name: Set up Go
53+
uses: actions/setup-go@v2
54+
with:
55+
go-version: ${{ env.GO_VERSION }}
56+
id: go
57+
58+
- name: Check out code into the Go module directory
59+
uses: actions/checkout@v2
60+
61+
- name: Run linters
62+
run: |
63+
export PATH=$PATH:$(go env GOPATH)/bin
64+
make golangci lint
65+
66+
staticcheck:
67+
runs-on: ubuntu-latest
68+
if: "!contains(github.event.head_commit.message, '[ci skip]')"
69+
steps:
70+
- name: Set up Go
71+
uses: actions/setup-go@v2
72+
with:
73+
go-version: ${{ env.GO_VERSION }}
74+
id: go
75+
76+
- name: Check out code into the Go module directory
77+
uses: actions/checkout@v2
78+
79+
- name: Run Staticcheck
80+
run: make staticcheck
81+
82+
test:
83+
runs-on: ubuntu-latest
84+
if: "!contains(github.event.head_commit.message, '[ci skip]')"
85+
steps:
86+
- name: Set up Go
87+
uses: actions/setup-go@v2
88+
with:
89+
go-version: ${{ env.GO_VERSION }}
90+
id: go
91+
92+
- name: Check out code into the Go module directory
93+
uses: actions/checkout@v2
94+
95+
- name: Run tests
96+
run: make test
97+
98+
- name: Upload coverage to Codecov
99+
uses: codecov/codecov-action@v1
100+
if: always()
101+
with:
102+
file: ./coverage.out

.gitignore

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# Binaries for programs and plugins
2+
*.exe
3+
*.exe~
4+
*.dll
5+
*.so
6+
*.dylib
7+
8+
# Test binary, built with `go test -c`
9+
*.test
10+
11+
# Output of the go coverage tool, specifically when used with LiteIDE
12+
*.out
13+
14+
# Dependency directories
15+
vendor/
16+
17+
# ignore GoLand files (debug config etc...)
18+
/.idea
19+
20+
# ignore vscode files (debug config etc...)
21+
/.vscode
22+
23+
# ignore asdf local versions
24+
/.tool-versions

.golangci.yml

+148
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,148 @@
1+
run:
2+
deadline: 5m
3+
4+
tests: true
5+
6+
linters-settings:
7+
govet:
8+
# report about shadowed variables
9+
check-shadowing: true
10+
11+
golint:
12+
# minimal confidence for issues, default is 0.8
13+
min-confidence: 0.8
14+
# min-confidence: 0
15+
16+
gofmt:
17+
# simplify code: gofmt with `-s` option, true by default
18+
simplify: true
19+
20+
goimports:
21+
# put imports beginning with prefix after 3rd-party packages;
22+
# it's a comma-separated list of prefixes
23+
local-prefixes: github.com/terraform-docs/plugin-sdk
24+
25+
gocyclo:
26+
# minimal code complexity to report, 30 by default (but we recommend 10-20)
27+
min-complexity: 10
28+
29+
maligned:
30+
# print struct with more effective memory layout or not, false by default
31+
suggest-new: true
32+
33+
dupl:
34+
# tokens count to trigger issue, 150 by default
35+
threshold: 100
36+
37+
goconst:
38+
# minimal length of string constant, 3 by default
39+
min-len: 3
40+
# min-len: 2
41+
# minimal occurrences count to trigger, 3 by default
42+
min-occurrences: 5
43+
# min-occurrences: 2
44+
45+
lll:
46+
# tab width in spaces. Default to 1.
47+
tab-width: 1
48+
49+
unused:
50+
# treat code as a program (not a library) and report unused exported identifiers; default is false.
51+
# XXX: if you enable this setting, unused will report a lot of false-positives in text editors:
52+
# if it's called for subdir of a project it can't find funcs usages. All text editor integrations
53+
# with golangci-lint call it on a directory with the changed file.
54+
check-exported: false
55+
56+
unparam:
57+
# Inspect exported functions, default is false. Set to true if no external program/library imports your code.
58+
# XXX: if you enable this setting, unparam will report a lot of false-positives in text editors:
59+
# if it's called for subdir of a project it can't find external interfaces. All text editor integrations
60+
# with golangci-lint call it on a directory with the changed file.
61+
check-exported: false
62+
63+
nakedret:
64+
# make an issue if func has more lines of code than this setting and it has naked returns; default is 30
65+
max-func-lines: 30
66+
67+
prealloc:
68+
# XXX: we don't recommend using this linter before doing performance profiling.
69+
# For most programs usage of prealloc will be a premature optimization.
70+
71+
# Report preallocation suggestions only on simple loops that have no returns/breaks/continues/gotos in them.
72+
# True by default.
73+
simple: true
74+
range-loops: true # Report preallocation suggestions on range loops, true by default
75+
for-loops: false # Report preallocation suggestions on for loops, false by default
76+
77+
gocritic:
78+
# Enable multiple checks by tags, run `GL_DEBUG=gocritic golangci-lint` run to see all tags and checks.
79+
# Empty list by default. See https://github.com/go-critic/go-critic#usage -> section "Tags".
80+
enabled-tags:
81+
- performance
82+
83+
settings: # settings passed to gocritic
84+
captLocal: # must be valid enabled check name
85+
paramsOnly: true
86+
rangeValCopy:
87+
sizeThreshold: 32
88+
89+
misspell:
90+
locale: US
91+
92+
linters:
93+
enable:
94+
- megacheck
95+
- govet
96+
- gocyclo
97+
- gocritic
98+
- interfacer
99+
- goconst
100+
- goimports
101+
- gofmt # We enable this as well as goimports for its simplify mode.
102+
- prealloc
103+
- golint
104+
- unconvert
105+
- misspell
106+
- nakedret
107+
108+
presets:
109+
- bugs
110+
- unused
111+
fast: false
112+
113+
issues:
114+
# Excluding configuration per-path and per-linter
115+
exclude-rules:
116+
# Exclude some linters from running on tests files.
117+
- path: _test(ing)?\.go
118+
linters:
119+
- gocyclo
120+
- errcheck
121+
- dupl
122+
- gosec
123+
- scopelint
124+
- unparam
125+
126+
# - text: "should have a package comment"
127+
# linters:
128+
# - golint
129+
130+
# Independently from option `exclude` we use default exclude patterns,
131+
# it can be disabled by this option. To list all
132+
# excluded by default patterns execute `golangci-lint run --help`.
133+
# Default value for this option is true.
134+
exclude-use-default: false
135+
136+
# Show only new issues: if there are unstaged changes or untracked files,
137+
# only those changes are analyzed, else only changes in HEAD~ are analyzed.
138+
# It's a super-useful option for integration of golangci-lint into existing
139+
# large codebase. It's not practical to fix all existing issues at the moment
140+
# of integration: much better don't allow issues in new code.
141+
# Default is false.
142+
new: false
143+
144+
# Maximum issues count per one linter. Set to 0 to disable. Default is 50.
145+
max-per-linter: 0
146+
147+
# Maximum count of issues with the same text. Set to 0 to disable. Default is 3.
148+
max-same-issues: 0

Makefile

+101
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
# Project variables
2+
PROJECT_NAME := plugin-sdk
3+
PROJECT_REPO := github.com/terraform-docs/$(PROJECT_NAME)
4+
DESCRIPTION := Plugin SDK for building custom formatter for terraform-docs
5+
LICENSE := Apache-2.0
6+
7+
# Build variables
8+
COVERAGE_OUT := coverage.out
9+
10+
# Go variables
11+
GO_PACKAGE_FILES := $(shell go list ./... | grep -v vendor/ | sed 's|$(PROJECT_REPO)/||')
12+
GOIMPORTS_LOCAL_ARG := -local $(PROJECT_REPO)
13+
14+
# Binary versions
15+
GOLANGCI_VERSION := v1.23.7
16+
17+
.PHONY: all
18+
all: clean verify checkfmt lint test
19+
20+
.PHONY: clean
21+
clean: ## Clean workspace
22+
@ $(MAKE) --no-print-directory log-$@
23+
rm -rf ./$(COVERAGE_OUT)
24+
25+
#########################
26+
## Development targets ##
27+
#########################
28+
.PHONY: checkfmt
29+
checkfmt: ## Check formatting of all go files
30+
@ $(MAKE) --no-print-directory log-$@
31+
@ if [ $$(goimports -l $(GOIMPORTS_LOCAL_ARG) $(GO_PACKAGE_FILES) | tee /dev/tty | grep -c ".go") = 0 ]; then \
32+
echo "OK" ; \
33+
else \
34+
exit 1 ; \
35+
fi
36+
37+
.PHONY: fmt
38+
fmt: ## Format all go files
39+
@ $(MAKE) --no-print-directory log-$@
40+
goimports -w $(GOIMPORTS_LOCAL_ARG) $(GO_PACKAGE_FILES)
41+
42+
.PHONY: lint
43+
lint: ## Run linter
44+
@ $(MAKE) --no-print-directory log-$@
45+
golangci-lint run ./...
46+
47+
.PHONY: staticcheck
48+
staticcheck: ## Run staticcheck
49+
@ $(MAKE) --no-print-directory log-$@
50+
go run honnef.co/go/tools/cmd/staticcheck -- ./...
51+
52+
.PHONY: test
53+
test: ## Run tests
54+
@ $(MAKE) --no-print-directory log-$@
55+
go test -coverprofile=$(COVERAGE_OUT) -covermode=atomic -v ./...
56+
57+
.PHONY: tidy
58+
tidy: ## Tidy 'vendor' dependencies
59+
@ $(MAKE) --no-print-directory log-$@
60+
go mod tidy
61+
62+
.PHONY: verify
63+
verify: ## Verify 'vendor' dependencies
64+
@ $(MAKE) --no-print-directory log-$@
65+
go mod verify
66+
67+
.PHONY: vendor
68+
vendor: ## Download 'vendor' dependencies
69+
@ $(MAKE) --no-print-directory log-$@
70+
go mod vendor
71+
72+
####################
73+
## Helper targets ##
74+
####################
75+
.PHONY: goimports
76+
goimports:
77+
ifeq (, $(shell which goimports))
78+
GO111MODULE=off go get -u golang.org/x/tools/cmd/goimports
79+
endif
80+
81+
.PHONY: golangci
82+
golangci:
83+
ifeq (, $(shell which golangci-lint))
84+
curl -sfL https://install.goreleaser.com/github.com/golangci/golangci-lint.sh | sh -s -- -b $(shell go env GOPATH)/bin $(GOLANGCI_VERSION)
85+
endif
86+
87+
.PHONY: tools
88+
tools: ## Install required tools
89+
@ $(MAKE) --no-print-directory log-$@
90+
@ $(MAKE) --no-print-directory goimports golangci
91+
92+
########################################################################
93+
## Self-Documenting Makefile Help ##
94+
## https://marmelab.com/blog/2016/02/29/auto-documented-makefile.html ##
95+
########################################################################
96+
.PHONY: help
97+
help:
98+
@ grep -h -E '^[a-zA-Z0-9_-]+:.*?## .*$$' $(MAKEFILE_LIST) | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-20s\033[0m %s\n", $$1, $$2}'
99+
100+
log-%:
101+
@ grep -h -E '^$*:.*?## .*$$' $(MAKEFILE_LIST) | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m==> %s\033[0m\n", $$2}'

README.md

+13-1
Original file line numberDiff line numberDiff line change
@@ -1 +1,13 @@
1-
# plugin-sdk
1+
# terraform-docs Plugin SDK
2+
3+
[![Build Status](https://github.com/terraform-docs/plugin-sdk/workflows/validate/badge.svg)](https://github.com/terraform-docs/plugin-sdk/actions) [![GoDoc](https://godoc.org/github.com/terraform-docs/plugin-sdk?status.svg)](https://godoc.org/github.com/terraform-docs/plugin-sdk) [![Go Report Card](https://goreportcard.com/badge/github.com/terraform-docs/plugin-sdk)](https://goreportcard.com/report/github.com/terraform-docs/plugin-sdk) [![Codecov Report](https://codecov.io/gh/terraform-docs/plugin-sdk/branch/main/graph/badge.svg)](https://codecov.io/gh/terraform-docs/plugin-sdk) [![License](https://img.shields.io/github/license/terraform-docs/plugin-sdk)](https://github.com/terraform-docs/plugin-sdk/blob/main/LICENSE)
4+
5+
[terraform-docs] plugin SDK for building custom formatters.
6+
7+
## Usage
8+
9+
Please refer to [tfdocs-format-template] for an example implementation of a
10+
formatter plugin with this SDK.
11+
12+
[terraform-docs]: https://github.com/terraform-docs/terraform-docs
13+
[tfdocs-format-template]: https://github.com/terraform-docs/tfdocs-format-template

0 commit comments

Comments
 (0)