From ad53a7afdf362dfc63c220c2616d5cfa488db626 Mon Sep 17 00:00:00 2001 From: Vilen Topchii <32271530+vtopc@users.noreply.github.com> Date: Sun, 25 Feb 2024 16:02:33 +0200 Subject: [PATCH 1/4] added .golangci.yml --- .github/workflows/workflow.yaml | 16 ++--- .golangci.yml | 119 ++++++++++++++++++++++++++++++++ Makefile | 12 +++- float_ms.go | 3 +- str_milliseconds.go | 1 + 5 files changed, 139 insertions(+), 12 deletions(-) create mode 100644 .golangci.yml diff --git a/.github/workflows/workflow.yaml b/.github/workflows/workflow.yaml index f15cbaf..c1917ac 100644 --- a/.github/workflows/workflow.yaml +++ b/.github/workflows/workflow.yaml @@ -12,11 +12,11 @@ jobs: 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 @@ -43,21 +43,19 @@ jobs: os: [ ubuntu-latest ] runs-on: ${{ matrix.os }} 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: 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: > diff --git a/.golangci.yml b/.golangci.yml new file mode 100644 index 0000000..c14e19e --- /dev/null +++ b/.golangci.yml @@ -0,0 +1,119 @@ +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: + # List of regexps of issue texts to exclude, empty list by default. + # But independently from this option we use default exclude patterns, + # it can be disabled by `exclude-use-default: false`. To list all + # excluded by default patterns execute `golangci-lint run --help` +# exclude: +# - G505 # sha1 +# - G401 # sha1 + + # 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 diff --git a/Makefile b/Makefile index ea47f74..66b733d 100644 --- a/Makefile +++ b/Makefile @@ -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 diff --git a/float_ms.go b/float_ms.go index 279f9c7..4897a59 100644 --- a/float_ms.go +++ b/float_ms.go @@ -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). diff --git a/str_milliseconds.go b/str_milliseconds.go index 82b1e5f..6b6c91f 100644 --- a/str_milliseconds.go +++ b/str_milliseconds.go @@ -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)) } From 538b91181b9fc90927f7886a1a36073f5493822e Mon Sep 17 00:00:00 2001 From: Vilen Topchii <32271530+vtopc@users.noreply.github.com> Date: Sun, 25 Feb 2024 16:03:58 +0200 Subject: [PATCH 2/4] bump golangci for GHA --- .github/workflows/workflow.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/workflow.yaml b/.github/workflows/workflow.yaml index c1917ac..2aa7f54 100644 --- a/.github/workflows/workflow.yaml +++ b/.github/workflows/workflow.yaml @@ -54,7 +54,7 @@ jobs: - name: golangci-lint uses: golangci/golangci-lint-action@v4 with: - version: v1.46 + version: v1.56 # Optional: golangci-lint command line arguments. # TODO: switch to .golangci.yml From 7528324b44eb1ddc8ddcb0aaeac11f17a87b32d8 Mon Sep 17 00:00:00 2001 From: Vilen Topchii <32271530+vtopc@users.noreply.github.com> Date: Sun, 25 Feb 2024 16:08:10 +0200 Subject: [PATCH 3/4] checks --- .github/workflows/workflow.yaml | 22 ++++++---------------- 1 file changed, 6 insertions(+), 16 deletions(-) diff --git a/.github/workflows/workflow.yaml b/.github/workflows/workflow.yaml index 2aa7f54..1748219 100644 --- a/.github/workflows/workflow.yaml +++ b/.github/workflows/workflow.yaml @@ -5,6 +5,7 @@ on: - v* branches: - master + - main pull_request: jobs: @@ -37,11 +38,7 @@ 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@v4 @@ -51,18 +48,11 @@ jobs: 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@v4 with: version: v1.56 - - # 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 + skip-cache: true # cache/restore is done by actions/setup-go step From ad4e3d8ad91b5c17ae35c666b5ea1d4c57945254 Mon Sep 17 00:00:00 2001 From: Vilen Topchii <32271530+vtopc@users.noreply.github.com> Date: Sun, 25 Feb 2024 16:11:06 +0200 Subject: [PATCH 4/4] removed redundant --- .golangci.yml | 8 -------- 1 file changed, 8 deletions(-) diff --git a/.golangci.yml b/.golangci.yml index c14e19e..47dafc1 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -104,14 +104,6 @@ linters-settings: require-specific: true # require nolint directives to be specific about which linter is being skipped issues: - # List of regexps of issue texts to exclude, empty list by default. - # But independently from this option we use default exclude patterns, - # it can be disabled by `exclude-use-default: false`. To list all - # excluded by default patterns execute `golangci-lint run --help` -# exclude: -# - G505 # sha1 -# - G401 # sha1 - # Maximum issues count per one linter. Set to 0 to disable. Default is 50. max-issues-per-linter: 0