Skip to content

Commit 2d5b711

Browse files
authored
add .golangci.yml (#19)
closes #16
1 parent 15484cf commit 2d5b711

File tree

5 files changed

+138
-29
lines changed

5 files changed

+138
-29
lines changed

.github/workflows/workflow.yaml

+14-26
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,19 @@ on:
55
- v*
66
branches:
77
- master
8+
- main
89
pull_request:
910

1011
jobs:
1112
unit-tests:
1213
name: unit-tests
1314
strategy:
1415
matrix:
15-
go-version: [ 1.17.x, 1.18.x ] # support latest 2 major versions
16+
go-version: [ 1.21.x, 1.22.x ] # support latest 2 major versions
1617
os: [ ubuntu-latest ]
1718
runs-on: ${{ matrix.os }}
1819
steps:
19-
- uses: actions/checkout@v3
20+
- uses: actions/checkout@v4
2021

2122
- name: Install Go
2223
uses: actions/setup-go@v5
@@ -37,34 +38,21 @@ jobs:
3738

3839
lint:
3940
name: lint
40-
strategy:
41-
matrix:
42-
go-version: [ 1.17.x, 1.18.x ] # support latest 2 major versions
43-
os: [ ubuntu-latest ]
44-
runs-on: ${{ matrix.os }}
41+
runs-on: ubuntu-latest
4542
steps:
46-
- uses: actions/checkout@v3
43+
- uses: actions/checkout@v4
4744

4845
- name: Install Go
49-
uses: actions/setup-go@v3
46+
uses: actions/setup-go@v5
5047
with:
51-
go-version: ${{ matrix.go-version }}
48+
go-version-file: ./go.mod
49+
cache: true # caching and restoring go modules and build outputs
50+
51+
- name: Check that 'go mod tidy' was called before commit
52+
run: go mod tidy && git diff --exit-code
5253

5354
- name: golangci-lint
54-
uses: golangci/golangci-lint-action@v3
55+
uses: golangci/golangci-lint-action@v4
5556
with:
56-
version: v1.46
57-
58-
# Optional: working directory, useful for monorepos
59-
# working-directory: somedir
60-
61-
# Optional: golangci-lint command line arguments.
62-
# TODO: switch to .golangci.yml
63-
args: >
64-
--tests=false
65-
-E bodyclose -E golint -E rowserrcheck -E gosec -E interfacer
66-
-E unconvert -E dupl -E goconst -E gocognit -E goimports -E maligned -E unparam
67-
-E dogsled -E prealloc -E gocritic -E wsl -E goprintffuncname
68-
69-
# Optional: show only new issues if it's a pull request. The default value is `false`.
70-
# only-new-issues: true
57+
version: v1.56
58+
skip-cache: true # cache/restore is done by actions/setup-go step

.golangci.yml

+111
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
linters:
2+
# please, do not use `enable-all`: it's deprecated and will be removed soon.
3+
# inverted configuration with `enable-all` and `disable` is not scalable during updates of golangci-lint
4+
disable-all: true
5+
enable:
6+
- errcheck
7+
- ineffassign
8+
- bodyclose
9+
- govet
10+
- gosec
11+
12+
- staticcheck
13+
- typecheck
14+
- gosimple
15+
- prealloc
16+
- nolintlint
17+
18+
- stylecheck
19+
- gocritic
20+
- revive
21+
- gofmt
22+
- goimports
23+
- lll
24+
- nlreturn
25+
26+
- dogsled
27+
- exhaustive
28+
- exportloopref
29+
- funlen
30+
- gochecknoinits
31+
- gocognit
32+
- goconst
33+
- gocyclo
34+
- goprintffuncname
35+
- misspell
36+
- nakedret
37+
- rowserrcheck
38+
- unconvert
39+
- unparam
40+
- unused
41+
42+
# TODO:
43+
# - noctx
44+
# - depguard
45+
# - dupl # skip in tests?
46+
47+
# disabled:
48+
# - asciicheck
49+
# - gochecknoglobals
50+
# - godot
51+
# - godox
52+
# - goerr113
53+
# - nestif
54+
# - testpackage
55+
# - wsl
56+
# - whitespace
57+
58+
linters-settings:
59+
dupl:
60+
threshold: 100
61+
funlen:
62+
lines: 100
63+
statements: 50
64+
gci:
65+
local-prefixes: github.com/vtopc/epoch
66+
goconst:
67+
min-len: 2
68+
min-occurrences: 2
69+
gocritic:
70+
enabled-tags:
71+
- diagnostic
72+
- experimental
73+
- opinionated
74+
- performance
75+
- style
76+
# - ifElseChain # ERRO Invalid gocritic settings: gocritic [enabled]tag "ifElseChain" doesn't exist
77+
disabled-checks:
78+
- dupImport # https://github.com/go-critic/go-critic/issues/845
79+
- octalLiteral
80+
- wrapperFunc
81+
- whyNoLint
82+
gocyclo:
83+
min-complexity: 15
84+
goimports:
85+
local-prefixes: github.com/vtopc/epoch
86+
golint:
87+
min-confidence: 0
88+
govet:
89+
check-shadowing: true
90+
#settings:
91+
# printf:
92+
# funcs:
93+
# - (github.com/golangci/golangci-lint/pkg/logutils.Log).Infof
94+
# - (github.com/golangci/golangci-lint/pkg/logutils.Log).Warnf
95+
# - (github.com/golangci/golangci-lint/pkg/logutils.Log).Errorf
96+
# - (github.com/golangci/golangci-lint/pkg/logutils.Log).Fatalf
97+
lll:
98+
line-length: 140
99+
misspell:
100+
locale: US
101+
nolintlint:
102+
allow-unused: false # report any unused nolint directives
103+
require-explanation: true # require an explanation for nolint directives
104+
require-specific: true # require nolint directives to be specific about which linter is being skipped
105+
106+
issues:
107+
# Maximum issues count per one linter. Set to 0 to disable. Default is 50.
108+
max-issues-per-linter: 0
109+
110+
# Maximum count of issues with the same text. Set to 0 to disable. Default is 3.
111+
max-same-issues: 50

Makefile

+10-2
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,13 @@ test: ## Run unit tests.
88

99
.PHONY: deps
1010
deps: ## Install dependencies.
11-
GO111MODULE=on go mod tidy
12-
GO111MODULE=on go mod download
11+
go mod download
12+
13+
# linter:
14+
GOLINT = $(GOPATH)/bin/golangci-lint
15+
$(GOLINT):
16+
curl -sfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(GOPATH)/bin v1.56.2
17+
18+
.PHONY: lint
19+
lint: $(GOLINT) ## Run linters.
20+
$(GOLINT) run

float_ms.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@ import (
99

1010
// FloatMS - integer part of timestamp represents seconds and fractional - milliseconds since
1111
// the Epoch(Unix time), e.g.
12-
// 1136239445.999
12+
//
13+
// 1136239445.999
1314
//
1415
// Inherits built-in time.Time type, thus has all it methods, but has custom serializer and
1516
// deserializer(converts float timestamp into built-in time.Time and vice versa).

str_milliseconds.go

+1
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ func NewStrMilliseconds(t time.Time) StrMilliseconds {
2020
// MarshalJSON - implements JSON marshaling interface
2121
func (m StrMilliseconds) MarshalJSON() ([]byte, error) {
2222
ms := m.Time.UnixNano() / nsPerMs
23+
2324
return json.Marshal(strconv.FormatInt(ms, 10))
2425
}
2526

0 commit comments

Comments
 (0)