Add 'unused' lint (#241)

* Add 'unused' lint

* Keep testdata consts
This commit is contained in:
Erik Johnston 2017-09-20 14:47:29 +01:00 committed by GitHub
parent cc2f755cb3
commit 584acbe9a9
7 changed files with 5 additions and 32 deletions

View File

@ -17,6 +17,7 @@
"unparam",
"errcheck",
"vet",
"unused",
"gosimple"
]
}

View File

@ -51,14 +51,10 @@ const selectMembershipsByLocalpartSQL = "" +
const deleteMembershipsByEventIDsSQL = "" +
"DELETE FROM account_memberships WHERE event_id = ANY($1)"
const updateMembershipByEventIDSQL = "" +
"UPDATE account_memberships SET event_id = $2 WHERE event_id = $1"
type membershipStatements struct {
deleteMembershipsByEventIDsStmt *sql.Stmt
insertMembershipStmt *sql.Stmt
selectMembershipsByLocalpartStmt *sql.Stmt
updateMembershipByEventIDStmt *sql.Stmt
}
func (s *membershipStatements) prepare(db *sql.DB) (err error) {
@ -75,9 +71,6 @@ func (s *membershipStatements) prepare(db *sql.DB) (err error) {
if s.selectMembershipsByLocalpartStmt, err = db.Prepare(selectMembershipsByLocalpartSQL); err != nil {
return
}
if s.updateMembershipByEventIDStmt, err = db.Prepare(updateMembershipByEventIDSQL); err != nil {
return
}
return
}
@ -120,12 +113,3 @@ func (s *membershipStatements) selectMembershipsByLocalpart(
return
}
func (s *membershipStatements) updateMembershipByEventID(
ctx context.Context, oldEventID string, newEventID string,
) (err error) {
_, err = s.updateMembershipByEventIDStmt.ExecContext(
ctx, oldEventID, newEventID,
)
return
}

View File

@ -14,7 +14,7 @@
package main
// nolint: varcheck, deadcode
// nolint: varcheck, deadcode, unused
const (
i0StateRoomCreate = iota
i1StateAliceJoin

View File

@ -47,6 +47,7 @@ type PartitionOffsetStatements struct {
// Prepare converts the raw SQL statements into prepared statements.
// Takes a prefix to prepend to the table name used to store the partition offsets.
// This allows multiple components to share the same database schema.
// nolint: safesql
func (s *PartitionOffsetStatements) Prepare(db *sql.DB, prefix string) (err error) {
_, err = db.Exec(strings.Replace(partitionOffsetsSchema, "${prefix}", prefix, -1))
if err != nil {

View File

@ -134,6 +134,7 @@ type publicRoomsStatements struct {
updateRoomAttributeStmts map[string]*sql.Stmt
}
// nolint: safesql
func (s *publicRoomsStatements) prepare(db *sql.DB) (err error) {
_, err = db.Exec(publicRoomsSchema)
if err != nil {

View File

@ -60,10 +60,6 @@ const bulkSelectEventStateKeyNIDSQL = "" +
"SELECT event_state_key, event_state_key_nid FROM roomserver_event_state_keys" +
" WHERE event_state_key = ANY($1)"
const selectEventStateKeySQL = "" +
"SELECT event_state_key FROM roomserver_event_state_keys" +
" WHERE event_state_key_nid = $1"
// Bulk lookup from numeric ID to string state key for that state key.
// Takes an array of strings as the query parameter.
const bulkSelectEventStateKeySQL = "" +
@ -73,7 +69,6 @@ const bulkSelectEventStateKeySQL = "" +
type eventStateKeyStatements struct {
insertEventStateKeyNIDStmt *sql.Stmt
selectEventStateKeyNIDStmt *sql.Stmt
selectEventStateKeyStmt *sql.Stmt
bulkSelectEventStateKeyNIDStmt *sql.Stmt
bulkSelectEventStateKeyStmt *sql.Stmt
}
@ -86,7 +81,6 @@ func (s *eventStateKeyStatements) prepare(db *sql.DB) (err error) {
return statementList{
{&s.insertEventStateKeyNIDStmt, insertEventStateKeyNIDSQL},
{&s.selectEventStateKeyNIDStmt, selectEventStateKeyNIDSQL},
{&s.selectEventStateKeyStmt, selectEventStateKeySQL},
{&s.bulkSelectEventStateKeyNIDStmt, bulkSelectEventStateKeyNIDSQL},
{&s.bulkSelectEventStateKeyStmt, bulkSelectEventStateKeySQL},
}.prepare(db)
@ -133,15 +127,6 @@ func (s *eventStateKeyStatements) bulkSelectEventStateKeyNID(
return result, nil
}
func (s *eventStateKeyStatements) selectEventStateKey(
ctx context.Context, txn *sql.Tx, eventStateKeyNID types.EventStateKeyNID,
) (string, error) {
var eventStateKey string
stmt := common.TxStmt(txn, s.selectEventStateKeyStmt)
err := stmt.QueryRowContext(ctx, eventStateKeyNID).Scan(&eventStateKey)
return eventStateKey, err
}
func (s *eventStateKeyStatements) bulkSelectEventStateKey(
ctx context.Context, eventStateKeyNIDs []types.EventStateKeyNID,
) (map[types.EventStateKeyNID]string, error) {

View File

@ -25,6 +25,7 @@ type statementList []struct {
}
// prepare the SQL for each statement in the list and assign the result to the prepared statement.
// nolint: safesql
func (s statementList) prepare(db *sql.DB) (err error) {
for _, statement := range s {
if *statement.statement, err = db.Prepare(statement.sql); err != nil {