Skip to content

Commit

Permalink
lint: Fix errcheck
Browse files Browse the repository at this point in the history
  • Loading branch information
sue445 committed Jul 13, 2024
1 parent cd01573 commit 8169d01
Show file tree
Hide file tree
Showing 7 changed files with 30 additions and 16 deletions.
2 changes: 1 addition & 1 deletion adapter/mysql/adapter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ func withDatabase(callback func(*Adapter)) {
panic(err)
}

defer close()
defer close() //nolint:errcheck

adapter.db.MustExec("DROP TABLE IF EXISTS followers;")
adapter.db.MustExec("DROP TABLE IF EXISTS articles;")
Expand Down
2 changes: 1 addition & 1 deletion adapter/oracle/adapter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ func withDatabase(callback func(*Adapter)) {
panic(err)
}

defer close()
defer close() //nolint:errcheck

// adapter.db.MustExec("DROP TABLE followers")
// adapter.db.MustExec("DROP TABLE articles")
Expand Down
2 changes: 1 addition & 1 deletion adapter/postgresql/adapter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ func withDatabase(callback func(*Adapter)) {
panic(err)
}

defer close()
defer close() //nolint:errcheck

adapter.db.MustExec("DROP TABLE IF EXISTS followers;")
adapter.db.MustExec("DROP TABLE IF EXISTS articles;")
Expand Down
2 changes: 1 addition & 1 deletion adapter/sqlite3/adapter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ func withDatabase(callback func(*Adapter)) {
panic(err)
}

defer close()
defer close() //nolint:errcheck

adapter.DB.MustExec("PRAGMA foreign_keys = ON;")

Expand Down
4 changes: 2 additions & 2 deletions cmd/plant_erd-oracle/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,14 +75,14 @@ func main() {
return errors.WithStack(err)
}

defer close()
defer close() //nolint:errcheck

schema, err := lib.LoadSchema(adapter)
if err != nil {
return errors.WithStack(err)
}

return generator.Run(schema)
return generator.Run(schema) //nolint:errcheck
}

sort.Sort(cli.CommandsByName(app.Commands))
Expand Down
8 changes: 4 additions & 4 deletions cmd/plant_erd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,14 +60,14 @@ func main() {
return errors.WithStack(err)
}

defer close()
defer close() //nolint:errcheck

schema, err := lib.LoadSchema(adapter)
if err != nil {
return errors.WithStack(err)
}

return generator.Run(schema)
return generator.Run(schema) //nolint:errcheck
},
},
{
Expand Down Expand Up @@ -135,7 +135,7 @@ func main() {
return errors.WithStack(err)
}

return generator.Run(schema)
return generator.Run(schema) //nolint:errcheck
},
},
{
Expand Down Expand Up @@ -199,7 +199,7 @@ func main() {
return errors.WithStack(err)
}

return generator.Run(schema)
return generator.Run(schema) //nolint:errcheck
},
},
}
Expand Down
26 changes: 20 additions & 6 deletions lib/erd_generator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package lib

import (
"bytes"
"github.com/stretchr/testify/require"
"io"
"os"
"path/filepath"
Expand All @@ -19,7 +20,7 @@ func withDatabase(callback func(*sqlite3.Adapter)) {
panic(err)
}

defer close()
defer close() //nolint:errcheck

adapter.DB.MustExec("PRAGMA foreign_keys = ON;")

Expand Down Expand Up @@ -214,7 +215,8 @@ func TestErdGenerator_output_ToFile(t *testing.T) {
Filepath: filePath,
}

g.output("aaa")
err := g.output("aaa")
require.NoError(t, err)

data, err := os.ReadFile(filePath)

Expand All @@ -237,10 +239,16 @@ func captureStdout(f func()) string {
f()

os.Stdout = stdout
w.Close()
err = w.Close()
if err != nil {
panic(err)
}

var buf bytes.Buffer
io.Copy(&buf, r)
_, err = io.Copy(&buf, r)
if err != nil {
panic(err)
}

return buf.String()
}
Expand Down Expand Up @@ -512,7 +520,10 @@ func ExampleErdGenerator_Run_two_tables_with_PlantUML() {
}

generator := ErdGenerator{Format: "plant_uml"}
generator.Run(schema)
err = generator.Run(schema)
if err != nil {
panic(err)
}

// Output:
// entity articles {
Expand Down Expand Up @@ -634,7 +645,10 @@ func ExampleErdGenerator_Run_many_tables_within_a_distance_of_1_from_the_article
}

generator := ErdGenerator{Format: "plant_uml", Table: "articles", Distance: 1}
generator.Run(schema)
err = generator.Run(schema)
if err != nil {
panic(err)
}

// Output:
// entity articles {
Expand Down

0 comments on commit 8169d01

Please sign in to comment.