Skip to content

Commit

Permalink
Fix reviewdog
Browse files Browse the repository at this point in the history
  • Loading branch information
nao1215 committed May 1, 2024
1 parent 643adca commit 712a01a
Show file tree
Hide file tree
Showing 12 changed files with 25 additions and 20 deletions.
2 changes: 1 addition & 1 deletion config/argument_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ func getStdout(t *testing.T, f func()) string {
Stdout = w

f()
w.Close() //nolint:errcheck
w.Close() //nolint

var buffer bytes.Buffer
if _, err := buffer.ReadFrom(r); err != nil {
Expand Down
11 changes: 8 additions & 3 deletions config/db.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ func NewInMemDB() (MemoryDB, func(), error) {
if err != nil {
return nil, nil, err
}
return MemoryDB(db), func() { db.Close() }, nil //nolint:errcheck
return MemoryDB(db), func() { db.Close() }, nil //nolint
}

// NewHistoryDB create *sql.DB for history.
Expand All @@ -32,7 +32,7 @@ func NewHistoryDB(c *Config) (HistoryDB, func(), error) {
if err != nil {
return nil, nil, err
}
return HistoryDB(db), func() { db.Close() }, nil //nolint:errcheck
return HistoryDB(db), func() { db.Close() }, nil //nolint
}

// InitSQLite3 registers the sqlite3 driver.
Expand All @@ -54,14 +54,19 @@ func (d sqliteDriver) Open(name string) (driver.Conn, error) {
if err != nil {
return conn, err
}
c := conn.(interface {
c, ok := conn.(interface {
Exec(stmt string, args []driver.Value) (driver.Result, error)
})
if !ok {
return nil, fmt.Errorf("connection does not support Exec method")
}

if _, err := c.Exec("PRAGMA foreign_keys = on;", nil); err != nil {
if err := conn.Close(); err != nil {
return nil, fmt.Errorf("failed to close connection: %w", err)
}
return nil, fmt.Errorf("failed to enable enable foreign keys: %w", err)
}

return conn, nil
}
2 changes: 1 addition & 1 deletion infrastructure/memory/sqlite3.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ func (r *sqlite3Repository) Query(ctx context.Context, query string) (*model.Tab
if err != nil {
return nil, err
}
defer rows.Close() //nolint:errcheck
defer rows.Close() //nolint

header, err := rows.Columns()
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion infrastructure/persistence/csv_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ func Test_csvRepository_List(t *testing.T) {
if err != nil {
t.Fatal(err)
}
defer f.Close() //nolint:errcheck
defer f.Close() //nolint

csv, err := cr.List(f)
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion infrastructure/persistence/ltsv_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ func Test_ltsvRepository_List(t *testing.T) {
if err != nil {
t.Fatal(err)
}
defer f.Close() //nolint:errcheck
defer f.Close() //nolint

ltsv, err := r.List(f)
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion infrastructure/persistence/tsv_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ func Test_tsvRepository_List(t *testing.T) {
if err != nil {
t.Fatal(err)
}
defer f.Close() //nolint:errcheck
defer f.Close() //nolint

tsv, err := r.List(f)
if err != nil {
Expand Down
4 changes: 2 additions & 2 deletions main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ func getStdoutForRunFunc(t *testing.T, f func([]string) int, list []string) []by
config.Stdout = w

f(list)
w.Close() //nolint:errcheck
w.Close() //nolint

var buffer bytes.Buffer
if _, err := buffer.ReadFrom(r); err != nil {
Expand All @@ -185,7 +185,7 @@ func getStdout(t *testing.T, f func()) []byte {
config.Stdout = w

f()
w.Close() //nolint:errcheck
w.Close() //nolint

var buffer bytes.Buffer
if _, err := buffer.ReadFrom(r); err != nil {
Expand Down
6 changes: 3 additions & 3 deletions shell/shell_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -811,7 +811,7 @@ func getStdoutForRunFunc(t *testing.T, f func() error) []byte {
if err := f(); err != nil {
t.Fatal(err)
}
w.Close() //nolint:errcheck
w.Close() //nolint

var buffer bytes.Buffer
if _, err := buffer.ReadFrom(r); err != nil {
Expand All @@ -834,7 +834,7 @@ func getStdout(t *testing.T, f func()) []byte {
config.Stdout = w

f()
w.Close() //nolint:errcheck
w.Close() //nolint

var buffer bytes.Buffer
if _, err := buffer.ReadFrom(r); err != nil {
Expand All @@ -857,7 +857,7 @@ func getExecStdOutput(t *testing.T, f func(string) error, arg string) ([]byte, e
config.Stdout = w

execErr := f(arg)
w.Close() //nolint:errcheck
w.Close() //nolint

var buffer bytes.Buffer
if _, err := buffer.ReadFrom(r); err != nil {
Expand Down
4 changes: 2 additions & 2 deletions usecase/csv.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ func (ci *CSVInteractor) List(csvFilePath string) (*model.CSV, error) {
if err != nil {
return nil, err
}
defer f.Close() //nolint:errcheck
defer f.Close() //nolint

csv, err := ci.Repository.List(f)
if err != nil {
Expand All @@ -41,7 +41,7 @@ func (ci *CSVInteractor) Dump(csvFilePath string, table *model.Table) error {
if err != nil {
return err
}
defer f.Close() //nolint:errcheck
defer f.Close() //nolint

return ci.Repository.Dump(f, table)
}
2 changes: 1 addition & 1 deletion usecase/json.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ func (i *JSONInteractor) Dump(jsonFilePath string, table *model.Table) error {
if err != nil {
return err
}
defer f.Close() //nolint:errcheck
defer f.Close() //nolint

return i.Repository.Dump(f, table)
}
4 changes: 2 additions & 2 deletions usecase/ltsv.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ func (li *LTSVInteractor) List(ltsvFilePath string) (*model.LTSV, error) {
if err != nil {
return nil, err
}
defer f.Close() //nolint:errcheck
defer f.Close() //nolint

TSV, err := li.Repository.List(f)
if err != nil {
Expand All @@ -38,7 +38,7 @@ func (li *LTSVInteractor) Dump(ltsvFilePath string, table *model.Table) error {
if err != nil {
return err
}
defer f.Close() //nolint:errcheck
defer f.Close() //nolint

return li.Repository.Dump(f, table)
}
4 changes: 2 additions & 2 deletions usecase/tsv.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ func (ti *TSVInteractor) List(TSVFilePath string) (*model.TSV, error) {
if err != nil {
return nil, err
}
defer f.Close() //nolint:errcheck
defer f.Close() //nolint

TSV, err := ti.Repository.List(f)
if err != nil {
Expand All @@ -40,7 +40,7 @@ func (ti *TSVInteractor) Dump(tsvFilePath string, table *model.Table) error {
if err != nil {
return err
}
defer f.Close() //nolint:errcheck
defer f.Close() //nolint

return ti.Repository.Dump(f, table)
}

0 comments on commit 712a01a

Please sign in to comment.