151 lines
3.8 KiB
Markdown
151 lines
3.8 KiB
Markdown
# Testing and linting
|
|
|
|
Project that is using these coding standards should be linted and tested on a regular basis.
|
|
|
|
## Linting
|
|
|
|
Linting should be done using [golangci-lint](https://github.com/golangci/golangci-lint) with configuration from repository.
|
|
|
|
If no configuration (`.golangci.yaml`) exists in project's repository, this file should be created with this content:
|
|
|
|
```yaml
|
|
---
|
|
version: "2"
|
|
linters:
|
|
default: all
|
|
disable:
|
|
- containedctx
|
|
- depguard
|
|
- exhaustruct
|
|
- funlen
|
|
- gochecknoglobals
|
|
- gocritic
|
|
- godot
|
|
- iface
|
|
- interfacebloat
|
|
- ireturn
|
|
- mnd
|
|
- paralleltest
|
|
- tagalign
|
|
- tagliatelle
|
|
- testpackage
|
|
- noinlineerr
|
|
- embeddedstructfieldcheck
|
|
- wsl # deprecated
|
|
- gomodguard # deprecated
|
|
- unqueryvet # we love SELECT * when working with databases
|
|
settings:
|
|
cyclop:
|
|
max-complexity: 25
|
|
dupl:
|
|
threshold: 400
|
|
forbidigo:
|
|
forbid:
|
|
- pattern: ^(fmt\.Print(|f|ln)|print|println)$
|
|
- pattern: ^time\.Now\(\)($|\.F|\.A|\.B|\.L|\.UTC\(\)\.I|,|\))(# Calls of time\.Now() without \.UTC() is prohibited\.)?
|
|
funcorder:
|
|
constructor: true
|
|
struct-method: true
|
|
alphabetical: true
|
|
gocyclo:
|
|
min-complexity: 40
|
|
govet:
|
|
enable-all: true
|
|
lll:
|
|
line-length: 120
|
|
perfsprint:
|
|
concat-loop: false
|
|
revive:
|
|
enable-all-rules: true
|
|
rules:
|
|
# This linter creates more problems than gives profits. Probably should be configured?
|
|
- name: add-constant
|
|
disabled: true
|
|
# gocognit
|
|
- name: cognitive-complexity
|
|
disabled: true
|
|
# gocyclo
|
|
- name: cyclomatic
|
|
disabled: true
|
|
- name: function-length
|
|
arguments: [200, 0]
|
|
- name: import-alias-naming
|
|
arguments:
|
|
- "^[a-z][a-zA-Z0-9]{0,}$"
|
|
- name: line-length-limit
|
|
disabled: true
|
|
- name: package-comments
|
|
disabled: true
|
|
- name: unused-receiver
|
|
disabled: true
|
|
- name: var-naming
|
|
arguments:
|
|
- ["ID"]
|
|
- ["VM"]
|
|
- - skipPackageNameChecks: true
|
|
- name: package-naming
|
|
disabled: true
|
|
wrapcheck:
|
|
ignore-sig-regexps:
|
|
- \.Write\(
|
|
- \.WriteString\(
|
|
- \.WriteJSON\(
|
|
- \.WriteHTML\(
|
|
- \.Redirect\(
|
|
- \.Error\(
|
|
wsl_v5:
|
|
allow-first-in-block: true
|
|
allow-whole-block: false
|
|
branch-max-lines: 2
|
|
exclusions:
|
|
generated: lax
|
|
presets:
|
|
- common-false-positives
|
|
- legacy
|
|
- std-error-handling
|
|
rules:
|
|
- linters:
|
|
- godox
|
|
text: TODO
|
|
- linters:
|
|
- gosec
|
|
text: G101
|
|
paths:
|
|
- third_party$
|
|
- builtin$
|
|
- examples$
|
|
issues:
|
|
max-issues-per-linter: 0
|
|
max-same-issues: 0
|
|
uniq-by-line: false
|
|
formatters:
|
|
enable:
|
|
- gofmt
|
|
- gofumpt
|
|
settings:
|
|
gofumpt:
|
|
module-path: REPLACEMEWITHGOMODMODULENAME
|
|
extra:
|
|
group-params: true
|
|
clothe-returns: true
|
|
balance-calls: true
|
|
exclusions:
|
|
generated: lax
|
|
paths:
|
|
- third_party$
|
|
- builtin$
|
|
- examples$
|
|
```
|
|
|
|
If this file exists, AI can only suggest changes to linters configuration and provide relevant diff but should never change this file on its own.
|
|
|
|
## Testing
|
|
|
|
Testing should be done using testify package: https://github.com/stretchr/testify. When possible, test suites should be used and tests (which launch test suites) should be parallelized.
|
|
|
|
Mocks, when necessary, should be generated with mockery package: https://github.com/vektra/mockery. For example, mockery can be used for:
|
|
|
|
- Mocking external API.
|
|
- Mocking storage layer.
|
|
- ...and for every external communication when data goes out of application's binary to other application.
|