Skip to content

Commit

Permalink
fix: lint
Browse files Browse the repository at this point in the history
  • Loading branch information
richard-ramos committed Jan 12, 2024
1 parent df69819 commit f245a83
Show file tree
Hide file tree
Showing 39 changed files with 157 additions and 115 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ install-gomobile: ##@install Go Mobile Build Tools
GO111MODULE=off go get -d golang.org/x/mobile/cmd/gobind

install-lint: ##@install Install Linting Tools
GO111MODULE=on go install github.com/golangci/golangci-lint/cmd/golangci-lint@v1.52.2
GO111MODULE=on go install github.com/golangci/golangci-lint/cmd/golangci-lint@v1.55.2

install-junit-report: ##@install Install Junit Report Tool for Jenkins integration
GO111MODULE=on go install github.com/jstemmer/go-junit-report/v2@latest
Expand Down
8 changes: 4 additions & 4 deletions api/backend_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -763,7 +763,7 @@ func TestLoginAccount(t *testing.T) {
Password: password,
BackupDisabledDataDir: tmpdir,
NetworkID: 1,
LogFilePath: tmpdir + "/log",
LogFilePath: tmpdir + "/log", // nolint: goconst
}
c := make(chan interface{}, 10)
signal.SetMobileSignalHandler(func(data []byte) {
Expand Down Expand Up @@ -914,7 +914,7 @@ func TestConvertAccount(t *testing.T) {
const keycardPassword = "222222" // represents password for a keycard user
const keycardUID = "1234"
const pathEIP1581Root = "m/43'/60'/1581'"
const pathEIP1581Chat = pathEIP1581Root + "/0'/0"
const pathEIP1581Chat = pathEIP1581Root + "/0'/0" // nolint: goconst
const pathWalletRoot = "m/44'/60'/0'/0"
const pathDefaultWalletAccount = pathWalletRoot + "/0"
const customWalletPath1 = pathWalletRoot + "/1"
Expand Down Expand Up @@ -1308,7 +1308,7 @@ func TestCreateWallet(t *testing.T) {
Password: password,
BackupDisabledDataDir: tmpdir,
NetworkID: 1,
LogFilePath: tmpdir + "/log",
LogFilePath: tmpdir + "/log", // nolint: goconst
}
c := make(chan interface{}, 10)
signal.SetMobileSignalHandler(func(data []byte) {
Expand Down Expand Up @@ -1367,7 +1367,7 @@ func TestSetFleet(t *testing.T) {
Password: password,
BackupDisabledDataDir: tmpdir,
NetworkID: 1,
LogFilePath: tmpdir + "/log",
LogFilePath: tmpdir + "/log", // nolint: goconst
Emoji: "some",
}
c := make(chan interface{}, 10)
Expand Down
2 changes: 1 addition & 1 deletion api/defaults.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import (

const pathWalletRoot = "m/44'/60'/0'/0"
const pathEIP1581 = "m/43'/60'/1581'"
const pathDefaultChat = pathEIP1581 + "/0'/0"
const pathDefaultChat = pathEIP1581 + "/0'/0" // nolint: goconst
const pathDefaultWallet = pathWalletRoot + "/0"
const defaultMnemonicLength = 12
const shardsTestClusterID = 16
Expand Down
22 changes: 12 additions & 10 deletions api/geth_backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,8 @@ var (
ErrConfigNotAvailable = errors.New("NodeConfig is not available")
)

const shm = "-shm"

var _ StatusBackend = (*GethStatusBackend)(nil)

// GethStatusBackend implements the Status.im service over go-ethereum
Expand Down Expand Up @@ -269,11 +271,11 @@ func (b *GethStatusBackend) DeleteMultiaccount(keyUID string, keyStoreDir string
filepath.Join(b.rootDataDir, fmt.Sprintf("%s.db-shm", keyUID)),
filepath.Join(b.rootDataDir, fmt.Sprintf("%s.db-wal", keyUID)),
appDbPath,
appDbPath + "-shm",
appDbPath + "-wal",
appDbPath + shm,
appDbPath + "-wal", // nolint: goconst
walletDbPath,
walletDbPath + "-shm",
walletDbPath + "-wal",
walletDbPath + shm,
walletDbPath + "-wal", // nolint: goconst
}
for _, path := range dbFiles {
if _, err := os.Stat(path); err == nil {
Expand Down Expand Up @@ -332,19 +334,19 @@ func (b *GethStatusBackend) runDBFileMigrations(account multiaccounts.Account, p
}

// rename journals as well, but ignore errors
_ = os.Rename(unsupportedPath+"-shm", v3Path+"-shm")
_ = os.Rename(unsupportedPath+shm, v3Path+shm)
_ = os.Rename(unsupportedPath+"-wal", v3Path+"-wal")
}

if _, err = os.Stat(v3Path); err == nil {
if err := appdatabase.MigrateV3ToV4(v3Path, v4Path, password, account.KDFIterations, signal.SendReEncryptionStarted, signal.SendReEncryptionFinished); err != nil {
_ = os.Remove(v4Path)
_ = os.Remove(v4Path + "-shm")
_ = os.Remove(v4Path + shm)
_ = os.Remove(v4Path + "-wal")
return "", errors.New("Failed to migrate v3 db to v4: " + err.Error())
}
_ = os.Remove(v3Path)
_ = os.Remove(v3Path + "-shm")
_ = os.Remove(v3Path + shm)
_ = os.Remove(v3Path + "-wal")
}

Expand Down Expand Up @@ -1096,7 +1098,7 @@ func (b *GethStatusBackend) createTempDBFile(pattern string) (tmpDbPath string,
_ = file.Close()
_ = os.Remove(filePath)
_ = os.Remove(filePath + "-wal")
_ = os.Remove(filePath + "-shm")
_ = os.Remove(filePath + shm)
_ = os.Remove(filePath + "-journal")
}
return
Expand All @@ -1110,9 +1112,9 @@ func replaceDBFile(dbPath string, newDBPath string) (cleanup func(), err error)

cleanup = func() {
_ = os.Remove(dbPath + "-wal")
_ = os.Remove(dbPath + "-shm")
_ = os.Remove(dbPath + shm)
_ = os.Rename(newDBPath+"-wal", dbPath+"-wal")
_ = os.Rename(newDBPath+"-shm", dbPath+"-shm")
_ = os.Rename(newDBPath+shm, dbPath+shm)
}

return
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ require (
github.com/mutecomm/go-sqlcipher/v4 v4.4.2
github.com/schollz/peerdiscovery v1.7.0
github.com/siphiuel/lc-proxy-wrapper v0.0.0-20230516150924-246507cee8c7
github.com/waku-org/go-waku v0.8.1-0.20240103095929-0dec3201773a
github.com/waku-org/go-waku v0.8.1-0.20240112174027-faf046e059a5
github.com/wk8/go-ordered-map/v2 v2.1.7
github.com/yeqown/go-qrcode/v2 v2.2.1
github.com/yeqown/go-qrcode/writer/standard v1.2.1
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -2123,8 +2123,8 @@ github.com/waku-org/go-discover v0.0.0-20221209174356-61c833f34d98 h1:xwY0kW5XZF
github.com/waku-org/go-discover v0.0.0-20221209174356-61c833f34d98/go.mod h1:eBHgM6T4EG0RZzxpxKy+rGz/6Dw2Nd8DWxS0lm9ESDw=
github.com/waku-org/go-libp2p-rendezvous v0.0.0-20240110193335-a67d1cc760a0 h1:R4YYx2QamhBRl/moIxkDCNW+OP7AHbyWLBygDc/xIMo=
github.com/waku-org/go-libp2p-rendezvous v0.0.0-20240110193335-a67d1cc760a0/go.mod h1:EhZP9fee0DYjKH/IOQvoNSy1tSHp2iZadsHGphcAJgY=
github.com/waku-org/go-waku v0.8.1-0.20240103095929-0dec3201773a h1:SGgdeFGSytDYpLmAJX/xlDsnUvi5aP096R1aroWJhkM=
github.com/waku-org/go-waku v0.8.1-0.20240103095929-0dec3201773a/go.mod h1:aT3Fx2CyP6NP7lDUqNDg6dwCGumkbIksu/xMq3ue4GI=
github.com/waku-org/go-waku v0.8.1-0.20240112174027-faf046e059a5 h1:D/IVX11ZKKUoBm9paWQFVyXyXFYAuovuqQzo9gUnqlE=
github.com/waku-org/go-waku v0.8.1-0.20240112174027-faf046e059a5/go.mod h1:nUmz07T/miK91i9b7vCIV4QN+fWElmkClvqd+1Wd9w4=
github.com/waku-org/go-zerokit-rln v0.1.14-0.20240102145250-fa738c0bdf59 h1:jisj+OCI6QydLtFq3Pyhu49wl9ytPN7oAHjMfepHDrA=
github.com/waku-org/go-zerokit-rln v0.1.14-0.20240102145250-fa738c0bdf59/go.mod h1:1PdBdPzyTaKt3VnpAHk3zj+r9dXPFOr3IHZP9nFle6E=
github.com/waku-org/go-zerokit-rln-apple v0.0.0-20230916172309-ee0ee61dde2b h1:KgZVhsLkxsj5gb/FfndSCQu6VYwALrCOgYI3poR95yE=
Expand Down
4 changes: 2 additions & 2 deletions images/decode_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,15 +120,15 @@ func TestDecodeFromURL(t *testing.T) {
},
},
{
s.URL + "/1.webp",
s.URL + "/1.webp", // nolint: goconst
false,
image.Rectangle{
Min: image.Point{X: 0, Y: 0},
Max: image.Point{X: 1, Y: 1},
},
},
{
s.URL + "/1.webp",
s.URL + "/1.webp", // nolint: goconst
true,
image.Rectangle{
Min: image.Point{X: 0, Y: 0},
Expand Down
2 changes: 2 additions & 0 deletions mailserver/mailserver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ func (s *MailserverSuite) TestInit() {
}

for _, tc := range testCases {
tc := tc
s.T().Run(tc.info, func(*testing.T) {
mailServer := &WakuMailServer{}
shh := waku.New(&waku.DefaultConfig, nil)
Expand Down Expand Up @@ -300,6 +301,7 @@ func (s *MailserverSuite) TestMailServer() {
},
}
for _, tc := range testCases {
tc := tc
s.T().Run(tc.info, func(*testing.T) {
request := s.createRequest(tc.params)
src := crypto.FromECDSAPub(&tc.params.key.PublicKey)
Expand Down
10 changes: 5 additions & 5 deletions multiaccounts/accounts/database_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -231,9 +231,9 @@ func TestWatchOnlyAccounts(t *testing.T) {
require.Equal(t, wo4.Address, dbAcc.Address)

// updated watch onl to save the same account after it's saved
wo4.Name = wo4.Name + "updated"
wo4.Name = wo4.Name + "updated" // nolint: goconst
wo4.ColorID = common.CustomizationColorCamel
wo4.Emoji = wo4.Emoji + "updated"
wo4.Emoji = wo4.Emoji + "updated" // nolint: goconst
err = db.SaveOrUpdateAccounts([]*Account{wo4}, false)
require.NoError(t, err)
dbAccounts, err = db.GetActiveAccounts()
Expand Down Expand Up @@ -279,7 +279,7 @@ func TestUpdateKeypairName(t *testing.T) {
require.True(t, SameKeypairs(kp, dbKeypairs[0]))

// update keypair name
kp.Name = kp.Name + "updated"
kp.Name = kp.Name + "updated" // nolint: goconst
kp.Accounts[0].Name = kp.Name
err = db.UpdateKeypairName(kp.KeyUID, kp.Name, kp.Clock, true)
require.NoError(t, err)
Expand Down Expand Up @@ -360,9 +360,9 @@ func TestKeypairs(t *testing.T) {
require.Equal(t, len(kp.Accounts), len(dbAccounts))

// update an existing account
accToUpdate.Name = accToUpdate.Name + "updated"
accToUpdate.Name = accToUpdate.Name + "updated" // nolint: goconst
accToUpdate.ColorID = common.CustomizationColorBrown
accToUpdate.Emoji = accToUpdate.Emoji + "updated"
accToUpdate.Emoji = accToUpdate.Emoji + "updated" // nolint: goconst

err = db.SaveOrUpdateAccounts([]*Account{accToUpdate}, false)
require.NoError(t, err)
Expand Down
9 changes: 1 addition & 8 deletions multiaccounts/accounts/keycard_database.go
Original file line number Diff line number Diff line change
Expand Up @@ -263,14 +263,7 @@ func (db *Database) deleteKeycardAccounts(tx *sql.Tx, kcUID string, accountAddre
}

inVector := strings.Repeat(",?", len(accountAddresses)-1)
query := `
DELETE
FROM
keycards_accounts
WHERE
keycard_uid = ?
AND
account_address IN (?` + inVector + `)`
query := `DELETE FROM keycards_accounts WHERE keycard_uid = ? AND account_address IN (?` + inVector + `)` // nolint: gosec

delete, err := tx.Prepare(query)
if err != nil {
Expand Down
4 changes: 2 additions & 2 deletions multiaccounts/accounts/keycard_database_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ func TestKeycards(t *testing.T) {

keycard2Copy := GetKeycardForSeedImportedKeypair1ForTest()
keycard2Copy.KeycardUID = keycard2Copy.KeycardUID + "C"
keycard2Copy.KeycardName = keycard2Copy.KeycardName + "Copy"
keycard2Copy.KeycardName = keycard2Copy.KeycardName + "Copy" // nolint: goconst
keycard2Copy.Position = keycard2Copy.Position + 1

// Pre-condition
Expand Down Expand Up @@ -162,7 +162,7 @@ func TestKeycardsRemovalWhenDeletingKeypair(t *testing.T) {

keycard2Copy := GetKeycardForSeedImportedKeypair1ForTest()
keycard2Copy.KeycardUID = keycard2Copy.KeycardUID + "C"
keycard2Copy.KeycardName = keycard2Copy.KeycardName + "Copy"
keycard2Copy.KeycardName = keycard2Copy.KeycardName + "Copy" // nolint: goconst
keycard2Copy.Position = keycard2Copy.Position + 1

// Pre-condition
Expand Down
4 changes: 2 additions & 2 deletions protocol/activity_center_persistence.go
Original file line number Diff line number Diff line change
Expand Up @@ -813,7 +813,7 @@ func (db sqlitePersistence) MarkActivityCenterNotificationsDeleted(ids []types.H
return nil, err
}

update := "UPDATE activity_center_notifications SET deleted = 1, updated_at = ? WHERE id IN (" + inVector + ") AND NOT deleted"
update := "UPDATE activity_center_notifications SET deleted = 1, updated_at = ? WHERE id IN (" + inVector + ") AND NOT deleted" // nolint: goconst, gosec
_, err = tx.Exec(update, args...)
if err != nil {
return nil, err
Expand Down Expand Up @@ -1072,7 +1072,7 @@ func (db sqlitePersistence) AcceptActivityCenterNotifications(ids []types.HexByt
}

inVector := strings.Repeat("?, ", len(ids)-1) + "?"
query := "UPDATE activity_center_notifications SET read = 1, accepted = 1, updated_at = ? WHERE id IN (" + inVector + ") AND NOT deleted AND updated_at < ?" // nolint: gosec
query := "UPDATE activity_center_notifications SET read = 1, accepted = 1, updated_at = ? WHERE id IN (" + inVector + ") AND NOT deleted AND updated_at < ?" // nolint: gosec, goconst
_, err = tx.Exec(query, args...)
if err != nil {
return nil, err
Expand Down
8 changes: 4 additions & 4 deletions protocol/communities/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -3704,8 +3704,8 @@ func (m *Manager) CreateHistoryArchiveTorrent(communityID types.HexBytes, msgs [

archiveDir := m.torrentConfig.DataDir + "/" + communityID.String()
torrentDir := m.torrentConfig.TorrentDir
indexPath := archiveDir + "/index"
dataPath := archiveDir + "/data"
indexPath := archiveDir + "/index" // nolint: goconst
dataPath := archiveDir + "/data" // nolint: goconst

wakuMessageArchiveIndexProto := &protobuf.WakuMessageArchiveIndex{}
wakuMessageArchiveIndex := make(map[string]*protobuf.WakuMessageArchiveIndexMetadata)
Expand Down Expand Up @@ -4399,11 +4399,11 @@ func (m *Manager) torrentFile(communityID string) string {
}

func (m *Manager) archiveIndexFile(communityID string) string {
return m.torrentConfig.DataDir + "/" + communityID + "/index"
return m.torrentConfig.DataDir + "/" + communityID + "/index" // nolint: goconst
}

func (m *Manager) archiveDataFile(communityID string) string {
return m.torrentConfig.DataDir + "/" + communityID + "/data"
return m.torrentConfig.DataDir + "/" + communityID + "/data" // nolint: goconst
}

func topicsAsByteArrays(topics []types.TopicType) [][]byte {
Expand Down
6 changes: 3 additions & 3 deletions protocol/communities/persistence.go
Original file line number Diff line number Diff line change
Expand Up @@ -923,7 +923,7 @@ func (p *Persistence) SaveWakuMessage(message *types.Message) error {
func wakuMessageTimestampQuery(topics []types.TopicType) string {
query := " FROM waku_messages WHERE "
for i, topic := range topics {
query += `topic = "` + topic.String() + `"`
query += `topic = "` + topic.String() + `"` // nolint: goconst
if i < len(topics)-1 {
query += OR
}
Expand All @@ -949,10 +949,10 @@ func (p *Persistence) GetLatestWakuMessageTimestamp(topics []types.TopicType) (u

func (p *Persistence) GetWakuMessagesByFilterTopic(topics []types.TopicType, from uint64, to uint64) ([]types.Message, error) {

query := "SELECT sig, timestamp, topic, payload, padding, hash, third_party_id FROM waku_messages WHERE timestamp >= " + fmt.Sprint(from) + " AND timestamp < " + fmt.Sprint(to) + " AND ("
query := "SELECT sig, timestamp, topic, payload, padding, hash, third_party_id FROM waku_messages WHERE timestamp >= " + fmt.Sprint(from) + " AND timestamp < " + fmt.Sprint(to) + " AND (" // nolint: gosec

for i, topic := range topics {
query += `topic = "` + topic.String() + `"`
query += `topic = "` + topic.String() + `"` // nolint: goconst
if i < len(topics)-1 {
query += OR
}
Expand Down
2 changes: 1 addition & 1 deletion protocol/message_persistence.go
Original file line number Diff line number Diff line change
Expand Up @@ -1483,7 +1483,7 @@ func (db sqlitePersistence) SaveMessages(messages []*common.Message) (err error)

allFields := db.tableUserMessagesAllFields()
valuesVector := strings.Repeat("?, ", db.tableUserMessagesAllFieldsCount()-1) + "?"
query := "INSERT INTO user_messages(" + allFields + ") VALUES (" + valuesVector + ")" // nolint: gosec
query := "INSERT INTO user_messages(" + allFields + ") VALUES (" + valuesVector + ")" // nolint: gosec, goconst
stmt, err := tx.Prepare(query)
if err != nil {
return
Expand Down
4 changes: 2 additions & 2 deletions protocol/messenger_testing_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ func WaitOnSignaledMessengerResponse(m *Messenger, condition func(*MessengerResp
return nil, errors.New(errorMessage)

case <-timeoutChan:
return nil, errors.New("timed out: " + errorMessage)
return nil, errors.New("timed out: " + errorMessage) // nolint: goconst

default: // No immediate response, rest & loop back to retrieve again
time.Sleep(interval)
Expand Down Expand Up @@ -145,7 +145,7 @@ func WaitOnSignaledCommunityFound(m *Messenger, action func(), condition func(co
return nil
}
case <-timeoutChan:
return errors.New("timed out: " + errorMessage)
return errors.New("timed out: " + errorMessage) // nolint: goconst
}
}
}
Expand Down
3 changes: 3 additions & 0 deletions protocol/transport/filters_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,8 @@ func (f *FiltersManager) InitCommunityFilters(communityFiltersToInitialize []Com
defer f.mutex.Unlock()

for _, cf := range communityFiltersToInitialize {
cf := cf

if cf.PrivKey == nil {
continue
}
Expand All @@ -164,6 +166,7 @@ func (f *FiltersManager) InitCommunityFilters(communityFiltersToInitialize []Com
}

for _, pubsubTopic := range topics {
pubsubTopic := pubsubTopic
pk := &cf.PrivKey.PublicKey
identityStr := PublicKeyToStr(pk)
rawFilter, err := f.addAsymmetric(identityStr, pubsubTopic, cf.PrivKey, true)
Expand Down
4 changes: 2 additions & 2 deletions protocol/transport/topic.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,15 @@ func PublicKeyToStr(publicKey *ecdsa.PublicKey) string {
}

func PersonalDiscoveryTopic(publicKey *ecdsa.PublicKey) string {
return "contact-discovery-" + PublicKeyToStr(publicKey)
return "contact-discovery-" + PublicKeyToStr(publicKey) // nolint: goconst
}

// PartitionedTopic returns the associated partitioned topic string
// with the given public key.
func PartitionedTopic(publicKey *ecdsa.PublicKey) string {
partition := big.NewInt(0)
partition.Mod(publicKey.X, nPartitions)
return "contact-discovery-" + strconv.FormatInt(partition.Int64(), 10)
return "contact-discovery-" + strconv.FormatInt(partition.Int64(), 10) // nolint: goconst
}

func ContactCodeTopic(publicKey *ecdsa.PublicKey) string {
Expand Down
8 changes: 4 additions & 4 deletions rpc/route_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@ func TestRouteWithUpstream(t *testing.T) {
router := newRouter(true)

for _, method := range remoteMethods {
require.True(t, router.routeRemote(method), "method "+method+" should routed to remote")
require.True(t, router.routeRemote(method), "method "+method+" should routed to remote") // nolint: goconst
}

for _, method := range localTestMethods {
t.Run(method, func(t *testing.T) {
require.False(t, router.routeRemote(method), "method "+method+" should routed to local")
require.False(t, router.routeRemote(method), "method "+method+" should routed to local") // nolint: goconst
})
}
}
Expand All @@ -27,11 +27,11 @@ func TestRouteWithoutUpstream(t *testing.T) {
router := newRouter(false)

for _, method := range remoteMethods {
require.False(t, router.routeRemote(method), "method "+method+" should routed to locally without UpstreamEnabled")
require.False(t, router.routeRemote(method), "method "+method+" should routed to locally without UpstreamEnabled") // nolint: goconst
}

for _, method := range localTestMethods {
require.False(t, router.routeRemote(method), "method "+method+" should routed to local")
require.False(t, router.routeRemote(method), "method "+method+" should routed to local") // nolint: goconst
}
}

Expand Down
Loading

0 comments on commit f245a83

Please sign in to comment.