Lichess4545/Chesster

View on GitHub
src/slack.ts

Summary

Maintainability
F
5 days
Test Coverage
F
13%

File slack.ts has 945 lines of code (exceeds 250 allowed). Consider refactoring.
Open

// -----------------------------------------------------------------------------
// Bot / Slack related helpers
// -----------------------------------------------------------------------------
import { RTMClient } from '@slack/rtm-api'
import {
Severity: Major
Found in src/slack.ts - About 2 days to fix

    Function startOnListener has 69 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

        async startOnListener() {
            this.rtm.on('message', async (event: SlackMessage) => {
                try {
                    const channel = await this.getChannel(event.channel)
                    if (!channel) {
    Severity: Major
    Found in src/slack.ts - About 2 hrs to fix

      Function handleMatch has 59 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

          async handleMatch(
              listener: SlackRTMEventListenerOptions,
              message: CommandMessage
          ) {
              let allowedTypes = ['command', 'league_command']
      Severity: Major
      Found in src/slack.ts - About 2 hrs to fix

        Function start has 53 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

            async start() {
                // Connect to Slack
                const { self, team } = await this.rtm.start()
                this.controller = self as SlackBotSelf
                this.team = team as SlackTeam
        Severity: Major
        Found in src/slack.ts - About 2 hrs to fix

          Function getLeague has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring.
          Open

          function getLeague(
              bot: SlackBot,
              message: ChessterMessage,
              channelOnly: boolean
          ): league.League | undefined {
          Severity: Minor
          Found in src/slack.ts - About 1 hr to fix

          Cognitive Complexity

          Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

          A method's cognitive complexity is based on a few simple rules:

          • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
          • Code is considered more complex for each "break in the linear flow of the code"
          • Code is considered more complex when "flow breaking structures are nested"

          Further reading

          Function updatesUsers has 40 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

              async updatesUsers() {
                  // Get our lichess username to slack username map
                  const slackIDByLichessUsername = await heltour.getUserMap(
                      this.config.heltour
                  )
          Severity: Minor
          Found in src/slack.ts - About 1 hr to fix

            Function handleMatch has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
            Open

                async handleMatch(
                    listener: SlackRTMEventListenerOptions,
                    message: CommandMessage
                ) {
                    let allowedTypes = ['command', 'league_command']
            Severity: Minor
            Found in src/slack.ts - About 1 hr to fix

            Cognitive Complexity

            Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

            A method's cognitive complexity is based on a few simple rules:

            • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
            • Code is considered more complex for each "break in the linear flow of the code"
            • Code is considered more complex when "flow breaking structures are nested"

            Further reading

            Function getLeague has 31 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

            function getLeague(
                bot: SlackBot,
                message: ChessterMessage,
                channelOnly: boolean
            ): league.League | undefined {
            Severity: Minor
            Found in src/slack.ts - About 1 hr to fix

              Function findLeagueByMessageText has 31 lines of code (exceeds 25 allowed). Consider refactoring.
              Open

              function findLeagueByMessageText(bot: SlackBot, message: ChessterMessage) {
                  const allLeagues = league.getAllLeagues(bot)
                  const leagueTargets: string[] = []
                  const targetToLeague: Record<string, league.League> = {}
                  function add_target(l: league.League, target: string) {
              Severity: Minor
              Found in src/slack.ts - About 1 hr to fix

                Similar blocks of code found in 2 locations. Consider refactoring.
                Open

                    _addByIdWithDuplicate(id: string, entity: SlackEntity) {
                        if (isDefined(this.byId[id])) {
                            this.idDuplicates[id].push(entity)
                        } else {
                            this.idDuplicates[id] = [entity]
                Severity: Major
                Found in src/slack.ts and 1 other location - About 2 hrs to fix
                src/slack.ts on lines 509..516

                Duplicated Code

                Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                Tuning

                This issue has a mass of 94.

                We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                Refactorings

                Further Reading

                Similar blocks of code found in 2 locations. Consider refactoring.
                Open

                    _addByNameWithDuplicate(key: string, entity: SlackEntity) {
                        if (isDefined(this.byName[key])) {
                            this.nameDuplicates[key].push(entity)
                        } else {
                            this.nameDuplicates[key] = [entity]
                Severity: Major
                Found in src/slack.ts and 1 other location - About 2 hrs to fix
                src/slack.ts on lines 500..507

                Duplicated Code

                Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                Tuning

                This issue has a mass of 94.

                We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                Refactorings

                Further Reading

                Similar blocks of code found in 2 locations. Consider refactoring.
                Open

                export interface LeagueCommandEventOptions {
                    type: 'league_command'
                    patterns: RegExp[]
                    messageTypes: HearsEventType[]
                    middleware?: MiddlewareFn[]
                Severity: Major
                Found in src/slack.ts and 1 other location - About 1 hr to fix
                src/slack.ts on lines 241..247

                Duplicated Code

                Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                Tuning

                This issue has a mass of 60.

                We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                Refactorings

                Further Reading

                Similar blocks of code found in 2 locations. Consider refactoring.
                Open

                export interface CommandEventOptions {
                    type: 'command'
                    patterns: RegExp[]
                    messageTypes: HearsEventType[]
                    middleware?: MiddlewareFn[]
                Severity: Major
                Found in src/slack.ts and 1 other location - About 1 hr to fix
                src/slack.ts on lines 248..254

                Duplicated Code

                Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                Tuning

                This issue has a mass of 60.

                We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                Refactorings

                Further Reading

                Similar blocks of code found in 3 locations. Consider refactoring.
                Open

                        this.rtm.on('disconnected', (error) => {
                            this.log.error(`Disconnecting: ${JSON.stringify(error)}`)
                        })
                Severity: Major
                Found in src/slack.ts and 2 other locations - About 55 mins to fix
                src/slack.ts on lines 649..651
                src/slack.ts on lines 667..669

                Duplicated Code

                Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                Tuning

                This issue has a mass of 54.

                We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                Refactorings

                Further Reading

                Similar blocks of code found in 3 locations. Consider refactoring.
                Open

                        this.rtm.on('authenticated', (connectData) => {
                            this.log.info(`Authenticating: ${JSON.stringify(connectData)}`)
                        })
                Severity: Major
                Found in src/slack.ts and 2 other locations - About 55 mins to fix
                src/slack.ts on lines 664..666
                src/slack.ts on lines 667..669

                Duplicated Code

                Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                Tuning

                This issue has a mass of 54.

                We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                Refactorings

                Further Reading

                Similar blocks of code found in 3 locations. Consider refactoring.
                Open

                        this.rtm.on('error', (error) => {
                            this.log.error(`Error: ${JSON.stringify(error)}`)
                        })
                Severity: Major
                Found in src/slack.ts and 2 other locations - About 55 mins to fix
                src/slack.ts on lines 649..651
                src/slack.ts on lines 664..666

                Duplicated Code

                Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                Tuning

                This issue has a mass of 54.

                We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                Refactorings

                Further Reading

                Similar blocks of code found in 2 locations. Consider refactoring.
                Open

                export interface SlackUserListResponse extends WebAPICallResult {
                    ok: boolean
                    members: SlackUser[]
                    cache_ts: number
                    response_metadata: SlackResponseMetadata
                Severity: Minor
                Found in src/slack.ts and 1 other location - About 35 mins to fix
                src/slack.ts on lines 108..113

                Duplicated Code

                Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                Tuning

                This issue has a mass of 47.

                We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                Refactorings

                Further Reading

                Similar blocks of code found in 2 locations. Consider refactoring.
                Open

                export interface SlackChannelListResponse extends WebAPICallResult {
                    ok: boolean
                    channels: SlackChannel[]
                    cache_ts: number
                    response_metadata: SlackResponseMetadata
                Severity: Minor
                Found in src/slack.ts and 1 other location - About 35 mins to fix
                src/slack.ts on lines 67..72

                Duplicated Code

                Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                Tuning

                This issue has a mass of 47.

                We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                Refactorings

                Further Reading

                There are no issues that match your filters.

                Category
                Status