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

Commit

Permalink
chore: add githook and fix ci (#36)
Browse files Browse the repository at this point in the history
  • Loading branch information
azrod authored Aug 30, 2023
1 parent 0f488e1 commit 0553757
Show file tree
Hide file tree
Showing 11 changed files with 244 additions and 116 deletions.
44 changes: 0 additions & 44 deletions .github/labeler.yml

This file was deleted.

10 changes: 0 additions & 10 deletions .github/workflows/issue-triage.yml

This file was deleted.

31 changes: 31 additions & 0 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
name: Lint

# This GitHub action runs your tests for each pull request and push.
# Optionally, you can turn it on using a schedule for regular testing.
on:
pull_request:
branches:
- main
paths:
- '**.go'

# Testing only needs permissions to read the repository contents.
permissions:
contents: read

jobs:
lint:
name: Lint
runs-on: ubuntu-latest
timeout-minutes: 5
steps:
- uses: actions/checkout@v3
- uses: actions/setup-go@v4
with:
go-version-file: 'go.mod'
cache: true
- run: go mod download
- name: Run linters
uses: golangci/golangci-lint-action@v3
with:
version: latest
43 changes: 0 additions & 43 deletions .github/workflows/pr-triage.yml

This file was deleted.

3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[submodule "githooks"]
path = githooks
url = https://github.com/FrangipaneTeam/githooks
178 changes: 178 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,178 @@
# Visit https://golangci-lint.run/ for usage documentation
# and information on other useful linters
issues:
max-per-linter: 0
max-same-issues: 0

linters:
enable:
- asciicheck # Simple linter to check that your code does not contain non-ASCII identifiers [fast: true, auto-fix: false]
- bidichk # Checks for dangerous unicode character sequences [fast: true, auto-fix: false]
- decorder # check declaration order and count of types, constants, variables and functions [fast: true, auto-fix: false]
- dogsled # Checks assignments with too many blank identifiers (e.g. x, _, _, _, := f()) [fast: true, auto-fix: false]
- durationcheck # check for two durations multiplied together [fast: false, auto-fix: false]
- 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]
- 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]
- errname # Checks that sentinel errors are prefixed with the `Err` and error types are suffixed with the `Error`. [fast: false, auto-fix: false]
- 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]
- exportloopref # checks for pointers to enclosing loop variables [fast: false, auto-fix: false]
- forbidigo # Forbids identifiers [fast: true, auto-fix: false]
- gci # Gci controls golang package import order and makes it always deterministic. [fast: true, auto-fix: false]
- goconst # Finds repeated strings that could be replaced by a constant [fast: true, auto-fix: false]
- gocritic # Provides diagnostics that check for bugs, performance and style issues. [fast: false, auto-fix: false]
- gocyclo # Computes and checks the cyclomatic complexity of functions [fast: true, auto-fix: false]
- 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]
- goheader # Checks is file header matches to pattern [fast: true, auto-fix: false]
- gofumpt # Gofumpt checks whether code was gofumpt-ed. [fast: true, auto-fix: true]
- gomoddirectives # Manage the use of 'replace', 'retract', and 'excludes' directives in go.mod. [fast: true, auto-fix: false]
- 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]
- goprintffuncname # Checks that printf-like functions are named with `f` at the end [fast: true, auto-fix: false]
- gosec #(gas): Inspects source code for security problems [fast: false, auto-fix: false]
- gosimple #(megacheck): Linter for Go source code that specializes in simplifying a code [fast: false, auto-fix: false]
- 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]
- grouper # An analyzer to analyze expression groups. [fast: true, auto-fix: false]
- ifshort # Checks that your code uses short syntax for if-statements whenever possible [fast: true, auto-fix: false]
- importas # Enforces consistent import aliases [fast: false, auto-fix: false]
- ineffassign # Detects when assignments to existing variables are not used [fast: true, auto-fix: false]
- makezero # Finds slice declarations with non-zero initial length [fast: false, auto-fix: false]
- misspell # Finds commonly misspelled English words in comments [fast: true, auto-fix: true]
- nilerr # Finds the code that returns nil even if it checks that the error is not nil. [fast: false, auto-fix: false]
- noctx # noctx finds sending http request without context.Context [fast: false, auto-fix: false]
- nolintlint # Reports ill-formed or insufficient nolint directives [fast: true, auto-fix: false]
- nosprintfhostport # Checks for misuse of Sprintf to construct a host with port in a URL. [fast: true, auto-fix: false]
- predeclared # find code that shadows one of Go's predeclared identifiers [fast: true, auto-fix: false]
- promlinter # Check Prometheus metrics naming via promlint [fast: true, auto-fix: false]
- revive # Fast, configurable, extensible, flexible, and beautiful linter for Go. Drop-in replacement of golint. [fast: false, auto-fix: false]
- rowserrcheck # checks whether Err of rows is checked successfully [fast: false, auto-fix: false]
- sqlclosecheck # Checks that sql.Rows and sql.Stmt are closed. [fast: false, auto-fix: false]
- stylecheck # Stylecheck is a replacement for golint [fast: false, auto-fix: false]
- tagliatelle # Checks the struct tags. [fast: true, auto-fix: false]
- tenv # tenv is analyzer that detects using os.Setenv instead of t.Setenv since Go1.17 [fast: false, auto-fix: false]
- tparallel # tparallel detects inappropriate usage of t.Parallel() method in your Go test codes [fast: false, auto-fix: false]
- typecheck # Like the front-end of a Go compiler, parses and type-checks Go code [fast: false, auto-fix: false]
- unconvert # Remove unnecessary type conversions [fast: false, auto-fix: false]
- wastedassign # wastedassign finds wasted assignment statements. [fast: false, auto-fix: false]
- whitespace # Tool for detection of leading and trailing whitespace [fast: true, auto-fix: true]
- 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]
- nilnil # Checks that there is no simultaneous return of `nil` error and an invalid value. [fast: false, auto-fix: false]
- godot # Check if comments end in a period [fast: true, auto-fix: true]
- unused #(megacheck): Checks Go code for unused constants, variables, functions and types [fast: false, auto-fix: false]
- unparam # reports unused function parameters
- staticcheck #(megacheck): Staticcheck is a go vet on steroids, applying a ton of static analysis checks [fast: false, auto-fix: false]
- bodyclose # checks whether HTTP response body is closed successfully

