Skip to content

Commit f32fcd7

Browse files
committed
Add basic golangci-lint configuration and GitHub Action workflow
1 parent 5075cb9 commit f32fcd7

File tree

2 files changed

+194
-0
lines changed

2 files changed

+194
-0
lines changed

.github/workflows/go.yml

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
---
2+
name: Go
3+
on:
4+
pull_request:
5+
push:
6+
branches:
7+
- main
8+
jobs:
9+
go-test-lint:
10+
name: Go Test & Lint
11+
permissions:
12+
contents: read # for actions/checkout to fetch code
13+
pull-requests: read # for golangci/golangci-lint-action to fetch pull requests
14+
runs-on: ubuntu-latest
15+
steps:
16+
- name: checkout-action
17+
uses: actions/checkout@v5
18+
19+
- name: Set up Go
20+
uses: actions/setup-go@v6
21+
with:
22+
go-version: stable
23+
24+
- name: golangci-lint
25+
uses: golangci/golangci-lint-action@v8
26+
with:
27+
version: latest
28+
29+
- name: Run tests
30+
run: go test

.golangci.yml

Lines changed: 164 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,164 @@
1+
---
2+
# golangci-lint configuration file made by @ccoVeille
3+
# Source: https://github.com/ccoVeille/golangci-lint-config-examples/
4+
# Author: @ccoVeille
5+
# License: MIT
6+
# Variant: 10-cautious
7+
# Version: v2.0.0
8+
#
9+
version: "2"
10+
linters:
11+
# some linters are enabled by default
12+
# https://golangci-lint.run/usage/linters/
13+
#
14+
# enable some extra linters
15+
enable:
16+
# Errcheck is a program for checking for unchecked errors in Go code.
17+
- errcheck
18+
19+
# Vet examines Go source code and reports suspicious constructs.
20+
- govet
21+
22+
# Detects when assignments to existing variables are not used.
23+
- ineffassign
24+
25+
# It's a set of rules from staticcheck. See https://staticcheck.io/
26+
- staticcheck
27+
28+
# Checks Go code for unused constants, variables, functions and types.
29+
- unused
30+
31+
# Fast, configurable, extensible, flexible, and beautiful linter for Go.
32+
# Drop-in replacement of golint.
33+
- revive
34+
35+
# make sure to use t.Helper() when needed
36+
- thelper
37+
38+
# mirror suggests rewrites to avoid unnecessary []byte/string conversion
39+
- mirror
40+
41+
# detect the possibility to use variables/constants from the Go standard library.
42+
- usestdlibvars
43+
44+
# Finds commonly misspelled English words.
45+
- misspell
46+
47+
# Checks for duplicate words in the source code.
48+
- dupword
49+
50+
# linter to detect errors invalid key values count
51+
- loggercheck
52+
53+
# detects nested contexts in loops or function literals
54+
- fatcontext
55+
56+
# detect when a package or method could be replaced by one from the standard library
57+
- exptostd
58+
59+
# detects nested contexts in loops or function literals
60+
- fatcontext
61+
62+
# Reports uses of functions with replacement inside the testing package.
63+
- usetesting
64+
65+
settings:
66+
revive:
67+
rules:
68+
# Check for commonly mistaken usages of the sync/atomic package
69+
- name: atomic
70+
71+
# Blank import should be only in a main or test package, or have a comment justifying it.
72+
- name: blank-imports
73+
74+
# Spots comments not starting with a space
75+
- name: comment-spacings
76+
77+
# context.Context() should be the first parameter of a function when provided as argument.
78+
- name: context-as-argument
79+
arguments:
80+
- allowTypesBefore: "*testing.T"
81+
82+
# Basic types should not be used as a key in `context.WithValue`
83+
- name: context-keys-type
84+
85+
# warns on some common mistakes when using defer statement.
86+
- name: defer
87+
88+
# Importing with `.` makes the programs much harder to understand
89+
- name: dot-imports
90+
91+
# suggest to simplify if-then-else constructions when possible
92+
- name: early-return
93+
94+
# Empty blocks make code less readable and could be a symptom of a bug or unfinished refactoring.
95+
- name: empty-block
96+
97+
# for better readability, variables of type `error` must be named with the prefix `err`.
98+
- name: error-naming
99+
100+
# for better readability, the errors should be last in the list of returned values by a function.
101+
- name: error-return
102+
103+
# for better readability, error messages should not be capitalized or end with punctuation or a newline.
104+
- name: error-strings
105+
106+
# report when replacing `errors.New(fmt.Sprintf())` with `fmt.Errorf()` is possible
107+
- name: errorf
108+
109+
# check naming and commenting conventions on exported symbols.
110+
- name: exported
111+
arguments:
112+
# make error messages clearer
113+
- "sayRepetitiveInsteadOfStutters"
114+
115+
# Checking if an error is nil to just after return the error or nil is redundant.
116+
- name: if-return
117+
118+
# incrementing an integer variable by 1 is recommended to be done using the `++` operator
119+
- name: increment-decrement
120+
121+
# highlights redundant else-blocks that can be eliminated from the code
122+
- name: indent-error-flow
123+
124+
# This rule suggests a shorter way of writing ranges that do not use the second value.
125+
- name: range
126+
127+
# receiver names in a method should reflect the struct name (p for Person, for example)
128+
- name: receiver-naming
129+
130+
# redefining built in names (true, false, append, make) can lead to bugs very difficult to detect.
131+
- name: redefines-builtin-id
132+
133+
# redundant else-blocks that can be eliminated from the code.
134+
- name: superfluous-else
135+
136+
# prevent confusing name for variables when using `time` package
137+
- name: time-naming
138+
139+
# warns when an exported function or method returns a value of an un-exported type.
140+
- name: unexported-return
141+
142+
# spots and proposes to remove unreachable code. also helps to spot errors
143+
- name: unreachable-code
144+
145+
# Functions or methods with unused parameters can be a symptom of an unfinished refactoring or a bug.
146+
- name: unused-parameter
147+
148+
# warns on useless break statements in case clauses of switch and select statements
149+
- name: useless-break
150+
151+
# report when a variable declaration can be simplified
152+
- name: var-declaration
153+
154+
# warns when initialism, variable or package naming conventions are not followed.
155+
- name: var-naming
156+
157+
errcheck:
158+
exclude-functions:
159+
- fmt.Fprintf
160+
- fmt.Fprint
161+
- fmt.Fprintln
162+
163+
misspell:
164+
locale: US

0 commit comments

Comments
 (0)