Skip to content

Commit

Permalink
Add golangci-lint (eatonphil#18)
Browse files Browse the repository at this point in the history
* Add golangci-lint

* Fail if gofmt diff

* Add install step

* Without gofmt diff

* With || exit 1

* Without gofmt diff
  • Loading branch information
eatonphil authored Apr 27, 2020
1 parent 9608511 commit 3bd3797
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 11 deletions.
7 changes: 6 additions & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@ jobs:
steps:
- checkout

# Install golangci-lint
- run: curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(go env GOPATH)/bin v1.25.0
- run: go get -v -t -d ./...
- run: go test -v ./...
- run: make test
- run: make lint
# Fail if there's a gofmt diff
- run: bash -c '[[ $(gofmt -l .) ]] && exit 1 || exit 0'
- run: go build cmd/main.go
3 changes: 2 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,6 @@ test:
cover:
go tool cover -func=coverage.out

vet:
lint:
go vet .
golangci-lint run
3 changes: 0 additions & 3 deletions ast.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,6 @@ func (e expression) generateCode() string {
return ""
}

type identifier expression

type selectItem struct {
exp *expression
asterisk bool
Expand Down Expand Up @@ -142,7 +140,6 @@ func (dts DropTableStatement) GenerateCode() string {

type InsertStatement struct {
table token
cols *[]*identifier
values *[]*expression
}

Expand Down
2 changes: 1 addition & 1 deletion cmd/indextest/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ func perf(name string, b gosql.Backend, cb func(b gosql.Backend)) {
start := time.Now()
fmt.Println("Starting", name)
cb(b)
fmt.Printf("Finished %s: %f seconds\n", name, time.Now().Sub(start).Seconds())
fmt.Printf("Finished %s: %f seconds\n", name, time.Since(start).Seconds())

var m runtime.MemStats
runtime.ReadMemStats(&m)
Expand Down
11 changes: 6 additions & 5 deletions memory.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ func (mc memoryCell) equals(b memoryCell) bool {
return mc == nil && b == nil
}

return bytes.Compare(mc, b) == 0
return bytes.Equal(mc, b)
}

func literalToMemoryCell(t *token) memoryCell {
Expand All @@ -66,7 +66,7 @@ func literalToMemoryCell(t *token) memoryCell {
// TODO: handle bigint
err = binary.Write(buf, binary.BigEndian, int32(i))
if err != nil {
fmt.Printf("Corrupted data [%s]: %s\n", string(buf.Bytes()), err)
fmt.Printf("Corrupted data [%s]: %s\n", buf.String(), err)
return nil
}
return buf.Bytes()
Expand Down Expand Up @@ -193,7 +193,8 @@ func (i *index) newTableFromSubset(t *table, exp expression) *table {
case eqSymbol:
i.tree.AscendGreaterOrEqual(tiValue, func(i llrb.Item) bool {
ti := i.(treeItem)
if bytes.Compare(ti.value, value) != 0 {

if !bytes.Equal(ti.value, value) {
return false
}

Expand All @@ -203,7 +204,7 @@ func (i *index) newTableFromSubset(t *table, exp expression) *table {
case neqSymbol:
i.tree.AscendGreaterOrEqual(llrb.Inf(-1), func(i llrb.Item) bool {
ti := i.(treeItem)
if bytes.Compare(ti.value, value) != 0 {
if bytes.Equal(ti.value, value) {
indexes = append(indexes, ti.index)
}

Expand Down Expand Up @@ -344,7 +345,7 @@ func (t *table) evaluateBinaryCell(rowIndex uint, exp expression) (memoryCell, s

return falseMemoryCell, "?column?", BoolType, nil
case neqSymbol:
if len(r) == 0 || len(r) == 0 {
if len(l) == 0 || len(r) == 0 {
return nullMemoryCell, "?column?", BoolType, nil
}

Expand Down

0 comments on commit 3bd3797

Please sign in to comment.