Skip to content

Commit

Permalink
linter fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
KevinJoiner committed Apr 22, 2024
1 parent 96fd5b9 commit 512a43c
Show file tree
Hide file tree
Showing 17 changed files with 231 additions and 218 deletions.
3 changes: 0 additions & 3 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,11 @@ linters:
disable-all: true
enable:
- bodyclose
- dogsled
- dupl
- errcheck
- exportloopref
- funlen
- gocritic
- goconst
- gocyclo
- gofumpt
- goimports
- revive
Expand Down
2 changes: 1 addition & 1 deletion cmd/clickhouse-container/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ func run(ctx context.Context) error {
defer chcontainer.Terminate(ctx)

if *migrate {
db, err := clickhouseinfra.GetClickhouseAsDB(ctx, chcontainer.ClickHouseContainer)
db, err := clickhouseinfra.GetClickhouseAsDB(ctx, chcontainer.ClickHouseContainer) //nolint: govet // false positive
if err != nil {
return fmt.Errorf("failed to get clickhouse db: %w", err)
}
Expand Down
6 changes: 4 additions & 2 deletions cmd/codegen/codegen.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@ func main() {
if *definitionPath != "" {
f, err := os.Open(filepath.Clean(*definitionPath))
if err != nil {
log.Fatalf("failed to open file: %v", err)
defer log.Fatalf("failed to open file: %v", err)
return
}
definitionReader = f
//nolint:errcheck // we don't care about the error since we are not writing to the file
Expand All @@ -70,6 +71,7 @@ func main() {

err := runner.Execute(vspecReader, definitionReader, gens, cfg)
if err != nil {
log.Fatal(err)
defer log.Fatal(err)
return
}
}
3 changes: 2 additions & 1 deletion internal/codegen/convert/convert.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ const (
convertTestFuncFileNameFormat = "%s-convert-funcs_test.go"
)

type ConversionData struct {
type conversionData struct {
Signal *codegen.SignalInfo
convIdx int
}
Expand All @@ -51,6 +51,7 @@ const header = `package %s
// Code generated by model-garage.
`

// Config is the configuration for the conversion generator.
type Config struct {
// WithTest determines if test functions should be generated.
WithTest bool
Expand Down
18 changes: 9 additions & 9 deletions internal/codegen/convert/convertFunc.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import (
"github.com/DIMO-Network/model-garage/internal/codegen"
)

func createConvertFuncs(tmplData *codegen.TemplateData, outputDir string, needsConvertFunc []ConversionData) error {
func createConvertFuncs(tmplData *codegen.TemplateData, outputDir string, needsConvertFunc []conversionData) error {
convertFuncTemplate, err := createConvertFuncTemplate()
if err != nil {
return err
Expand All @@ -34,22 +34,22 @@ func createConvertFuncs(tmplData *codegen.TemplateData, outputDir string, needsC
}

// getConversionFunctions returns the signals that need conversion functions and test functions.
func getConversionFunctions(signals []*codegen.SignalInfo, existingFuncs map[string]bool) ([]ConversionData, []ConversionData) {
var needsConvertFunc []ConversionData
var needsConvertTestFunc []ConversionData
func getConversionFunctions(signals []*codegen.SignalInfo, existingFuncs map[string]bool) ([]conversionData, []conversionData) {
var needsConvertFunc []conversionData
var needsConvertTestFunc []conversionData
for _, signal := range signals {
if len(signal.Conversions) == 0 {
continue
}
for i, _ := range signal.Conversions {
for i := range signal.Conversions {
funcName := convertName(signal) + strconv.Itoa(i)
if !existingFuncs[funcName] {
convData := ConversionData{Signal: signal, convIdx: i}
convData := conversionData{Signal: signal, convIdx: i}
needsConvertFunc = append(needsConvertFunc, convData)
}
funcName = convertTestName(signal) + strconv.Itoa(i)
if !existingFuncs[funcName] {
convData := ConversionData{Signal: signal, convIdx: i}
convData := conversionData{Signal: signal, convIdx: i}
needsConvertTestFunc = append(needsConvertTestFunc, convData)
}
}
Expand All @@ -58,7 +58,7 @@ func getConversionFunctions(signals []*codegen.SignalInfo, existingFuncs map[str
}

// createConvertTestFunc creates test functions for the conversion functions if they do not exist.
func createConvertTestFunc(tmplData *codegen.TemplateData, outputDir string, needsConvertTestFunc []ConversionData) error {
func createConvertTestFunc(tmplData *codegen.TemplateData, outputDir string, needsConvertTestFunc []conversionData) error {
convertTestFuncTemplate, err := createConvertTestFuncTemplate(tmplData.PackageName)
if err != nil {
return err
Expand Down Expand Up @@ -173,7 +173,7 @@ func ensureFuncFile(convertFuncPath string, packageName string) error {
return nil
}

func writeConvertFuncs(needsConvertFunc []ConversionData, tmpl *template.Template, outputPath string, packageName string) error {
func writeConvertFuncs(needsConvertFunc []conversionData, tmpl *template.Template, outputPath string, packageName string) error {
// check if we need to create convertFunc file
err := ensureFuncFile(outputPath, packageName)
if err != nil {
Expand Down
1 change: 0 additions & 1 deletion internal/codegen/graphql/graphql.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
package graphql

import (
_ "embed"
"fmt"
"os"
"path"
Expand Down
1 change: 1 addition & 0 deletions internal/codegen/migration/migration.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// Package migration provides a function for migrating a clickhouse database to a schema.
package migration

import (
Expand Down
2 changes: 2 additions & 0 deletions internal/codegen/signal.go
Original file line number Diff line number Diff line change
Expand Up @@ -175,11 +175,13 @@ func chName(name string) string {
return strings.ReplaceAll(removePrefix(name), ".", "_")
}

// JSONName returns the json name of the signal.
func JSONName(name string) string {
n := goName(name)
// lowercase the first letter
return strings.ToLower(n[:1]) + n[1:]
}

func removePrefix(name string) string {
idx := strings.IndexByte(name, '.')
if idx != -1 {
Expand Down
12 changes: 8 additions & 4 deletions pkg/clickhouseinfra/clickhouseinfra.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// Package clickhouseinfra provides a set of functions to interact with ClickHouse containers.
package clickhouseinfra

import (
Expand All @@ -20,6 +21,8 @@ type ColInfo struct {
Type string
Comment string
}

// Container is a struct that holds the clickhouse and zookeeper containers.
type Container struct {
*chmodule.ClickHouseContainer
ZooKeeperContainer testcontainers.Container
Expand All @@ -37,7 +40,7 @@ func CreateClickHouseContainer(ctx context.Context, userName, password string) (
}
ipaddr, err := zkcontainer.ContainerIP(ctx)
if err != nil {
zkcontainer.Terminate(ctx)
_ = zkcontainer.Terminate(ctx)
return nil, fmt.Errorf("failed to get zookeeper container IP: %w", err)
}
clickHouseContainer, err := chmodule.RunContainer(ctx,
Expand All @@ -48,7 +51,7 @@ func CreateClickHouseContainer(ctx context.Context, userName, password string) (
chmodule.WithZookeeper(ipaddr, zkPort),
)
if err != nil {
zkcontainer.Terminate(ctx)
_ = zkcontainer.Terminate(ctx)
return nil, fmt.Errorf("failed to start clickhouse container: %w", err)
}
return &Container{clickHouseContainer, zkcontainer}, nil
Expand Down Expand Up @@ -94,7 +97,7 @@ func GetClickhouseAsDB(ctx context.Context, container *chmodule.ClickHouseContai
return dbConn, nil
}

// Terminate function terminates the clickhouse container.
// Terminate function terminates the clickhouse and zookeeper containers.
// If an error occurs, it will be printed to stderr.
func (c *Container) Terminate(ctx context.Context) {
if err := c.ClickHouseContainer.Terminate(ctx); err != nil {
Expand All @@ -112,7 +115,7 @@ func GetCurrentCols(ctx context.Context, chConn clickhouse.Conn, tableName strin
if err != nil {
return nil, fmt.Errorf("failed to show table: %w", err)
}
defer rows.Close()
defer rows.Close() //nolint // we are not interested in the error here
colInfos := []ColInfo{}
count := 0
for rows.Next() {
Expand All @@ -127,6 +130,7 @@ func GetCurrentCols(ctx context.Context, chConn clickhouse.Conn, tableName strin
return colInfos, nil
}

// StartZooKeeperContainer function starts a zookeeper container. The caller is responsible for terminating the container.
func StartZooKeeperContainer(ctx context.Context) (testcontainers.Container, string, error) {
zkPort := nat.Port("2181/tcp")

Expand Down
1 change: 1 addition & 0 deletions pkg/migrations/20240402091429_init.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ func downInit(ctx context.Context, tx *sql.Tx) error {
return nil
}

//nolint:misspell // false positive
const createDIMOtableStatement = `CREATE TABLE IF NOT EXISTS dimo (
DefinitionID String COMMENT 'ID for the vehicles definition',
Source String COMMENT 'where the data was sourced from',
Expand Down
2 changes: 2 additions & 0 deletions pkg/runner/runner.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// Package runner is a package that provides a programmatic interface to the code generation tool.
package runner

import (
Expand Down Expand Up @@ -25,6 +26,7 @@ const (
MigrationGenerator = "migration"
)

// Config is the configuration for the code generation tool.
type Config struct {
PackageName string
OutputDir string
Expand Down
1 change: 1 addition & 0 deletions pkg/vss/convert/payloadv1.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// Package convert provides a function to generate conversion functions for a vehicle struct.
package convert

import (
Expand Down
Loading

0 comments on commit 512a43c

Please sign in to comment.