Skip to content

Commit

Permalink
feat: add separate config (#8)
Browse files Browse the repository at this point in the history
Signed-off-by: tkrop <[email protected]>
  • Loading branch information
tkrop authored Jan 4, 2024
1 parent 0e3e8d1 commit 288bf43
Show file tree
Hide file tree
Showing 9 changed files with 1,756 additions and 0 deletions.
8 changes: 8 additions & 0 deletions config/.codacy.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
engines:
duplication:
minTokenMatch: 50
exclude_paths:
- "**/*_test.go"
revive:
exclude_paths:
- "**/mock_*_test.go"
12 changes: 12 additions & 0 deletions config/.gitleaks.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
[extend]
useDefault = true

[allowlist]
description = "Allowlist false positives"
regexTarget = "match"
regexes = [
# Mark CDP build secret_version as false positive since it does not contain a secret.
'''(?i)(?:secret_version:)(?:['|\"|\s]{0,5})([0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12})(?:['|\"|\n|\r|\s]{0,5}|$)''',
# Mark api-id or api_id or x-api-id as false positive since they are uuids that are used in OAS and stacksets to track apis.
'''(?i)(?:api[_-]id(?:['|\"|\s|:]{0,5}))(?:['|\"|\s]{0,5})([0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12})(?:['|\"|\n|\r|\s]{0,5}|$)'''
]
201 changes: 201 additions & 0 deletions config/.golangci.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,201 @@
run:
# Timeout for analysis, e.g. 30s, 5m.
# Default: 1m
timeout: 3m

linters: {}
# Placeholder for dynamically enabled linters.

issues:
# Maximum count of issues with the same text.
# Set to 0 to disable.
# Default: 3 (we recommend 10-20)
max-same-issues: 10

# Use default exclusions for common false positives as defined in
# https://golangci-lint.run/usage/false-positives/#default-exclusions
# Default: true (we use false to sync behavior with Codacy)
exclude-use-default: false

# Defining manually exclusions that make sense.
exclude-rules:
# Exclude go:generate directives from line length checking.
- source: "^//\\s*go:generate\\s"
linters: [ lll, revive ]
# Exclude magic number in time setups and bit shifting.
- source: "[0-9]+ ?\\* ?time\\.|(<<|>>) ?[0-9]+|[0-9]+ ?(<<|>>)"
linters: [ gomnd ]
# Exclude certain standards from being applied in test.
- path: "_test\\.go"
linters: [ bodyclose, contextcheck, dupl, funlen, goconst, gosec, noctx,
goerr113, wrapcheck ]

# Exclude error return value check because of too many false positives.
- text: 'Error return value of .((os\.)?std(out|err)\..*|.*Close|.*Flush|os\.Remove(All)?|.*print(f|ln)?|os\.(Un)?Setenv). is not checked'
linters: [ errcheck ]
# Exclude certain revive standards from being applied in tests.
- path: "_test\\.go"
text: "^(max-public-structs|function-length|cognitive-complexity):"
linters: [ revive ]
# Exclude dots in unfinished thoughts.
- source: "(noinspection|TODO)"
linters: [ godot ]


# This contains only configs which differ from defaults. For other configs see
# https://github.com/golangci/golangci-lint/blob/master/.golangci.reference.yml
linters-settings:
cyclop:
# The maximal code complexity to report.
# Default: 10 (we allow up to 20)
max-complexity: 20
# The maximal average package complexity.
# If it's higher than 0.0 (float) the check is enabled
# Default: 0.0 (we recommend 10.0 as baseline)
package-average: 10.0

gocognit:
# Minimal code complexity to report.
# Default: 30 (we recommend 10-20)
min-complexity: 20

lll:
# Max line length, lines longer will be reported. '\t' is counted as 1
# character by default, and can be changed with the tab-width option.
# Default: 120 (we recommend 80 but compromise at 100)
line-length: 100
# Tab width in spaces.
# Default: 1 (go uses 4 for visualization)
tab-width: 4

nolintlint:
# Exclude following linters from requiring an explanation.
# Default: [] (but some lll does not need explanation)
allow-no-explanation: [ lll, wrapcheck ]
# Enable to require an explanation of nonzero length after each nolint
# directive.
# Default: false
require-explanation: true
# Enable to require nolint directives to mention the specific linter being
# suppressed.
# Default: false
require-specific: true

govet:
# Enable all analyzers.
# Default: false
enable-all: true
# Disable analyzers by name.
# Run `go tool vet help` to see all analyzers.
# Default: []
disable:
- fieldalignment # too strict
- shadow # too strict to always work around

gosec:
# To specify a set of rules to explicitly exclude.
# Available rules: https://github.com/securego/gosec#available-rules
# Default: [] (issues are fixed)
excludes: [ G307 ]

gocritic:
# Settings passed to gocritic. The settings key is the name of a supported
# gocritic checker. The list of supported checkers can be find in
# https://go-critic.github.io/overview.
settings:
captLocal:
# Whether to restrict checker to params only.
# Default: true
paramsOnly: false
underef:
# Whether to skip (*x).method() calls where x is a pointer receiver.
# Default: true
skipRecvDeref: false

tenv:
# The option `all` will run the linter on the whole test files regardless
# of method signatures. Otherwise, only methods that take `*testing.T`,
# `*testing.B`, and `testing.TB` as arguments are checked.
# Default: false
all: true

revive:
# Enable all available rules.
# Default: false
enable-all-rules: true
# When set to false, ignores files with "GENERATED" header, similar to golint.
# See https://github.com/mgechev/revive#available-rules for details.
# Default: false
ignore-generated-header: true
# Sets the default severity.
# See https://github.com/mgechev/revive#configuration
# Default: warning
severity: error

rules:
# No need to enforce a file header.
- name: file-header
disabled: true
# Reports on each file in a package.
- name: package-comments
disabled: true
# Reports on comments not matching the name as first word.
- name: exported
disabled: true
# Ident error flow is buggy and throws false alerts.
- name: indent-error-flow
disabled: true
# No need to exclude import shadowing.
- name: import-shadowing
disabled: true
# Restricted alias naming conflicts with '.'-imports.
- name: import-alias-naming
disabled: true
# Exluding '.'-import makes test package separation unnecessary difficult.
- name: dot-imports
disabled: true
# Fails to exclude nolint directives from reporting.
- name: comment-spacings
disabled: true
# Fails to disable writers that actually cannot return errors.
- name: unhandled-error
disabled: true
# Fails to detect and exclude type safe usages of type assertions.
- name: unchecked-type-assertion
disabled: true
# Fails to restrict sufficiently in switches with numeric values.
- name: add-constant
disabled: true
# Rule prevents intentional usage of similar variable names.
- name: flag-parameter
disabled: true
# Rule prevents intentional usage of similar private method names.
- name: confusing-naming
disabled: true

# Enables a more experienced cyclomatic complexity (we enabled a lot of
# rules to counter-act the complexity trap).
- name: cyclomatic
arguments: [20]
# Enables a more experienced cognitive complexity (we enabled a lot of
# rules to counter-act the complexity trap).
- name: cognitive-complexity
arguments: [20]
# Limit line-length to increase readability.
- name: line-length-limit
arguments: [100]
# We are a bit more relaxed with function length consistent with funlen.
- name: function-length
arguments: [40, 60]
# Limit arguments of functions to the maximum understandable value.
- name: argument-limit
arguments: [6]
# Limit results of functions to the maximum understandable value.
- name: function-result-limit
arguments: [4]
# Raise the limit a bit to allow more complex package models.
- name: max-public-structs
arguments: [8]
# I do not know what I'm doing here...
- name: banned-characters
arguments: ["Ω", "Σ", "σ"]
35 changes: 35 additions & 0 deletions config/.markdownlint.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# Default state for all rules
default: true

# MD012/no-multiple-blanks - Multiple consecutive blank lines
MD012:
# Consecutive blank lines
maximum: 3

# MD013/line-length - Line length
MD013:
# Number of characters
line_length: 80
# Number of characters for headings
heading_line_length: 80
# Number of characters for code blocks
code_block_line_length: 80
# Include code blocks
code_blocks: true
# Include tables
tables: true
# Include headings
headings: true
# Include headings
headers: true
# Strict length checking
strict: true
# Stern length checking
stern: false

# MD022/blanks-around-headings/blanks-around-headers - Headings should be surrounded by blank lines
MD022:
# Blank lines above heading
lines_above: 2
# Blank lines below heading
lines_below: 1
21 changes: 21 additions & 0 deletions config/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
SHELL := /bin/bash

# Include custom variables to modify behavior.
ifneq ("$(wildcard Makefile.vars)","")
include Makefile.vars
else
$(warning warning: please customize variables in Makefile.vars)
endif

GOBIN ?= $(shell go env GOPATH)/bin
GOMAKE ?= github.com/tkrop/[email protected]
TARGETS := $(shell command -v go-make >/dev/null || \
go install $(GOMAKE) && go-make targets)

# Declare all targets phony to make them available for auto-completion.
.PHONY: $(TARGETS)

# Delegate all targets to go-make in a single call suppressing other targets.
$(eval $(wordlist 1,$(words $(MAKECMDGOALS)),$(MAKECMDGOALS))::;@:)
$(firstword $(MAKECMDGOALS) all)::
$(GOBIN)/go-make $(MAKEFLAGS) $(MAKECMDGOALS);
Loading

0 comments on commit 288bf43

Please sign in to comment.