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

Draft Test Lint #51

Draft
wants to merge 14 commits into
base: main
Choose a base branch
from
34 changes: 34 additions & 0 deletions .github/workflows/golangci.lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
name: golangci-lint
on:
push:
tags:
- v*
branches:
- main
pull_request:
branches:
- main

jobs:
golangci:
name: lint
runs-on: ubuntu-latest
steps:
- name: Checkout sources
uses: actions/checkout@v3
with:
submodules: true
- name: Get go version from go.mod
run: |
echo "GO_VERSION=$(grep '^go ' go.mod | cut -d " " -f 2)" >> $GITHUB_ENV
- name: Setup-go
uses: actions/setup-go@v3
with:
go-version: 1.22
- name: Run Lint
run: |
make remove-lint
make golanci-lint
make go-lint


67 changes: 67 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@

linters-settings:
goconst:
min-len: 2
min-occurrences: 3
gocritic:
enabled-tags:
- diagnostic
- experimental
- opinionated
- performance
- style
govet:
enable:
- shadow
- fieldalignment
nolintlint:
require-explanation: true
require-specific: true

linters:
disable-all: true
enable:
- bodyclose
# - unused # intentionally commented to avoid unused func warning as this repo is library
# - depguard
- dogsled
- dupl
- errcheck
- copyloopvar
- exhaustive
- goconst
- gocritic
- gofmt
- goimports
- gocyclo
- gosec
- gosimple
# - govet # intentionally disabled because we choose readability over performance
- ineffassign
- misspell
- nolintlint
- nakedret
- prealloc # pre-allocate slices with define size if the slice size is known in advance
- predeclared
- revive
- staticcheck
- stylecheck
- thelper
- tparallel
- typecheck
- unconvert
- unparam
- whitespace
- lll
- wsl # While space linter

run:
issues-exit-code: 1
go: '1.22'

issues:
exclude-dirs:
- testdata
- .git
- schema/schemas

15 changes: 15 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
repos:
- repo: https://github.com/tekwizely/pre-commit-golang
rev: v1.0.0-rc.1 # change this to the latest version
hooks:
- id: go-mod-tidy
- id: golangci-lint
args:
- --config=.golangci.yml

- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.4.0
hooks:
- id: check-merge-conflict
- id: end-of-file-fixer
- id: trailing-whitespace
23 changes: 23 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
# Get the currently used golang install path (in GOPATH/bin, unless GOBIN is set)
ifeq (,$(shell go env GOBIN))
GOBIN=$(shell go env GOPATH)/bin
else
GOBIN=$(shell go env GOBIN)
endif

# Variables required for this Makefile
ROOT_DIR = $(shell dirname $(realpath $(firstword $(MAKEFILE_LIST))))
VERSION = $(shell git describe --tags --always)
Expand Down Expand Up @@ -25,6 +32,22 @@ SOURCES := $(shell find . -name "*.go")
$(ACONFIG_BIN): $(SOURCES)
$(GO_ENV_VARS) go build -ldflags="-X 'github.com/aerospike/asconfig/cmd.VERSION=$(VERSION)'" -o $(ACONFIG_BIN) .

GOLANGCI_LINT ?= $(GOBIN)/golangci-lint
GOLANGCI_LINT_VERSION ?= v1.61.0

.PHONY: golanci-lint
golanci-lint: $(GOLANGCI_LINT) ## Download golangci-lint locally if necessary.
$(GOLANGCI_LINT): $(GOBIN)
curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(GOBIN) $(GOLANGCI_LINT_VERSION)

go-lint: golanci-lint ## Run golangci-lint against code.
$(GOLANGCI_LINT) run -c .golangci.yml -v


.PHONY: remove-lint
remove-lint:
$(RM) ${GOBIN}/golangci-lint

# Clean up
.PHONY: clean
clean:
Expand Down
Loading
Loading