Skip to content

Commit

Permalink
Merge pull request #285 from dkropachev/add_linter
Browse files Browse the repository at this point in the history
Add golangci-lint
  • Loading branch information
vponomaryov authored Apr 25, 2023
2 parents 9e601d5 + 0140acb commit 09de93c
Show file tree
Hide file tree
Showing 36 changed files with 648 additions and 369 deletions.
6 changes: 5 additions & 1 deletion .github/workflows/go.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ on:

jobs:
build:
name: Build
name: Lint Test and Build
runs-on: ubuntu-latest
steps:
- name:
Expand All @@ -19,6 +19,10 @@ jobs:
with:
go-version: 1.14

- name: Linting
run: |
make check
- name: Unit Tests
run: |
go test -v -race ./...
Expand Down
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
cmd/gemini/dist/
/gemini
.idea
.idea
bin/
63 changes: 63 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
issues:
exclude:
- Error return value of `.*.Unlock` is not checked
- Error return value of `.*.Completed` is not checked
linters:
disable-all: true
enable:
- errcheck
- govet
- ineffassign
- unused
- goheader
- goimports
- misspell
- gofumpt
- gosimple
- staticcheck
- lll
- errorlint
run:
deadline: 10m
modules-download-mode: readonly
linters-settings:
govet:
check-shadowing: true
settings:
shadow:
strict: true
enable-all: true
lll:
line-length: 180
goheader:
values:
regexp:
spaces: \s+
two-digits: \d\d
template: 'Copyright 20{{two-digits}} ScyllaDB
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
{{spaces}}http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.'
gofumpt:
lang-version: "1.12"
extra-rules: true
goimports:
local-prefixes: github.com/scylladb/gemini
45 changes: 45 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
GOPACKAGES := $(shell go list ./...)
MAKEFILE_PATH := $(abspath $(dir $(abspath $(lastword $(MAKEFILE_LIST)))))

GO111MODULE := on
# GO_UPGRADE - do not remove this comment, used by scripts/go-upgrade.sh
GOVERSION ?= 1.12
GOOS := $(shell uname | tr '[:upper:]' '[:lower:]')
GOARCH := $(shell go env GOARCH)

ifndef GOBIN
export GOBIN := $(MAKEFILE_PATH)/bin
endif

define dl_tgz
@mkdir -p $(GOBIN) 2>/dev/null

@if [ ! -f "$(GOBIN)/$(1)" ]; then \
echo "Downloading $(GOBIN)/$(1)"; \
curl --progress-bar -L $(2) | tar zxf - --wildcards --strip 1 -C $(GOBIN) '*/$(1)'; \
chmod +x "$(GOBIN)/$(1)"; \
fi
endef

$(GOBIN)/golangci-lint: GOLANGCI_VERSION = 1.51.1
$(GOBIN)/golangci-lint: Makefile
$(call dl_tgz,golangci-lint,https://github.com/golangci/golangci-lint/releases/download/v$(GOLANGCI_VERSION)/golangci-lint-$(GOLANGCI_VERSION)-$(GOOS)-amd64.tar.gz)

.PHONY: check-golangci
check-golangci: $(GOBIN)/golangci-lint
@echo $(GOPACKAGES) | sed -e 's/github.com\/scylladb\/gemini/./g' | \
xargs $(GOBIN)/golangci-lint run --max-issues-per-linter=0 --max-same-issues=0

# fix-golangci Automated fix for golangci-lint errors.
.PHONY: fix-golangci
fix-golangci: $(GOBIN)/golangci-lint
@echo $(GOPACKAGES) | sed -e 's/github.com\/scylladb\/gemini/./g' | \
xargs $(GOBIN)/golangci-lint run --fix

# check Run all static code analysis. (use make fix to attempt automatic fix)
.PHONY: check
check: check-golangci

# fix make all static code analysis tools to fix the issues
.PHONY: fix
fix: fix-golangci
5 changes: 2 additions & 3 deletions auth/auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,13 @@
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package auth

import (
Expand All @@ -22,7 +21,7 @@ import (

// BuildAuthenticator : Returns a new gocql.PasswordAuthenticator
// if both username and password are provided.
func BuildAuthenticator(username string, password string) (*gocql.PasswordAuthenticator, error) {
func BuildAuthenticator(username, password string) (*gocql.PasswordAuthenticator, error) {
if username == "" && password == "" {
return nil, nil
}
Expand Down
3 changes: 1 addition & 2 deletions auth/auth_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,13 @@
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package auth

import (
Expand Down
15 changes: 11 additions & 4 deletions cmd/gemini/generators.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,31 @@
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package main

import (
"context"

"github.com/scylladb/gemini"
"go.uber.org/zap"

"github.com/scylladb/gemini"
)

func createGenerators(ctx context.Context, schema *gemini.Schema, schemaConfig gemini.SchemaConfig, distributionFunc gemini.DistributionFunc, actors, distributionSize uint64, logger *zap.Logger) []*gemini.Generator {
func createGenerators(
ctx context.Context,
schema *gemini.Schema,
schemaConfig gemini.SchemaConfig,
distributionFunc gemini.DistributionFunc,
_, distributionSize uint64,
logger *zap.Logger,
) []*gemini.Generator {
partitionRangeConfig := gemini.PartitionRangeConfig{
MaxBlobLength: schemaConfig.MaxBlobLength,
MinBlobLength: schemaConfig.MinBlobLength,
Expand Down
Loading

0 comments on commit 09de93c

Please sign in to comment.