mirror of
https://github.com/1f349/dendrite.git
synced 2024-11-22 19:51:39 +00:00
Use gometalinter (#210)
* Remove unused struct field * Ignore unused test data * Remove unused variables * Remove deadcode * Fix up vetshadow warnings * Convert to using gometalinter * Update travis * Use vendored versions of gometalinter * Make gometalinter install its stuff * Vendor misspell
This commit is contained in:
parent
a26d7c2899
commit
2dcb3a11a5
@ -18,10 +18,6 @@ services:
|
|||||||
|
|
||||||
install:
|
install:
|
||||||
- go get github.com/constabulary/gb/...
|
- go get github.com/constabulary/gb/...
|
||||||
- go get github.com/golang/lint/golint
|
|
||||||
- go get github.com/fzipp/gocyclo
|
|
||||||
- go get github.com/client9/misspell/...
|
|
||||||
- go get github.com/gordonklaus/ineffassign
|
|
||||||
|
|
||||||
# Generate a self-signed X.509 certificate for TLS.
|
# Generate a self-signed X.509 certificate for TLS.
|
||||||
before_script:
|
before_script:
|
||||||
|
@ -2,29 +2,27 @@
|
|||||||
|
|
||||||
set -eu
|
set -eu
|
||||||
|
|
||||||
golint src/...
|
export GOPATH="$(pwd):$(pwd)/vendor"
|
||||||
|
export PATH="$PATH:$(pwd)/vendor/bin:$(pwd)/bin"
|
||||||
|
|
||||||
|
echo "Installing lint search engine..."
|
||||||
|
go install github.com/alecthomas/gometalinter/
|
||||||
|
gometalinter --config=linter.json ./... --install
|
||||||
|
|
||||||
|
echo "Looking for lint..."
|
||||||
|
gometalinter --config=linter.json ./...
|
||||||
|
|
||||||
|
echo "Double checking spelling..."
|
||||||
misspell -error src *.md
|
misspell -error src *.md
|
||||||
|
|
||||||
# gofmt doesn't exit with an error code if the files don't match the expected
|
echo "Testing..."
|
||||||
# format. So we have to run it and see if it outputs anything.
|
|
||||||
if gofmt -l -s ./src/ 2>&1 | read
|
|
||||||
then
|
|
||||||
echo "Error: not all code had been formatted with gofmt."
|
|
||||||
echo "Fixing the following files"
|
|
||||||
gofmt -s -w -l ./src/
|
|
||||||
echo
|
|
||||||
echo "Please add them to the commit"
|
|
||||||
git status --short
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
ineffassign ./src/
|
|
||||||
go tool vet --all --shadow ./src
|
|
||||||
gocyclo -over 12 src/
|
|
||||||
gb test
|
gb test
|
||||||
|
|
||||||
# Check that all the packages can build.
|
# Check that all the packages can build.
|
||||||
# When `go build` is given multiple packages it won't output anything, and just
|
# When `go build` is given multiple packages it won't output anything, and just
|
||||||
# checks that everything builds. This seems to do a better job of handling
|
# checks that everything builds. This seems to do a better job of handling
|
||||||
# missing imports than `gb build` does.
|
# missing imports than `gb build` does.
|
||||||
GOPATH=$(pwd):$(pwd)/vendor go build github.com/matrix-org/dendrite/cmd/...
|
echo "Double checking it builds..."
|
||||||
|
go build github.com/matrix-org/dendrite/cmd/...
|
||||||
|
|
||||||
|
echo "Done!"
|
||||||
|
17
linter.json
Normal file
17
linter.json
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
{
|
||||||
|
"Vendor": true,
|
||||||
|
"Cyclo": 12,
|
||||||
|
"Enable": [
|
||||||
|
"vetshadow",
|
||||||
|
"gotype",
|
||||||
|
"deadcode",
|
||||||
|
"gocyclo",
|
||||||
|
"golint",
|
||||||
|
"varcheck",
|
||||||
|
"structcheck",
|
||||||
|
"aligncheck",
|
||||||
|
"ineffassign",
|
||||||
|
"gas",
|
||||||
|
"misspell"
|
||||||
|
]
|
||||||
|
}
|
@ -47,9 +47,6 @@ const selectAccountDataSQL = "" +
|
|||||||
const selectAccountDataByTypeSQL = "" +
|
const selectAccountDataByTypeSQL = "" +
|
||||||
"SELECT content FROM account_data WHERE localpart = $1 AND room_id = $2 AND type = $3"
|
"SELECT content FROM account_data WHERE localpart = $1 AND room_id = $2 AND type = $3"
|
||||||
|
|
||||||
const deleteAccountDataSQL = "" +
|
|
||||||
"DELETE FROM account_data WHERE localpart = $1 AND room_id = $2 AND type = $3"
|
|
||||||
|
|
||||||
type accountDataStatements struct {
|
type accountDataStatements struct {
|
||||||
insertAccountDataStmt *sql.Stmt
|
insertAccountDataStmt *sql.Stmt
|
||||||
selectAccountDataStmt *sql.Stmt
|
selectAccountDataStmt *sql.Stmt
|
||||||
|
@ -56,7 +56,6 @@ const updateMembershipByEventIDSQL = "" +
|
|||||||
type membershipStatements struct {
|
type membershipStatements struct {
|
||||||
deleteMembershipsByEventIDsStmt *sql.Stmt
|
deleteMembershipsByEventIDsStmt *sql.Stmt
|
||||||
insertMembershipStmt *sql.Stmt
|
insertMembershipStmt *sql.Stmt
|
||||||
selectMembershipByEventIDStmt *sql.Stmt
|
|
||||||
selectMembershipsByLocalpartStmt *sql.Stmt
|
selectMembershipsByLocalpartStmt *sql.Stmt
|
||||||
updateMembershipByEventIDStmt *sql.Stmt
|
updateMembershipByEventIDStmt *sql.Stmt
|
||||||
}
|
}
|
||||||
|
@ -15,7 +15,6 @@
|
|||||||
package readers
|
package readers
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
"github.com/matrix-org/dendrite/clientapi/auth"
|
"github.com/matrix-org/dendrite/clientapi/auth"
|
||||||
@ -121,7 +120,3 @@ func Login(
|
|||||||
JSON: jsonerror.NotFound("Bad method"),
|
JSON: jsonerror.NotFound("Bad method"),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func makeUserID(localpart string, domain gomatrixserverlib.ServerName) string {
|
|
||||||
return fmt.Sprintf("@%s:%s", localpart, domain)
|
|
||||||
}
|
|
||||||
|
@ -49,13 +49,6 @@ var (
|
|||||||
format = flag.String("Format", "InputRoomEvent", "The output format to use for the messages: InputRoomEvent or Event")
|
format = flag.String("Format", "InputRoomEvent", "The output format to use for the messages: InputRoomEvent or Event")
|
||||||
)
|
)
|
||||||
|
|
||||||
func defaulting(value, defaultValue string) string {
|
|
||||||
if value == "" {
|
|
||||||
return defaultValue
|
|
||||||
}
|
|
||||||
return value
|
|
||||||
}
|
|
||||||
|
|
||||||
// By default we use a private key of 0.
|
// By default we use a private key of 0.
|
||||||
const defaultKey = "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"
|
const defaultKey = "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"
|
||||||
|
|
||||||
|
@ -197,7 +197,6 @@ func (m *monolith) setupFederation() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (m *monolith) setupKafka() {
|
func (m *monolith) setupKafka() {
|
||||||
var err error
|
|
||||||
if m.cfg.Kafka.UseNaffka {
|
if m.cfg.Kafka.UseNaffka {
|
||||||
naff, err := naffka.New(&naffka.MemoryDatabase{})
|
naff, err := naffka.New(&naffka.MemoryDatabase{})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -208,6 +207,7 @@ func (m *monolith) setupKafka() {
|
|||||||
m.naffka = naff
|
m.naffka = naff
|
||||||
m.kafkaProducer = naff
|
m.kafkaProducer = naff
|
||||||
} else {
|
} else {
|
||||||
|
var err error
|
||||||
m.kafkaProducer, err = sarama.NewSyncProducer(m.cfg.Kafka.Addresses, nil)
|
m.kafkaProducer, err = sarama.NewSyncProducer(m.cfg.Kafka.Addresses, nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.WithFields(log.Fields{
|
log.WithFields(log.Fields{
|
||||||
|
@ -221,14 +221,14 @@ func testRoomserver(input []string, wantOutput []string, checkQueries func(api.R
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
if err := test.WriteConfig(cfg, dir); err != nil {
|
if err = test.WriteConfig(cfg, dir); err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
outputTopic := string(cfg.Kafka.Topics.OutputRoomEvent)
|
outputTopic := string(cfg.Kafka.Topics.OutputRoomEvent)
|
||||||
|
|
||||||
exe.DeleteTopic(outputTopic)
|
exe.DeleteTopic(outputTopic)
|
||||||
if err := exe.CreateTopic(outputTopic); err != nil {
|
if err = exe.CreateTopic(outputTopic); err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -271,17 +271,6 @@ func testRoomserver(input []string, wantOutput []string, checkQueries func(api.R
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func canonicalJSONInput(jsonData []string) []string {
|
|
||||||
for i := range jsonData {
|
|
||||||
jsonBytes, err := gomatrixserverlib.CanonicalJSON([]byte(jsonData[i]))
|
|
||||||
if err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
jsonData[i] = string(jsonBytes)
|
|
||||||
}
|
|
||||||
return jsonData
|
|
||||||
}
|
|
||||||
|
|
||||||
func equalJSON(a, b string) bool {
|
func equalJSON(a, b string) bool {
|
||||||
canonicalA, err := gomatrixserverlib.CanonicalJSON([]byte(a))
|
canonicalA, err := gomatrixserverlib.CanonicalJSON([]byte(a))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -14,6 +14,7 @@
|
|||||||
|
|
||||||
package main
|
package main
|
||||||
|
|
||||||
|
// nolint: varcheck, deadcode
|
||||||
const (
|
const (
|
||||||
i0StateRoomCreate = iota
|
i0StateRoomCreate = iota
|
||||||
i1StateAliceJoin
|
i1StateAliceJoin
|
||||||
|
@ -99,14 +99,14 @@ type latestEventsUpdater struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (u *latestEventsUpdater) doUpdateLatestEvents() error {
|
func (u *latestEventsUpdater) doUpdateLatestEvents() error {
|
||||||
var err error
|
|
||||||
var prevEvents []gomatrixserverlib.EventReference
|
var prevEvents []gomatrixserverlib.EventReference
|
||||||
prevEvents = u.event.PrevEvents()
|
prevEvents = u.event.PrevEvents()
|
||||||
oldLatest := u.updater.LatestEvents()
|
oldLatest := u.updater.LatestEvents()
|
||||||
u.lastEventIDSent = u.updater.LastEventIDSent()
|
u.lastEventIDSent = u.updater.LastEventIDSent()
|
||||||
u.oldStateNID = u.updater.CurrentStateSnapshotNID()
|
u.oldStateNID = u.updater.CurrentStateSnapshotNID()
|
||||||
|
|
||||||
if hasBeenSent, err := u.updater.HasEventBeenSent(u.stateAtEvent.EventNID); err != nil {
|
hasBeenSent, err := u.updater.HasEventBeenSent(u.stateAtEvent.EventNID)
|
||||||
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
} else if hasBeenSent {
|
} else if hasBeenSent {
|
||||||
// Already sent this event so we can stop processing
|
// Already sent this event so we can stop processing
|
||||||
@ -119,8 +119,8 @@ func (u *latestEventsUpdater) doUpdateLatestEvents() error {
|
|||||||
|
|
||||||
eventReference := u.event.EventReference()
|
eventReference := u.event.EventReference()
|
||||||
// Check if this event is already referenced by another event in the room.
|
// Check if this event is already referenced by another event in the room.
|
||||||
var alreadyReferenced bool
|
alreadyReferenced, err := u.updater.IsReferenced(eventReference)
|
||||||
if alreadyReferenced, err = u.updater.IsReferenced(eventReference); err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -67,7 +67,7 @@ func (n *Notifier) OnNewEvent(ev *gomatrixserverlib.Event, userID string, pos ty
|
|||||||
userIDs := n.joinedUsers(ev.RoomID())
|
userIDs := n.joinedUsers(ev.RoomID())
|
||||||
// If this is an invite, also add in the invitee to this list.
|
// If this is an invite, also add in the invitee to this list.
|
||||||
if ev.Type() == "m.room.member" && ev.StateKey() != nil {
|
if ev.Type() == "m.room.member" && ev.StateKey() != nil {
|
||||||
userID := *ev.StateKey()
|
targetUserID := *ev.StateKey()
|
||||||
membership, err := ev.Membership()
|
membership, err := ev.Membership()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.WithError(err).WithField("event_id", ev.EventID()).Errorf(
|
log.WithError(err).WithField("event_id", ev.EventID()).Errorf(
|
||||||
@ -77,22 +77,22 @@ func (n *Notifier) OnNewEvent(ev *gomatrixserverlib.Event, userID string, pos ty
|
|||||||
// Keep the joined user map up-to-date
|
// Keep the joined user map up-to-date
|
||||||
switch membership {
|
switch membership {
|
||||||
case "invite":
|
case "invite":
|
||||||
userIDs = append(userIDs, userID)
|
userIDs = append(userIDs, targetUserID)
|
||||||
case "join":
|
case "join":
|
||||||
// Manually append the new user's ID so they get notified
|
// Manually append the new user's ID so they get notified
|
||||||
// along all members in the room
|
// along all members in the room
|
||||||
userIDs = append(userIDs, userID)
|
userIDs = append(userIDs, targetUserID)
|
||||||
n.addJoinedUser(ev.RoomID(), userID)
|
n.addJoinedUser(ev.RoomID(), targetUserID)
|
||||||
case "leave":
|
case "leave":
|
||||||
fallthrough
|
fallthrough
|
||||||
case "ban":
|
case "ban":
|
||||||
n.removeJoinedUser(ev.RoomID(), userID)
|
n.removeJoinedUser(ev.RoomID(), targetUserID)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, userID := range userIDs {
|
for _, toNotifyUserID := range userIDs {
|
||||||
n.wakeupUser(userID, pos)
|
n.wakeupUser(toNotifyUserID, pos)
|
||||||
}
|
}
|
||||||
} else if len(userID) > 0 {
|
} else if len(userID) > 0 {
|
||||||
n.wakeupUser(userID, pos)
|
n.wakeupUser(userID, pos)
|
||||||
|
Loading…
Reference in New Issue
Block a user