disable:
- dupl # Tool for code clone detection [fast: true, auto-fix: false]
- varcheck # Finds unused global variables and constants [fast: false, auto-fix: false]
- deadcode # Finds unused code [fast: false, auto-fix: false]
- structcheck # Finds unused struct fields [fast: false, auto-fix: false]
- nakedret # Finds naked returns in functions greater than a specified function length [fast: true, auto-fix: false]
- depguard # Go linter that checks if package imports are in a list of acceptable packages [fast: true, auto-fix: false]
- goimports # In addition to fixing imports, goimports also formats your code in the same style as gofmt. [fast: true, auto-fix: true]
- containedctx # containedctx is a linter that detects struct contained context.Context field [fast: true, auto-fix: false]
- thelper # thelper detects golang test helpers without t.Helper() call and checks the consistency of test helpers [fast: false, auto-fix: false]
- cyclop # checks function and package cyclomatic complexity [fast: false, auto-fix: false]
- exhaustive # check exhaustiveness of enum switch statements [fast: false, auto-fix: false]
- funlen # Tool for detection of long functions [fast: true, auto-fix: false]
- gochecknoglobals # check that no global variables exist [fast: true, auto-fix: false]
- gochecknoinits # Checks that no init functions are present in Go code [fast: true, auto-fix: false]
- gocognit # Computes and checks the cognitive complexity of functions [fast: true, auto-fix: false]
- godox # Tool for detection of FIXME, TODO and other comment keywords [fast: true, auto-fix: false]
- goerr113 # Golang linter to check the errors handling expressions [fast: false, auto-fix: false]
- gomnd # An analyzer to detect magic numbers. [fast: true, auto-fix: false]
- lll # Reports long lines [fast: true, auto-fix: false]
- maintidx # maintidx measures the maintainability index of each function. [fast: true, auto-fix: false]
- nestif # Reports deeply nested if statements [fast: true, auto-fix: false]
- nlreturn # nlreturn checks for a new line before return and branch statements to increase code clarity [fast: true, auto-fix: false]
- varnamelen # checks that the length of a variable's name matches its scope [fast: false, auto-fix: false]
- wrapcheck # Checks that errors returned from external packages are wrapped [fast: false, auto-fix: false]
- wsl # Whitespace Linter - Forces you to use empty lines! [fast: true, auto-fix: false]

