Skip to content

Commit

Permalink
Fixed lint errors. Made CI run on PRs (#27)
Browse files Browse the repository at this point in the history
* Fixed lint errors. Made CI run on PRs

* Adjusting CI trigger

* Changes to README
  • Loading branch information
ryanrolds committed Aug 27, 2023
1 parent 986f197 commit 1116461
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 14 deletions.
5 changes: 4 additions & 1 deletion .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
name: build
on:
push:
branches:
- main
pull_request:
jobs:
golangci:
name: lint
name: CI
runs-on: ubuntu-latest
steps:
- uses: actions/setup-go@v3
Expand Down
17 changes: 13 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# sqlclosecheck

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

## Running

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

## CI
## Developers

Start by creating a test that should pass/fail.
Test are located at `pkg/analyzer/testdata`.
All PRs that modify the analyzer should include a test.
Negative tests are just as important as positive tests.

Make changes to the analyzer (`pkg/analyzer`) and run the tests:
```
go install github.com/ryanrolds/sqlclosecheck@latest
go vet -vettool=${GOPATH}/bin/sqlclosecheck ./...
make test
```

## CI

GitHub Actions that runs on push to `main` and PRs.
19 changes: 10 additions & 9 deletions pkg/analyzer/analyzer.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package analyzer

import (
"go/types"

"golang.org/x/tools/go/analysis"
"golang.org/x/tools/go/analysis/passes/buildssa"
"golang.org/x/tools/go/ssa"
Expand Down Expand Up @@ -171,11 +172,11 @@ func getTargetTypesValues(b *ssa.BasicBlock, i int, targetTypes []any) []targetV
for _, targetType := range targetTypes {
var tt types.Type

switch targetType.(type) {
switch t := targetType.(type) {
case *types.Pointer:
tt = targetType.(*types.Pointer)
tt = t
case *types.Named:
tt = targetType.(*types.Named)
tt = t
default:
continue
}
Expand Down Expand Up @@ -297,11 +298,11 @@ func getAction(instr ssa.Instruction, targetTypes []any) action {
for _, targetType := range targetTypes {
var tt types.Type

switch targetType.(type) {
switch t := targetType.(type) {
case *types.Pointer:
tt = targetType.(*types.Pointer)
tt = t
case *types.Named:
tt = targetType.(*types.Named)
tt = t
default:
continue
}
Expand Down Expand Up @@ -361,11 +362,11 @@ func checkDeferred(pass *analysis.Pass, instrs *[]ssa.Instruction, targetTypes [
for _, targetType := range targetTypes {
var tt types.Type

switch targetType.(type) {
switch t := targetType.(type) {
case *types.Pointer:
tt = targetType.(*types.Pointer)
tt = t
case *types.Named:
tt = targetType.(*types.Named)
tt = t
default:
continue
}
Expand Down

0 comments on commit 1116461

Please sign in to comment.