Skip to content
This repository was archived by the owner on Jan 2, 2025. It is now read-only.

Commit 0553757

Browse files
authored
chore: add githook and fix ci (#36)
1 parent 0f488e1 commit 0553757

File tree

11 files changed

+244
-116
lines changed

11 files changed

+244
-116
lines changed

.github/labeler.yml

-44
This file was deleted.

.github/workflows/issue-triage.yml

-10
This file was deleted.

.github/workflows/lint.yml

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
name: Lint
2+
3+
# This GitHub action runs your tests for each pull request and push.
4+
# Optionally, you can turn it on using a schedule for regular testing.
5+
on:
6+
pull_request:
7+
branches:
8+
- main
9+
paths:
10+
- '**.go'
11+
12+
# Testing only needs permissions to read the repository contents.
13+
permissions:
14+
contents: read
15+
16+
jobs:
17+
lint:
18+
name: Lint
19+
runs-on: ubuntu-latest
20+
timeout-minutes: 5
21+
steps:
22+
- uses: actions/checkout@v3
23+
- uses: actions/setup-go@v4
24+
with:
25+
go-version-file: 'go.mod'
26+
cache: true
27+
- run: go mod download
28+
- name: Run linters
29+
uses: golangci/golangci-lint-action@v3
30+
with:
31+
version: latest

.github/workflows/pr-triage.yml

-43
This file was deleted.

.gitmodules

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[submodule "githooks"]
2+
path = githooks
3+
url = https://github.com/FrangipaneTeam/githooks

.golangci.yml

+178
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,178 @@
1+
# Visit https://golangci-lint.run/ for usage documentation
2+
# and information on other useful linters
3+
issues:
4+
max-per-linter: 0
5+
max-same-issues: 0
6+
7+
linters:
8+
enable:
9+
- asciicheck # Simple linter to check that your code does not contain non-ASCII identifiers [fast: true, auto-fix: false]
10+
- bidichk # Checks for dangerous unicode character sequences [fast: true, auto-fix: false]
11+
- decorder # check declaration order and count of types, constants, variables and functions [fast: true, auto-fix: false]
12+
- dogsled # Checks assignments with too many blank identifiers (e.g. x, _, _, _, := f()) [fast: true, auto-fix: false]
13+
- durationcheck # check for two durations multiplied together [fast: false, auto-fix: false]
14+
- errcheck # Errcheck is a program for checking for unchecked errors in go programs. These unchecked errors can be critical bugs in some cases [fast: false, auto-fix: false]
15+
- errchkjson # Checks types passed to the json encoding functions. Reports unsupported types and optionally reports occasions, where the check for the returned error can be omitted. [fast: false, auto-fix: false]
16+
- errname # Checks that sentinel errors are prefixed with the `Err` and error types are suffixed with the `Error`. [fast: false, auto-fix: false]
17+
- execinquery # execinquery is a linter about query string checker in Query function which reads your Go src files and warning it finds [fast: false, auto-fix: false]
18+
- exportloopref # checks for pointers to enclosing loop variables [fast: false, auto-fix: false]
19+
- forbidigo # Forbids identifiers [fast: true, auto-fix: false]
20+
- gci # Gci controls golang package import order and makes it always deterministic. [fast: true, auto-fix: false]
21+
- goconst # Finds repeated strings that could be replaced by a constant [fast: true, auto-fix: false]
22+
- gocritic # Provides diagnostics that check for bugs, performance and style issues. [fast: false, auto-fix: false]
23+
- gocyclo # Computes and checks the cyclomatic complexity of functions [fast: true, auto-fix: false]
24+
- gofmt # Gofmt checks whether code was gofmt-ed. By default this tool runs with -s option to check for code simplification [fast: true, auto-fix: true]
25+
- goheader # Checks is file header matches to pattern [fast: true, auto-fix: false]
26+
- gofumpt # Gofumpt checks whether code was gofumpt-ed. [fast: true, auto-fix: true]
27+
- gomoddirectives # Manage the use of 'replace', 'retract', and 'excludes' directives in go.mod. [fast: true, auto-fix: false]
28+
- gomodguard # Allow and block list linter for direct Go module dependencies. This is different from depguard where there are different block types for example version constraints and module recommendations. [fast: true, auto-fix: false]
29+
- goprintffuncname # Checks that printf-like functions are named with `f` at the end [fast: true, auto-fix: false]
30+
- gosec #(gas): Inspects source code for security problems [fast: false, auto-fix: false]
31+
- gosimple #(megacheck): Linter for Go source code that specializes in simplifying a code [fast: false, auto-fix: false]
32+
- govet #(vet, vetshadow): Vet examines Go source code and reports suspicious constructs, such as Printf calls whose arguments do not align with the format string [fast: false, auto-fix: false]
33+
- grouper # An analyzer to analyze expression groups. [fast: true, auto-fix: false]
34+
- ifshort # Checks that your code uses short syntax for if-statements whenever possible [fast: true, auto-fix: false]
35+
- importas # Enforces consistent import aliases [fast: false, auto-fix: false]
36+
- ineffassign # Detects when assignments to existing variables are not used [fast: true, auto-fix: false]
37+
- makezero # Finds slice declarations with non-zero initial length [fast: false, auto-fix: false]
38+
- misspell # Finds commonly misspelled English words in comments [fast: true, auto-fix: true]
39+
- nilerr # Finds the code that returns nil even if it checks that the error is not nil. [fast: false, auto-fix: false]
40+
- noctx # noctx finds sending http request without context.Context [fast: false, auto-fix: false]
41+
- nolintlint # Reports ill-formed or insufficient nolint directives [fast: true, auto-fix: false]
42+
- nosprintfhostport # Checks for misuse of Sprintf to construct a host with port in a URL. [fast: true, auto-fix: false]
43+
- predeclared # find code that shadows one of Go's predeclared identifiers [fast: true, auto-fix: false]
44+
- promlinter # Check Prometheus metrics naming via promlint [fast: true, auto-fix: false]
45+
- revive # Fast, configurable, extensible, flexible, and beautiful linter for Go. Drop-in replacement of golint. [fast: false, auto-fix: false]
46+
- rowserrcheck # checks whether Err of rows is checked successfully [fast: false, auto-fix: false]
47+
- sqlclosecheck # Checks that sql.Rows and sql.Stmt are closed. [fast: false, auto-fix: false]
48+
- stylecheck # Stylecheck is a replacement for golint [fast: false, auto-fix: false]
49+
- tagliatelle # Checks the struct tags. [fast: true, auto-fix: false]
50+
- tenv # tenv is analyzer that detects using os.Setenv instead of t.Setenv since Go1.17 [fast: false, auto-fix: false]
51+
- tparallel # tparallel detects inappropriate usage of t.Parallel() method in your Go test codes [fast: false, auto-fix: false]
52+
- typecheck # Like the front-end of a Go compiler, parses and type-checks Go code [fast: false, auto-fix: false]
53+
- unconvert # Remove unnecessary type conversions [fast: false, auto-fix: false]
54+
- wastedassign # wastedassign finds wasted assignment statements. [fast: false, auto-fix: false]
55+
- whitespace # Tool for detection of leading and trailing whitespace [fast: true, auto-fix: true]
56+
- errorlint # errorlint is a linter for that can be used to find code that will cause problems with the error wrapping scheme introduced in Go 1.13. [fast: false, auto-fix: false]
57+
- nilnil # Checks that there is no simultaneous return of `nil` error and an invalid value. [fast: false, auto-fix: false]
58+
- godot # Check if comments end in a period [fast: true, auto-fix: true]
59+
- unused #(megacheck): Checks Go code for unused constants, variables, functions and types [fast: false, auto-fix: false]
60+
- unparam # reports unused function parameters
61+
- staticcheck #(megacheck): Staticcheck is a go vet on steroids, applying a ton of static analysis checks [fast: false, auto-fix: false]
62+
- bodyclose # checks whether HTTP response body is closed successfully
63+
64+
disable:
65+
- dupl # Tool for code clone detection [fast: true, auto-fix: false]
66+
- varcheck # Finds unused global variables and constants [fast: false, auto-fix: false]
67+
- deadcode # Finds unused code [fast: false, auto-fix: false]
68+
- structcheck # Finds unused struct fields [fast: false, auto-fix: false]
69+
- nakedret # Finds naked returns in functions greater than a specified function length [fast: true, auto-fix: false]
70+
- depguard # Go linter that checks if package imports are in a list of acceptable packages [fast: true, auto-fix: false]
71+
- goimports # In addition to fixing imports, goimports also formats your code in the same style as gofmt. [fast: true, auto-fix: true]
72+
- containedctx # containedctx is a linter that detects struct contained context.Context field [fast: true, auto-fix: false]
73+
- thelper # thelper detects golang test helpers without t.Helper() call and checks the consistency of test helpers [fast: false, auto-fix: false]
74+
- cyclop # checks function and package cyclomatic complexity [fast: false, auto-fix: false]
75+
- exhaustive # check exhaustiveness of enum switch statements [fast: false, auto-fix: false]
76+
- funlen # Tool for detection of long functions [fast: true, auto-fix: false]
77+
- gochecknoglobals # check that no global variables exist [fast: true, auto-fix: false]
78+
- gochecknoinits # Checks that no init functions are present in Go code [fast: true, auto-fix: false]
79+
- gocognit # Computes and checks the cognitive complexity of functions [fast: true, auto-fix: false]
80+
- godox # Tool for detection of FIXME, TODO and other comment keywords [fast: true, auto-fix: false]
81+
- goerr113 # Golang linter to check the errors handling expressions [fast: false, auto-fix: false]
82+
- gomnd # An analyzer to detect magic numbers. [fast: true, auto-fix: false]
83+
- lll # Reports long lines [fast: true, auto-fix: false]
84+
- maintidx # maintidx measures the maintainability index of each function. [fast: true, auto-fix: false]
85+
- nestif # Reports deeply nested if statements [fast: true, auto-fix: false]
86+
- nlreturn # nlreturn checks for a new line before return and branch statements to increase code clarity [fast: true, auto-fix: false]
87+
- varnamelen # checks that the length of a variable's name matches its scope [fast: false, auto-fix: false]
88+
- wrapcheck # Checks that errors returned from external packages are wrapped [fast: false, auto-fix: false]
89+
- wsl # Whitespace Linter - Forces you to use empty lines! [fast: true, auto-fix: false]
90+
91+
linters-settings:
92+
goimports:
93+
local-prefixes: github.com/FrangipaneTeam/tf-doc-extractor
94+
95+
gci:
96+
# Section configuration to compare against.
97+
# Section names are case-insensitive and may contain parameters in ().
98+
# The default order of sections is `standard > default > custom > blank > dot`,
99+
# If `custom-order` is `true`, it follows the order of `sections` option.
100+
# Default: ["standard", "default"]
101+
sections:
102+
- standard # Standard section: captures all standard packages.
103+
- default # Default section: contains all imports that could not be matched to another section type.
104+
- prefix(github.com/FrangipaneTeam)
105+
- prefix(github.com/FrangipaneTeam/tf-doc-extractor)
106+
- blank # Blank section: contains all blank imports. This section is not present unless explicitly enabled.
107+
- dot # Dot section: contains all dot imports. This section is not present unless explicitly enabled.
108+
skip-generated: true
109+
custom-order: true
110+
111+
gofumpt:
112+
# Module path which contains the source code being formatted.
113+
# Default: ""
114+
module-path: github.com/FrangipaneTeam/tf-doc-extractor
115+
# Choose whether to use the extra rules.
116+
# Default: false
117+
extra-rules: true
118+
119+
revive:
120+
revive:
121+
ignore-generated-header: true
122+
severity: error
123+
rules:
124+
- name: exported
125+
severity: warning
126+
disabled: false
127+
- name: indent-error-flow
128+
severity: warning
129+
disabled: false
130+
- name: var-naming
131+
severity: warning
132+
disabled: false
133+
arguments:
134+
# List Bypass rules
135+
- []
136+
# List force rules
137+
- [
138+
# Default rules
139+
"ACL",
140+
"API",
141+
"ASCII",
142+
"CPU",
143+
"CSS",
144+
"DNS",
145+
"EOF",
146+
"GUID",
147+
"HTML",
148+
"HTTP",
149+
"HTTPS",
150+
"ID",
151+
"IP",
152+
"JSON",
153+
"LHS",
154+
"QPS",
155+
"RAM",
156+
"RHS",
157+
"RPC",
158+
"SLA",
159+
"SMTP",
160+
"SQL",
161+
"SSH",
162+
"TCP",
163+
"TLS",
164+
"TTL",
165+
"UDP",
166+
"UI",
167+
"UID",
168+
"UUID",
169+
"URI",
170+
"URL",
171+
"UTF8",
172+
"VM",
173+
"XML",
174+
"XMPP",
175+
"XSRF",
176+
"XSS",
177+
# Custom rules
178+
]

Makefile

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
default: build
2+
3+
build:
4+
go build -v ./...
5+
6+
lint:
7+
golangci-lint run
8+
9+
fmt:
10+
gofmt -s -w -e .
11+
12+
test:
13+
go test -v -cover -timeout=120s -parallel=4 ./...
14+
15+
submodules:
16+
@git submodule sync
17+
@git submodule update --init --recursive
18+
@git config core.hooksPath githooks
19+
@git config submodule.recurse true
20+
21+
.PHONY: build lint fmt test submodules

githooks

Submodule githooks added at 113e3c9

internal/example/example.go

+4-10
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import (
1111
"github.com/hashicorp/hcl/v2/hclwrite"
1212

1313
"github.com/FrangipaneTeam/terraform-templates/pkg/file"
14+
1415
"github.com/FrangipaneTeam/tf-doc-extractor/internal/format"
1516
"github.com/FrangipaneTeam/tf-doc-extractor/internal/logger"
1617
)
@@ -59,8 +60,6 @@ func genExampleFromTest(str, tfType string) (string, string) {
5960
// check for doc end
6061
if endDoc.MatchString(line) {
6162
logger.Logger.Info().Msgf("found end doc: %s", line)
62-
startFound = false
63-
endFound = true
6463
break
6564
}
6665
if startFound {
@@ -107,14 +106,9 @@ func CreateExampleFile(fileName, exampleDir string) error {
107106
doc = strings.TrimSpace(doc)
108107

109108
exampleDirPath := exampleDir + "/" + tfType + "s/" + tfName
110-
errMkdir := os.MkdirAll(exampleDirPath, 0o755)
111-
if errMkdir != nil {
112-
return errMkdir
109+
if err := os.MkdirAll(exampleDirPath, 0o755); err != nil {
110+
return err
113111
}
114112

115-
errWrite := os.WriteFile(exampleDirPath+"/"+tfType+".tf", []byte(doc), 0o644)
116-
if errWrite != nil {
117-
return errWrite
118-
}
119-
return nil
113+
return os.WriteFile(exampleDirPath+"/"+tfType+".tf", []byte(doc), 0o644) //nolint:gosec
120114
}

internal/example/import.go

+1-6
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@ func genExampleFromResource(str string) (string, string) {
4040
}
4141

4242
func getCategoryFromBase(resourceFile string) string {
43-
4443
categoryNameRe := regexp.MustCompile(`categoryName = "(\S+)"`)
4544
categoryName := ""
4645

@@ -93,9 +92,5 @@ func CreateImportExampleFile(fileName, exampleDir string) error {
9392
doc := fmt.Sprintf("# use the %s to import the resource\n", importName)
9493
doc += fmt.Sprintf("terraform import cloudavenue_%s_%s.example %s", categoryName, tfName, importName)
9594

96-
errWrite := os.WriteFile(exampleDirPath+"/import.sh", []byte(doc), 0o644)
97-
if errWrite != nil {
98-
return errWrite
99-
}
100-
return nil
95+
return os.WriteFile(exampleDirPath+"/import.sh", []byte(doc), 0o644) //nolint:gosec
10196
}

0 commit comments

Comments
 (0)