Skip to content

Commit

Permalink
Initial add of revive (#32)
Browse files Browse the repository at this point in the history
* Initial add of revive
* Fix the fails
  • Loading branch information
nickschuch authored Aug 30, 2024
1 parent 416a3dc commit 0f78403
Show file tree
Hide file tree
Showing 6 changed files with 53 additions and 15 deletions.
16 changes: 11 additions & 5 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,18 @@ on:

jobs:
lint:
name: 📋 Lint
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-go@v3
- name: ⬇️ Git clone the repository
uses: actions/checkout@v3

- name: 📦 Install Go
uses: actions/setup-go@v3
with:
go-version: '1.21'
- uses: golangci/golangci-lint-action@v3
with:
args: --timeout=5m

- name: 🧪 Revive
run: |
go install github.com/mgechev/revive@latest
make lint
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ build:

# Run all lint checking with exit codes for CI.
lint:
golint -set_exit_status `go list ./... | grep -v /vendor/`
revive -config revive.toml -set_exit_status ./cmd/... ./internal/... ./pkg/...

# Run tests with coverage reporting.
test:
Expand Down
6 changes: 3 additions & 3 deletions internal/mysql/provider/stdout/provider_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,12 @@ func TestMySQLGetSelectQueryFor(t *testing.T) {
func TestMySQLGetSelectQueryForHandlingError(t *testing.T) {
db, mock := mock.GetDB(t)
dumper := NewClient(db, log.New(os.Stdout, "", 0))
error := errors.New("broken")
mock.ExpectQuery("SELECT \\* FROM `table` LIMIT 1").WillReturnError(error)
e := errors.New("broken")
mock.ExpectQuery("SELECT \\* FROM `table` LIMIT 1").WillReturnError(e)
query, err := dumper.GetSelectQueryForTable("table", provider.DumpParams{
SelectMap: map[string]map[string]string{"table": {"c2": "NOW()"}},
WhereMap: map[string]string{"table": "c1 > 0"},
})
assert.Equal(t, error, err)
assert.Equal(t, e, err)
assert.Equal(t, "", query)
}
6 changes: 3 additions & 3 deletions internal/mysql/provider/utils/utils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,11 @@ func TestMySQLGetColumnsForSelect(t *testing.T) {

func TestMySQLGetColumnsForSelectHandlingErrorWhenQuerying(t *testing.T) {
db, mock := mock.GetDB(t)
error := errors.New("broken")
mock.ExpectQuery("SELECT \\* FROM `table` LIMIT 1").WillReturnError(error)
e := errors.New("broken")
mock.ExpectQuery("SELECT \\* FROM `table` LIMIT 1").WillReturnError(e)
columns, err := QueryColumnsForTable(db, "table", provider.DumpParams{
SelectMap: map[string]map[string]string{"table": {"col2": "NOW()"}},
})
assert.Equal(t, err, error)
assert.Equal(t, err, e)
assert.Empty(t, columns)
}
6 changes: 3 additions & 3 deletions internal/mysql/write_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ func TestMySQLDumpTableDataHandlingErrorFromSelectAllDataFor(t *testing.T) {
db, mock := mock.GetDB(t)
buffer := bytes.NewBuffer(make([]byte, 0))
dumper := NewClient(db, log.New(os.Stdout, "", 0), "stdout", "", "")
error := errors.New("fail")
mock.ExpectQuery("SELECT \\* FROM `table` LIMIT 1").WillReturnError(error)
assert.Equal(t, error, dumper.WriteTableData(buffer, "table", provider.DumpParams{}))
e := errors.New("fail")
mock.ExpectQuery("SELECT \\* FROM `table` LIMIT 1").WillReturnError(e)
assert.Equal(t, e, dumper.WriteTableData(buffer, "table", provider.DumpParams{}))
}
32 changes: 32 additions & 0 deletions revive.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
ignoreGeneratedHeader = false
severity = "warning"
confidence = 0.8
errorCode = 0
warningCode = 0

[rule.blank-imports]
[rule.context-as-argument]
[rule.context-keys-type]
[rule.dot-imports]
[rule.error-return]
[rule.error-strings]
[rule.error-naming]
[rule.exported]
[rule.increment-decrement]
[rule.var-naming]
[rule.var-declaration]
[rule.range]
[rule.receiver-naming]
[rule.time-naming]
[rule.unexported-return]
[rule.indent-error-flow]
[rule.errorf]
[rule.empty-block]
[rule.superfluous-else]
[rule.unreachable-code]
[rule.redefines-builtin-id]

# These should be uncommented and resolve in
# future pull requests.
# [rule.package-comments]
# [rule.unused-parameter]

0 comments on commit 0f78403

Please sign in to comment.