Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add .golangci.yml #19

Merged
merged 4 commits into from
Feb 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 14 additions & 26 deletions .github/workflows/workflow.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,19 @@ on:
- v*
branches:
- master
- main
pull_request:

jobs:
unit-tests:
name: unit-tests
strategy:
matrix:
go-version: [ 1.17.x, 1.18.x ] # support latest 2 major versions
go-version: [ 1.21.x, 1.22.x ] # support latest 2 major versions
os: [ ubuntu-latest ]
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4

- name: Install Go
uses: actions/setup-go@v5
Expand All @@ -37,34 +38,21 @@ jobs:

lint:
name: lint
strategy:
matrix:
go-version: [ 1.17.x, 1.18.x ] # support latest 2 major versions
os: [ ubuntu-latest ]
runs-on: ${{ matrix.os }}
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4

- name: Install Go
uses: actions/setup-go@v3
uses: actions/setup-go@v5
with:
go-version: ${{ matrix.go-version }}
go-version-file: ./go.mod
cache: true # caching and restoring go modules and build outputs

- name: Check that 'go mod tidy' was called before commit
run: go mod tidy && git diff --exit-code

- name: golangci-lint
uses: golangci/golangci-lint-action@v3
uses: golangci/golangci-lint-action@v4
with:
version: v1.46

# Optional: working directory, useful for monorepos
# working-directory: somedir

# Optional: golangci-lint command line arguments.
# TODO: switch to .golangci.yml
args: >
--tests=false
-E bodyclose -E golint -E rowserrcheck -E gosec -E interfacer
-E unconvert -E dupl -E goconst -E gocognit -E goimports -E maligned -E unparam
-E dogsled -E prealloc -E gocritic -E wsl -E goprintffuncname

# Optional: show only new issues if it's a pull request. The default value is `false`.
# only-new-issues: true
version: v1.56
skip-cache: true # cache/restore is done by actions/setup-go step
111 changes: 111 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
linters:
# please, do not use `enable-all`: it's deprecated and will be removed soon.
# inverted configuration with `enable-all` and `disable` is not scalable during updates of golangci-lint
disable-all: true
enable:
- errcheck
- ineffassign
- bodyclose
- govet
- gosec

- staticcheck
- typecheck
- gosimple
- prealloc
- nolintlint

- stylecheck
- gocritic
- revive
- gofmt
- goimports
- lll
- nlreturn

- dogsled
- exhaustive
- exportloopref
- funlen
- gochecknoinits
- gocognit
- goconst
- gocyclo
- goprintffuncname
- misspell
- nakedret
- rowserrcheck
- unconvert
- unparam
- unused

# TODO:
# - noctx
# - depguard
# - dupl # skip in tests?

# disabled:
# - asciicheck
# - gochecknoglobals
# - godot
# - godox
# - goerr113
# - nestif
# - testpackage
# - wsl
# - whitespace

linters-settings:
dupl:
threshold: 100
funlen:
lines: 100
statements: 50
gci:
local-prefixes: github.com/vtopc/epoch
goconst:
min-len: 2
min-occurrences: 2
gocritic:
enabled-tags:
- diagnostic
- experimental
- opinionated
- performance
- style
# - ifElseChain # ERRO Invalid gocritic settings: gocritic [enabled]tag "ifElseChain" doesn't exist
disabled-checks:
- dupImport # https://github.com/go-critic/go-critic/issues/845
- octalLiteral
- wrapperFunc
- whyNoLint
gocyclo:
min-complexity: 15
goimports:
local-prefixes: github.com/vtopc/epoch
golint:
min-confidence: 0
govet:
check-shadowing: true
#settings:
# printf:
# funcs:
# - (github.com/golangci/golangci-lint/pkg/logutils.Log).Infof
# - (github.com/golangci/golangci-lint/pkg/logutils.Log).Warnf
# - (github.com/golangci/golangci-lint/pkg/logutils.Log).Errorf
# - (github.com/golangci/golangci-lint/pkg/logutils.Log).Fatalf
lll:
line-length: 140
misspell:
locale: US
nolintlint:
allow-unused: false # report any unused nolint directives
require-explanation: true # require an explanation for nolint directives
require-specific: true # require nolint directives to be specific about which linter is being skipped

issues:
# Maximum issues count per one linter. Set to 0 to disable. Default is 50.
max-issues-per-linter: 0

# Maximum count of issues with the same text. Set to 0 to disable. Default is 3.
max-same-issues: 50
12 changes: 10 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,13 @@ test: ## Run unit tests.

.PHONY: deps
deps: ## Install dependencies.
GO111MODULE=on go mod tidy
GO111MODULE=on go mod download
go mod download

# linter:
GOLINT = $(GOPATH)/bin/golangci-lint
$(GOLINT):
curl -sfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(GOPATH)/bin v1.56.2

.PHONY: lint
lint: $(GOLINT) ## Run linters.
$(GOLINT) run
3 changes: 2 additions & 1 deletion float_ms.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ import (

// FloatMS - integer part of timestamp represents seconds and fractional - milliseconds since
// the Epoch(Unix time), e.g.
// 1136239445.999
//
// 1136239445.999
//
// Inherits built-in time.Time type, thus has all it methods, but has custom serializer and
// deserializer(converts float timestamp into built-in time.Time and vice versa).
Expand Down
1 change: 1 addition & 0 deletions str_milliseconds.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ func NewStrMilliseconds(t time.Time) StrMilliseconds {
// MarshalJSON - implements JSON marshaling interface
func (m StrMilliseconds) MarshalJSON() ([]byte, error) {
ms := m.Time.UnixNano() / nsPerMs

return json.Marshal(strconv.FormatInt(ms, 10))
}

Expand Down
Loading