Skip to content

Commit

Permalink
Chore/ci (#2)
Browse files Browse the repository at this point in the history
* style: fixed linter errors

* ci: configured GitGub Actions to run tests and linter

* refactor!: renamed interface method
  • Loading branch information
GoncharovLeonid authored Dec 6, 2022
1 parent 77ec9b1 commit deacdd2
Show file tree
Hide file tree
Showing 16 changed files with 227 additions and 66 deletions.
42 changes: 42 additions & 0 deletions .github/workflows/github-actions.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
name: GitHub Actions
on:
workflow_dispatch:
push:
branches:
- master
pull_request:
branches:
- master
jobs:
linter:
runs-on: ubuntu-20.04
timeout-minutes: 5
steps:
- name: Set up Go
uses: actions/setup-go@v3
with:
go-version: 1.19
- uses: actions/checkout@v3
with:
fetch-depth: 1
- name: golangci-lint
uses: golangci/golangci-lint-action@v3
with:
version: v1.50
env:
CGO_ENABLED: 0
tests:
runs-on: ubuntu-20.04
timeout-minutes: 5
steps:
- name: Set up Go
uses: actions/setup-go@v3
with:
go-version: 1.19
- uses: actions/checkout@v3
with:
fetch-depth: 1
- name: Run tests
run: go test -cover ./...
env:
CGO_ENABLED: 0
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
.idea
.idea
.DS_Store
115 changes: 115 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
linters-settings:
dupl:
threshold: 100
funlen:
lines: 120
statements: 60
gci:
local-prefixes: github.com/velmie/q2sql
goconst:
min-len: 2
min-occurrences: 2
gocritic:
enabled-tags:
- diagnostic
- experimental
- opinionated
- performance
- style
gocyclo:
min-complexity: 20
goimports:
local-prefixes: github.com/velmie/q2sql
gomnd:
settings:
mnd:
# don't include the "operation" and "assign"
checks: [argument,case,condition,return]
govet:
check-shadowing: true
lll:
line-length: 140
maligned:
suggest-new: true
misspell:
locale: US
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

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:
- bodyclose
- depguard
- dogsled
- errcheck
- funlen
- gochecknoinits
- goconst
- gocyclo
- gofmt
- goimports
- gomnd
- goprintffuncname
- gosec
- gosimple
- govet
- ineffassign
- lll
- misspell
- nakedret
- nolintlint
- staticcheck
- stylecheck
- typecheck
- unconvert
- unparam
- unused
- whitespace
- asasalint
- asasalint
- bidichk
- contextcheck
- dupl
- durationcheck
- errchkjson
- exportloopref
- forbidigo
- gocognit
- gocritic
- grouper
- importas
- loggercheck
- maintidx
- makezero
- nilerr
- nilnil
- prealloc
- reassign
- tagliatelle
- tenv
- usestdlibvars
# Unsupported because of the issue https://github.com/golangci/golangci-lint/issues/2649
# - rowserrcheck

issues:
# Excluding configuration per-path, per-linter, per-text and per-source
exclude-rules:
- path: _test\.go
linters:
- dupl
- gomnd
- funlen
- gocyclo
- lll
- maintidx
- path: expr\.go
linters:
- gocritic
run:
timeout: 5m
6 changes: 3 additions & 3 deletions builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,11 +77,11 @@ func (s *ResourceSelectBuilder) Build(
selectFields = s.allowedSelectFieldsSlc
} else {
if fields, ok := query.Fields.FieldsByResource(s.resourceName); ok {
fields, err := s.translator(fields)
f, err := s.translator(fields)
if err != nil {
return nil, err
}
selectFields = fields
selectFields = f
} else {
selectFields = s.defaultFields
}
Expand Down Expand Up @@ -128,7 +128,7 @@ func (s *ResourceSelectBuilder) Build(
b.OrderBy(OrderBy(sortList))
}
for _, extension := range s.extensions {
if err = extension(ctx, query, b); err != nil {
if err := extension(ctx, query, b); err != nil {
return nil, err
}
}
Expand Down
6 changes: 3 additions & 3 deletions builder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ var resourceBuilderTests = []resourceBuilderTest{
args: []interface{}{"1"},
sb: func() *SelectBuilder {
sb := new(SelectBuilder)
return sb.Where(&RawSqlWithArgs{"id = ?", []interface{}{"1"}})
return sb.Where(&RawSQLWithArgs{"id = ?", []interface{}{"1"}})
},
},
{
Expand Down Expand Up @@ -148,7 +148,7 @@ func TestNewResourceSelectBuilder(t *testing.T) {
},
filterContains: func(field string, args ...interface{}) Sqlizer {
if len(args) == 0 {
return RawSql("")
return RawSQL("")
}
val := "%" + args[0].(string) + "%"
return &Like{
Expand Down Expand Up @@ -213,7 +213,7 @@ func TestNewResourceSelectBuilder(t *testing.T) {
} else if err != nil {
continue
}
sql, args, err := sqlizer.ToSql()
sql, args, err := sqlizer.ToSQL()
if !tt.expectedErr && err != nil {
t.Errorf("%sunexpected error %s", meta, err)
continue
Expand Down
2 changes: 1 addition & 1 deletion condition/condition.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"github.com/velmie/q2sql"
)

const nilSqlizer = q2sql.RawSql("")
const nilSqlizer = q2sql.RawSQL("")

// Eq - equal to
func Eq(field string, args ...interface{}) q2sql.Sqlizer {
Expand Down
1 change: 0 additions & 1 deletion condition_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,5 @@ func TestConditionMap(t *testing.T) {
t.Errorf("ConditionMap.CreateCondition(%q) returned unexpected error %s", test.name, err)
continue
}

}
}
2 changes: 1 addition & 1 deletion examples/basic/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ func main() {
log.Fatal("failed to build query", err)
}

sqlStr, args, err := sqlizer.ToSql()
sqlStr, args, err := sqlizer.ToSQL()
if err != nil {
log.Fatal("failed to build SQL query", err)
}
Expand Down
2 changes: 1 addition & 1 deletion examples/custom_params/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ func main() {
// or rewrite some parts, for example the line below clears sorting
sb.OrderByParts = nil

sqlStr, args, err := sb.ToSql()
sqlStr, args, err := sb.ToSQL()
if err != nil {
log.Fatal("failed to build SQL query", err)
}
Expand Down
Loading

0 comments on commit deacdd2

Please sign in to comment.