Skip to content

Commit 928f6ee

Browse files
committed
Configure linters
Adds .golangci.yaml file that defines linters used used on the codebase Signed-off-by: Veronika Fuxova <[email protected]>
1 parent ad3cc24 commit 928f6ee

File tree

2 files changed

+112
-1
lines changed

2 files changed

+112
-1
lines changed

.golangci.yaml

+106
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
run:
2+
timeout: 5m
3+
linters:
4+
enable:
5+
# region General
6+
7+
# Add depguard to prevent adding additional dependencies.
8+
- depguard
9+
# Prevent improper directives in go.mod.
10+
- gomoddirectives
11+
# Prevent improper nolint directives.
12+
- nolintlint
13+
14+
# endregion
15+
16+
17+
# region Code Quality and Comments
18+
19+
# Inspect source code for potential security problems. This check has a fairly high false positive rate,
20+
# comment with //nolint:gosec where not relevant.
21+
- gosec
22+
# Replaces deprecated golint.
23+
- revive
24+
# Complain about deeply nested if cases.
25+
- nestif
26+
# Prevent naked returns in long functions.
27+
- nakedret
28+
# Make Go code more readable.
29+
- gocritic
30+
# Check for global variables.
31+
- gochecknoglobals
32+
# Check if comments end in a period. This helps prevent incomplete comment lines, such as half-written sentences.
33+
- godot
34+
# Complain about comments as these indicate incomplete code.
35+
- godox
36+
# Keep the cyclomatic complexity of functions to a reasonable level.
37+
- gocyclo
38+
# Complain about cognitive complexity of functions.
39+
- gocognit
40+
# Find repeated strings that could be converted into constants.
41+
- goconst
42+
# Complain about unnecessary type conversions.
43+
- unconvert
44+
# Complain about unused parameters. These should be replaced with underscores.
45+
- unparam
46+
# Check for non-ASCII identifiers.
47+
- asciicheck
48+
# Check for HTTP response body being closed. Sometimes, you may need to disable this using //nolint:bodyclose.
49+
- bodyclose
50+
# Check for duplicate code. You may want to disable this with //nolint:dupl if the source code is the same, but
51+
# legitimately exists for different reasons.
52+
- dupl
53+
# Check for pointers in loops. This is a typical bug source.
54+
- exportloopref
55+
# Enforce a reasonable function length of 60 lines or 40 instructions. In very rare cases you may want to disable
56+
# this with //nolint:funlen if there is absolutely no way to split the function in question.
57+
- funlen
58+
# Prevent dogsledding (mass-ignoring return values). This typically indicates missing error handling.
59+
- dogsled
60+
# Enforce consistent import aliases across all files.
61+
- importas
62+
# Make package imports always deterministic.
63+
- gci
64+
# Make code properly formatted.
65+
- gofmt
66+
# Prevent faulty error checks.
67+
- nilerr
68+
# Prevent direct error checks that won't work with wrapped errors.
69+
- errorlint
70+
# Find slice usage that could potentially be preallocated.
71+
- prealloc
72+
# Check for improper duration handling.
73+
- durationcheck
74+
# Enforce tests being in the _test package.
75+
- testpackage
76+
# Check for magic numbers
77+
- gomnd
78+
# Check that errors returned from external packages are wrapped.
79+
- wrapcheck
80+
81+
# endregion
82+
linters-settings:
83+
depguard:
84+
list-type: whitelist
85+
include-go-root: false
86+
packages:
87+
- github.com/lib/pq
88+
govet:
89+
enable-all: true
90+
check-shadowing: false
91+
disable:
92+
# Do not check variable shadowing.
93+
- shadow
94+
stylecheck:
95+
checks:
96+
- all
97+
issues:
98+
exclude-use-default: false
99+
exclude-rules:
100+
- linters:
101+
- gofmt
102+
source: "//"
103+
- linters:
104+
- gofmt
105+
- revive
106+
source: "/*"

CONTRIBUTING.md

+6-1
Original file line numberDiff line numberDiff line change
@@ -25,4 +25,9 @@ rules:
2525

2626
* Follow Go conventions where applicable (e.g. naming using camelCase or PascalCase)
2727
* Use `go fmt` to format the code
28-
* Linting rules TBA
28+
* To sanity-check your code before submitting a PR, use [golangci-lint](https://golangci-lint.run/)
29+
```
30+
golangci-lint run
31+
```
32+
The provided `.golangci.yaml` file describes the linting rules that are used in this codebase. If you have
33+
a good reason to skip a rule, you can add a `//nolint:rule` comment to the line that you want to skip.

0 commit comments

Comments
 (0)