Skip to content

Commit

Permalink
chore: update to latest golangci and fix linting issues
Browse files Browse the repository at this point in the history
  • Loading branch information
doug-martin committed May 4, 2021
1 parent 89a3daf commit 668ffa2
Show file tree
Hide file tree
Showing 39 changed files with 1,323 additions and 1,508 deletions.
9 changes: 4 additions & 5 deletions .github/workflows/golangci-lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,11 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
# Disable for now to get release out will will upgrade in a followup
#- name: golangci-lint
# uses: golangci/golangci-lint-action@v1.2.1
# with:
- name: golangci-lint
uses: golangci/golangci-lint-action@v2
with:
# Optional: version of golangci-lint to use in form of v1.2 or v1.2.3 or `latest` to use the latest version
# version: v1.23
#version: v1.23

# Optional: working directory, useful for monorepos
# working-directory: somedir
Expand Down
153 changes: 109 additions & 44 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,37 @@
linters-settings:
funlen:
lines: 140
statements: 50
gci:
local-prefixes: github.com/golangci/golangci-lint
goconst:
min-len: 2
min-occurrences: 2
gocritic:
enabled-tags:
- diagnostic
- experimental
- opinionated
- performance
- style
disabled-checks:
- dupImport # https://github.com/go-critic/go-critic/issues/845
- ifElseChain
- octalLiteral
- whyNoLint
- wrapperFunc
- sqlQuery # used by tests
gocyclo:
min-complexity: 20
goimports:
local-prefixes: github.com/golangci/golangci-lint
golint:
min-confidence: 0
gomnd:
settings:
mnd:
# don't include the "operation" and "assign"
checks: argument,case,condition,return
govet:
check-shadowing: true
settings:
Expand All @@ -8,60 +41,92 @@ linters-settings:
- (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
golint:
min-confidence: 0
gocyclo:
min-complexity: 20
lll:
line-length: 140
maligned:
suggest-new: true
goconst:
min-len: 2
min-occurrences: 2
depguard:
list-type: blacklist
packages:
# logging is allowed only by logutils.Log, logrus
# is allowed to use only in logutils package
- github.com/sirupsen/logrus
misspell:
locale: US
lll:
line-length: 140
exclude: '\/\/ '
goimports:
local-prefixes: github.com/golangci/golangci-lint
gocritic:
enabled-tags:
- performance
- style
disabled-checks:
- wrapperFunc
nolintlint:
allow-leading-space: true # don't require machine-readable nolint directives (i.e. with no leading space)
allow-unused: false # report any unused nolint directives
require-explanation: false # don't require an explanation for nolint directives
require-specific: false # don't require nolint directives to be specific about which linter is being skipped
exhaustive:
default-signifies-exhaustive: true

linters:
enable-all: true
disable:
- maligned
- prealloc
- gochecknoglobals
- gochecknoinits
- dupl
- gomnd
# 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:
- bodyclose
- deadcode
- depguard
- dogsled
- errcheck
- exportloopref
- exhaustive
- funlen
- wsl
- goconst
- gocritic
- gocyclo
- gofmt
- goimports
- golint
- gomnd
- goprintffuncname
- gosec
- gosimple
- govet
- ineffassign
- lll
- misspell
- nakedret
- noctx
- nolintlint
- rowserrcheck
- staticcheck
- structcheck
- stylecheck
- typecheck
- unconvert
- unparam
- unused
- varcheck
- whitespace

run:
skip-dirs:
- pkg/golinters/goanalysis/(checker|passes)
# don't enable:
# - asciicheck
# - scopelint
# - gochecknoglobals
# - gocognit
# - godot
# - godox
# - goerr113
# - interfacer
# - maligned
# - nestif
# - prealloc
# - testpackage
# - revive
# - wsl

issues:
# Excluding configuration per-path, per-linter, per-text and per-source
exclude-rules:
- text: "weak cryptographic primitive"
- path: _test\.go
linters:
- gosec
- gomnd

# https://github.com/go-critic/go-critic/issues/926
- linters:
- gocritic
text: "unnecessaryDefer:"

# golangci.com configuration
# https://github.com/golangci/golangci/wiki/Configuration
service:
golangci-lint-version: 1.23.x # use the fixed version to not introduce new linters unexpectedly
prepare:
- echo "here I can run custom commands, but no preparation needed for this repo"
run:
skip-dirs:
- test/testdata_etc
- internal/cache
- internal/renameio
- internal/robustio
15 changes: 11 additions & 4 deletions database.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,10 @@ type (
Database struct {
logger Logger
dialect string
Db SQLDatabase
qf exec.QueryFactory
qfOnce sync.Once
// nolint: stylecheck // keep for backwards compatibility
Db SQLDatabase
qf exec.QueryFactory
qfOnce sync.Once
}
)

Expand Down Expand Up @@ -62,7 +63,13 @@ type (
// }
// fmt.Printf("%+v", ids)
func newDatabase(dialect string, db SQLDatabase) *Database {
return &Database{dialect: dialect, Db: db}
return &Database{
logger: nil,
dialect: dialect,
Db: db,
qf: nil,
qfOnce: sync.Once{},
}
}

// returns this databases dialect
Expand Down
14 changes: 7 additions & 7 deletions database_example_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
)

func ExampleDatabase_Begin() {
db := getDb()
db := getDB()

tx, err := db.Begin()
if err != nil {
Expand Down Expand Up @@ -43,7 +43,7 @@ func ExampleDatabase_Begin() {
}

func ExampleDatabase_BeginTx() {
db := getDb()
db := getDB()

ctx := context.Background()
tx, err := db.BeginTx(ctx, &sql.TxOptions{Isolation: sql.LevelReadCommitted})
Expand Down Expand Up @@ -77,7 +77,7 @@ func ExampleDatabase_BeginTx() {
}

func ExampleDatabase_WithTx() {
db := getDb()
db := getDB()
var ids []int64
if err := db.WithTx(func(tx *goqu.TxDatabase) error {
// use tx.From to get a dataset that will execute within this transaction
Expand All @@ -98,7 +98,7 @@ func ExampleDatabase_WithTx() {
}

func ExampleDatabase_Dialect() {
db := getDb()
db := getDB()

fmt.Println(db.Dialect())

Expand All @@ -107,7 +107,7 @@ func ExampleDatabase_Dialect() {
}

func ExampleDatabase_Exec() {
db := getDb()
db := getDB()

_, err := db.Exec(`DROP TABLE "user_role"; DROP TABLE "goqu_user"`)
if err != nil {
Expand All @@ -119,7 +119,7 @@ func ExampleDatabase_Exec() {
}

func ExampleDatabase_ExecContext() {
db := getDb()
db := getDB()
d := time.Now().Add(50 * time.Millisecond)
ctx, cancel := context.WithDeadline(context.Background(), d)
defer cancel()
Expand All @@ -133,7 +133,7 @@ func ExampleDatabase_ExecContext() {
}

func ExampleDatabase_From() {
db := getDb()
db := getDB()
var names []string

if err := db.From("goqu_user").Select("first_name").ScanVals(&names); err != nil {
Expand Down
Loading

0 comments on commit 668ffa2

Please sign in to comment.