linters-settings:
goimports:
local-prefixes: github.com/FrangipaneTeam/tf-doc-extractor

gci:
# Section configuration to compare against.
# Section names are case-insensitive and may contain parameters in ().
# The default order of sections is `standard > default > custom > blank > dot`,
# If `custom-order` is `true`, it follows the order of `sections` option.
# Default: ["standard", "default"]
sections:
- standard # Standard section: captures all standard packages.
- default # Default section: contains all imports that could not be matched to another section type.
- prefix(github.com/FrangipaneTeam)
- prefix(github.com/FrangipaneTeam/tf-doc-extractor)
- blank # Blank section: contains all blank imports. This section is not present unless explicitly enabled.
- dot # Dot section: contains all dot imports. This section is not present unless explicitly enabled.
skip-generated: true
custom-order: true

gofumpt:
# Module path which contains the source code being formatted.
# Default: ""
module-path: github.com/FrangipaneTeam/tf-doc-extractor
# Choose whether to use the extra rules.
# Default: false
extra-rules: true

revive:
revive:
ignore-generated-header: true
severity: error
rules:
- name: exported
severity: warning
disabled: false
- name: indent-error-flow
severity: warning
disabled: false
- name: var-naming
severity: warning
disabled: false
arguments:
# List Bypass rules
- []
# List force rules
- [
# Default rules
"ACL",
"API",
"ASCII",
"CPU",
"CSS",
"DNS",
"EOF",
"GUID",
"HTML",
"HTTP",
"HTTPS",
"ID",
"IP",
"JSON",
"LHS",
"QPS",
"RAM",
"RHS",
"RPC",
"SLA",
"SMTP",
"SQL",
"SSH",
"TCP",
"TLS",
"TTL",
"UDP",
"UI",
"UID",
"UUID",
"URI",
"URL",
"UTF8",
"VM",
"XML",
"XMPP",
"XSRF",
"XSS",
# Custom rules
]
21 changes: 21 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
default: build

build:
go build -v ./...

lint:
golangci-lint run

fmt:
gofmt -s -w -e .

test:
go test -v -cover -timeout=120s -parallel=4 ./...

submodules:
@git submodule sync
@git submodule update --init --recursive
@git config core.hooksPath githooks
@git config submodule.recurse true

.PHONY: build lint fmt test submodules
1 change: 1 addition & 0 deletions githooks
Submodule githooks added at 113e3c
14 changes: 4 additions & 10 deletions internal/example/example.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"github.com/hashicorp/hcl/v2/hclwrite"

"github.com/FrangipaneTeam/terraform-templates/pkg/file"

"github.com/FrangipaneTeam/tf-doc-extractor/internal/format"
"github.com/FrangipaneTeam/tf-doc-extractor/internal/logger"
)
Expand Down Expand Up @@ -59,8 +60,6 @@ func genExampleFromTest(str, tfType string) (string, string) {
// check for doc end
if endDoc.MatchString(line) {
logger.Logger.Info().Msgf("found end doc: %s", line)
startFound = false
endFound = true
break
}
if startFound {
Expand Down Expand Up @@ -107,14 +106,9 @@ func CreateExampleFile(fileName, exampleDir string) error {
doc = strings.TrimSpace(doc)

exampleDirPath := exampleDir + "/" + tfType + "s/" + tfName
errMkdir := os.MkdirAll(exampleDirPath, 0o755)
if errMkdir != nil {
return errMkdir
if err := os.MkdirAll(exampleDirPath, 0o755); err != nil {
return err
}

errWrite := os.WriteFile(exampleDirPath+"/"+tfType+".tf", []byte(doc), 0o644)
if errWrite != nil {
return errWrite
}
return nil
return os.WriteFile(exampleDirPath+"/"+tfType+".tf", []byte(doc), 0o644) //nolint:gosec
}
7 changes: 1 addition & 6 deletions internal/example/import.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ func genExampleFromResource(str string) (string, string) {
}

func getCategoryFromBase(resourceFile string) string {

categoryNameRe := regexp.MustCompile(`categoryName = "(\S+)"`)
categoryName := ""

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

errWrite := os.WriteFile(exampleDirPath+"/import.sh", []byte(doc), 0o644)
if errWrite != nil {
return errWrite
}
return nil
return os.WriteFile(exampleDirPath+"/import.sh", []byte(doc), 0o644) //nolint:gosec
}
Loading

0 comments on commit 0553757

Please sign in to comment.