Skip to content

Commit 1116461

Browse files
authored
Fixed lint errors. Made CI run on PRs (#27)
* Fixed lint errors. Made CI run on PRs * Adjusting CI trigger * Changes to README
1 parent 986f197 commit 1116461

File tree

3 files changed

+27
-14
lines changed

3 files changed

+27
-14
lines changed

.github/workflows/ci.yaml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
11
name: build
22
on:
33
push:
4+
branches:
5+
- main
6+
pull_request:
47
jobs:
58
golangci:
6-
name: lint
9+
name: CI
710
runs-on: ubuntu-latest
811
steps:
912
- uses: actions/setup-go@v3

README.md

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# sqlclosecheck
22

33
Linter that checks if SQL rows/statements are closed. Unclosed rows and statements may
4-
cause DB connection pool exhaustion.
4+
cause DB connection pool exhaustion. Included in `golangci-lint` as `sqlclosecheck`.
55

66
## Running
77

@@ -15,9 +15,18 @@ In your project directory:
1515
go vet -vettool=$(which sqlclosecheck) ./...
1616
```
1717

18-
## CI
18+
## Developers
19+
20+
Start by creating a test that should pass/fail.
21+
Test are located at `pkg/analyzer/testdata`.
22+
All PRs that modify the analyzer should include a test.
23+
Negative tests are just as important as positive tests.
1924

25+
Make changes to the analyzer (`pkg/analyzer`) and run the tests:
2026
```
21-
go install github.com/ryanrolds/sqlclosecheck@latest
22-
go vet -vettool=${GOPATH}/bin/sqlclosecheck ./...
27+
make test
2328
```
29+
30+
## CI
31+
32+
GitHub Actions that runs on push to `main` and PRs.

pkg/analyzer/analyzer.go

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package analyzer
22

33
import (
44
"go/types"
5+
56
"golang.org/x/tools/go/analysis"
67
"golang.org/x/tools/go/analysis/passes/buildssa"
78
"golang.org/x/tools/go/ssa"
@@ -171,11 +172,11 @@ func getTargetTypesValues(b *ssa.BasicBlock, i int, targetTypes []any) []targetV
171172
for _, targetType := range targetTypes {
172173
var tt types.Type
173174

174-
switch targetType.(type) {
175+
switch t := targetType.(type) {
175176
case *types.Pointer:
176-
tt = targetType.(*types.Pointer)
177+
tt = t
177178
case *types.Named:
178-
tt = targetType.(*types.Named)
179+
tt = t
179180
default:
180181
continue
181182
}
@@ -297,11 +298,11 @@ func getAction(instr ssa.Instruction, targetTypes []any) action {
297298
for _, targetType := range targetTypes {
298299
var tt types.Type
299300

300-
switch targetType.(type) {
301+
switch t := targetType.(type) {
301302
case *types.Pointer:
302-
tt = targetType.(*types.Pointer)
303+
tt = t
303304
case *types.Named:
304-
tt = targetType.(*types.Named)
305+
tt = t
305306
default:
306307
continue
307308
}
@@ -361,11 +362,11 @@ func checkDeferred(pass *analysis.Pass, instrs *[]ssa.Instruction, targetTypes [
361362
for _, targetType := range targetTypes {
362363
var tt types.Type
363364

364-
switch targetType.(type) {
365+
switch t := targetType.(type) {
365366
case *types.Pointer:
366-
tt = targetType.(*types.Pointer)
367+
tt = t
367368
case *types.Named:
368-
tt = targetType.(*types.Named)
369+
tt = t
369370
default:
370371
continue
371372
}

0 commit comments

Comments
 (0)