42wim / matterircd

Connect to your mattermost or slack using your IRC-client of choice.
MIT License
294 stars 60 forks source link

Fix golangci-lint dupl, unused, nestif, and gocritic #382

Closed hloeung closed 3 years ago

hloeung commented 3 years ago

That's the following:

$ golangci-lint run
WARN [runner] Can't process result by diff processor: can't prepare diff by revgrep: no version control repository found
mm-go-irckit/server_commands.go:584: 584-606 lines are duplicate of `mm-go-irckit/server_commands.go:608-630` (dupl)
func threadMsgChannel(u *User, msg *irc.Message, channelID string) bool {
        threadID, text := parseThreadID(u, msg, channelID)
        if threadID == "" {
                return false
        }

        msgID, err := u.br.MsgChannelThread(channelID, threadID, text)
        if err != nil {
                u.MsgSpoofUser(u, u.br.Protocol(), "msg: "+text+" could not be send: "+err.Error())
                return false
        }

        u.msgLastMutex.Lock()
        defer u.msgLastMutex.Unlock()
        u.msgLast[channelID] = [2]string{msgID, threadID}
        u.saveLastViewedAt(channelID)

        if u.v.GetBool(u.br.Protocol()+".prefixcontext") || u.v.GetBool(u.br.Protocol()+".suffixcontext") {
                u.prefixContext(channelID, msgID, "", "")
        }

        return true
}
mm-go-irckit/server_commands.go:608: 608-630 lines are duplicate of `mm-go-irckit/server_commands.go:584-606` (dupl)
func threadMsgUser(u *User, msg *irc.Message, toUser string) bool {
        threadID, text := parseThreadID(u, msg, toUser)
        if threadID == "" {
                return false
        }

        msgID, err := u.br.MsgUserThread(toUser, threadID, text)
        if err != nil {
                u.MsgSpoofUser(u, u.br.Protocol(), "msg: "+text+" could not be send: "+err.Error())
                return false
        }

        u.msgLastMutex.Lock()
        defer u.msgLastMutex.Unlock()
        u.msgLast[toUser] = [2]string{msgID, threadID}
        u.saveLastViewedAt(toUser)

        if u.v.GetBool(u.br.Protocol()+".prefixcontext") || u.v.GetBool(u.br.Protocol()+".suffixcontext") {
                u.prefixContext(toUser, msgID, "", "")
        }

        return true
}
pkg/matterclient/matterclient.go:365:3: ifElseChain: rewrite if-else to switch statement (gocritic)
                if m.Credentials.Token != "" {
                ^
mm-go-irckit/commands.go:9:1: comment on exported var `ErrUnknownCommand` should be of the form `ErrUnknownCommand ...` (golint)
// The error returned when an invalid command is issued.
^
mm-go-irckit/server_commands.go:179:21: `LISTEND` is a misspelling of `LISTENED` (misspell)
                Command:  irc.RPL_LISTEND,
                                  ^
mm-go-irckit/userbridge.go:265:2: `if u.v.GetBool(u.br.Protocol() + ".prefixcontext")` is deeply nested (complexity: 5) (nestif)
        if u.v.GetBool(u.br.Protocol() + ".prefixcontext") {
        ^
mm-go-irckit/server.go:137:2: `count` is unused (structcheck)
        count    int
        ^
mm-go-irckit/userbridge.go:209:45: `(*User).getMessageChannel` - `channelType` is unused (unparam)
func (u *User) getMessageChannel(channelID, channelType string, sender *bridge.UserInfo) Channel {
                                            ^
bridge/mattermost/mattermost.go:169:22: func `(*Mattermost).antiIdle` is unused (unused)
bridge/slack/slack.go:633:17: func `(*Slack).getBotname` is unused (unused)
bridge/mattermost/mattermost.go:723:2: directive `// nolint:nestif` is unused for linter nestif (nolintlint)
        // nolint:nestif
        ^
mm-go-irckit/userbridge.go:801:1: directive `// nolint:unparam,unused` is unused for linter unused (nolintlint)
// nolint:unparam,unused
^

Ignoring the funlen, goconst, gocognit, gocyclo, and a bunch of other nestif ones for now.

hloeung commented 3 years ago

FWIW, these are the ones skipped over:

pkg/matterclient/matterclient.go:111: Function 'Login' is too long (68 > 60) (funlen)
func (m *Client) Login() error {
pkg/matterclient/matterclient.go:365:3: ifElseChain: rewrite if-else to switch statement (gocritic)
            if m.Credentials.Token != "" {
            ^
bridge/slack/slack.go:504: Function 'handleSlack' has too many statements (44 > 40) (funlen)
func (s *Slack) handleSlack() {
main.go:27: Function 'main' has too many statements (54 > 40) (funlen)
func main() {
mm-go-irckit/channel.go:332: Function 'Join' is too long (62 > 60) (funlen)
func (ch *channel) Join(u *User) error {
mm-go-irckit/server.go:402: Function 'handshake' is too long (74 > 60) (funlen)
func (s *server) handshake(u *User) error {
mm-go-irckit/server_commands.go:336: Function 'CmdPrivMsg' has too many statements (62 > 40) (funlen)
func CmdPrivMsg(s Server, u *User, msg *irc.Message) error {
mm-go-irckit/server_commands.go:445: Function 'parseModifyMsg' has too many statements (44 > 40) (funlen)
func parseModifyMsg(u *User, msg *irc.Message, channelID string) bool {
mm-go-irckit/service.go:36: Function 'login' has too many statements (93 > 40) (funlen)
func login(u *User, toUser *User, args []string, service string) {
mm-go-irckit/service.go:400: Function 'parseCommandString' is too long (61 > 60) (funlen)
func parseCommandString(line string) ([]string, error) {
mm-go-irckit/userbridge.go:548: Function 'addUserToChannelWorker' has too many statements (59 > 40) (funlen)
func (u *User) addUserToChannelWorker(channels <-chan *bridge.ChannelInfo, throttle *time.Ticker) {
mm-go-irckit/server.go:460:15: string `slack` has 10 occurrences, make it a constant (goconst)
                            service = "slack"
                                      ^
mm-go-irckit/server_commands.go:710:30: string `online` has 3 occurrences, make it a constant (goconst)
            if statuses[other.User] != "online" {
                                       ^
mm-go-irckit/channel.go:359:16: string `&users` has 3 occurrences, make it a constant (goconst)
    if ch.name == "&users" && u.Ghost {
                  ^
mm-go-irckit/user.go:133:21: string `PRIVMSG` has 3 occurrences, make it a constant (goconst)
            if msg.Command == "PRIVMSG" && (msg.Prefix.Name == "slack" || msg.Prefix.Name == "mattermost") && msg.Prefix.Host == "service" && strings.Contains(msg.Trailing, "token") {
                              ^
mm-go-irckit/server.go:458:15: string `mattermost` has 7 occurrences, make it a constant (goconst)
                    service := "mattermost"
                               ^
mm-go-irckit/service.go:42:2: `if service == "slack"` is deeply nested (complexity: 10) (nestif)
    if service == "slack" {
    ^
mm-go-irckit/server_commands.go:371:2: `if exists` is deeply nested (complexity: 5) (nestif)
    if ch, exists := s.HasChannel(query); exists {
    ^
mm-go-irckit/server_commands.go:403:2: `if exists` is deeply nested (complexity: 5) (nestif)
    if toUser, exists := s.HasUser(query); exists {
    ^
42wim commented 3 years ago

For OCD reasons, could you rename your commits to Fix golangci-lint dupl etc ? :) (So I don't need to squash)

hloeung commented 3 years ago

For OCD reasons, could you rename your commits to Fix golangci-lint dupl etc ? :) (So I don't need to squash)

Done, I think that's what you mean.

42wim commented 3 years ago

Thanks!