oklahomer/go-sarah

View on GitHub

Showing 18 of 18 total issues

Function SlackCommandFunc has 127 lines of code (exceeds 50 allowed). Consider refactoring.
Open

func SlackCommandFunc(ctx context.Context, input sarah.Input, config sarah.CommandConfig) (*sarah.CommandResponse, error) {
    strippedMessage := sarah.StripMessage(MatchPattern, input.Message())

    // Share the client instance with later executions
    conf, _ := config.(*CommandConfig)
Severity: Major
Found in _examples/simple/plugins/worldweather/weather.go - About 4 hrs to fix

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

        err := func() error {
            locker.Lock()
            defer locker.Unlock()
    
            rv := reflect.ValueOf(cfg)
    Severity: Major
    Found in task.go and 1 other location - About 2 hrs to fix
    command.go on lines 104..128

    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 209.

    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

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

        err := func() error {
            locker.Lock()
            defer locker.Unlock()
    
            rv := reflect.ValueOf(cfg)
    Severity: Major
    Found in command.go and 1 other location - About 2 hrs to fix
    task.go on lines 143..166

    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 209.

    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

    Function buildScheduledTask has 59 lines of code (exceeds 50 allowed). Consider refactoring.
    Open

    func buildScheduledTask(ctx context.Context, props *ScheduledTaskProps, watcher ConfigWatcher) (ScheduledTask, error) {
        if props.config == nil {
            // If a config struct is not set, props MUST provide a default schedule to execute the task.
            if props.schedule == "" {
                return nil, ErrTaskScheduleNotGiven
    Severity: Minor
    Found in task.go - About 1 hr to fix

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

      var SlackProps = sarah.NewScheduledTaskPropsBuilder().
          BotType(slack.SLACK).
          Identifier("timer").
          ConfigurableFunc(&timerConfig{}, func(_ context.Context, config sarah.TaskConfig) ([]*sarah.ScheduledTaskResult, error) {
              return []*sarah.ScheduledTaskResult{
      Severity: Minor
      Found in _examples/simple/plugins/timer/props.go and 1 other location - About 55 mins to fix
      _examples/simple/plugins/fixedtimer/props.go on lines 28..39

      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 127.

      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

      var SlackProps = sarah.NewScheduledTaskPropsBuilder().
          BotType(slack.SLACK).
          Identifier("fixed_timer").
          ConfigurableFunc(&timerConfig{}, func(_ context.Context, config sarah.TaskConfig) ([]*sarah.ScheduledTaskResult, error) {
              return []*sarah.ScheduledTaskResult{
      Severity: Minor
      Found in _examples/simple/plugins/fixedtimer/props.go and 1 other location - About 55 mins to fix
      _examples/simple/plugins/timer/props.go on lines 32..43

      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 127.

      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

      Function buildScheduledTask has 7 return statements (exceeds 4 allowed).
      Open

      func buildScheduledTask(ctx context.Context, props *ScheduledTaskProps, watcher ConfigWatcher) (ScheduledTask, error) {
          if props.config == nil {
              // If a config struct is not set, props MUST provide a default schedule to execute the task.
              if props.schedule == "" {
                  return nil, ErrTaskScheduleNotGiven
      Severity: Major
      Found in task.go - About 45 mins to fix

        Method command.inputTime has 6 return statements (exceeds 4 allowed).
        Open

        func (cmd *command) inputTime(_ context.Context, input sarah.Input, validDate string, args *args) (*sarah.CommandResponse, error) {
            t := strings.TrimSpace(input.Message())
        
            reinput := func(c context.Context, i sarah.Input) (*sarah.CommandResponse, error) {
                return cmd.inputTime(c, i, validDate, args)
        Severity: Major
        Found in _examples/simple/plugins/todo/command.go - About 40 mins to fix

          Method Client.Get has 6 return statements (exceeds 4 allowed).
          Open

          func (client *Client) Get(ctx context.Context, apiType string, queryParams *url.Values, data interface{}) error {
              endpoint := client.buildEndpoint(apiType, queryParams)
              req, err := http.NewRequest(http.MethodGet, endpoint.String(), nil)
              if err != nil {
                  return fmt.Errorf("failed to build request: %w", err)
          Severity: Major
          Found in _examples/simple/plugins/worldweather/client.go - About 40 mins to fix

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

                    if config.HelpCommand != "" && trimmed == config.HelpCommand {
                        // Help command
                        help := sarah.NewHelpInput(input)
                        _ = enqueueInput(help)
                    } else if config.AbortCommand != "" && trimmed == config.AbortCommand {
            Severity: Minor
            Found in slack/rtmapi.go and 1 other location - About 40 mins to fix
            slack/eventsapi.go on lines 60..71

            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 109.

            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

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

                if config.HelpCommand != "" && trimmed == config.HelpCommand {
                    // Help command
                    help := sarah.NewHelpInput(input)
                    _ = enqueueInput(help)
                } else if config.AbortCommand != "" && trimmed == config.AbortCommand {
            Severity: Minor
            Found in slack/eventsapi.go and 1 other location - About 40 mins to fix
            slack/rtmapi.go on lines 173..184

            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 109.

            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

            func RegisterScheduledTaskProps(props *ScheduledTaskProps) {
                options.register(func(r *runner) {
                    stashed, ok := r.scheduledTaskProps[props.botType]
                    if !ok {
                        stashed = []*ScheduledTaskProps{}
            Severity: Minor
            Found in runner.go and 1 other location - About 40 mins to fix
            runner.go on lines 87..95

            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 108.

            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

            func RegisterCommandProps(props *CommandProps) {
                options.register(func(r *runner) {
                    stashed, ok := r.commandProps[props.botType]
                    if !ok {
                        stashed = []*CommandProps{}
            Severity: Minor
            Found in runner.go and 1 other location - About 40 mins to fix
            runner.go on lines 111..119

            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 108.

            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

            Method RestAPIClient.Post has 5 return statements (exceeds 4 allowed).
            Open

            func (client *RestAPIClient) Post(ctx context.Context, resourceFragments []string, sendingPayload interface{}, responsePayload interface{}) error {
                reqBody, err := json.Marshal(sendingPayload)
                if err != nil {
                    return fmt.Errorf("can not marshal given payload: %w", err)
                }
            Severity: Major
            Found in gitter/rest.go - About 35 mins to fix

              Function guessFunc has 5 return statements (exceeds 4 allowed).
              Open

              func guessFunc(_ context.Context, input sarah.Input, answer int) (*sarah.CommandResponse, error) {
                  // For handiness, create a function that recursively calls guessFunc until the user inputs the right answer.
                  retry := func(c context.Context, i sarah.Input) (*sarah.CommandResponse, error) {
                      return guessFunc(c, i, answer)
                  }
              Severity: Major
              Found in _examples/simple/plugins/guess/props.go - About 35 mins to fix

                Method command.inputDate has 5 return statements (exceeds 4 allowed).
                Open

                func (cmd *command) inputDate(_ context.Context, input sarah.Input, args *args) (*sarah.CommandResponse, error) {
                    date := strings.TrimSpace(input.Message())
                
                    reinput := func(c context.Context, i sarah.Input) (*sarah.CommandResponse, error) {
                        return cmd.inputDate(c, i, args)
                Severity: Major
                Found in _examples/simple/plugins/todo/command.go - About 35 mins to fix

                  Function buildCommand has 5 return statements (exceeds 4 allowed).
                  Open

                  func buildCommand(ctx context.Context, props *CommandProps, watcher ConfigWatcher) (Command, error) {
                      if props.config == nil {
                          return &defaultCommand{
                              identifier:      props.identifier,
                              matchFunc:       props.matchFunc,
                  Severity: Major
                  Found in command.go - About 35 mins to fix

                    Method runner.superviseBot has a Cognitive Complexity of 21 (exceeds 20 allowed). Consider refactoring.
                    Open

                    func (r *runner) superviseBot(runnerCtx context.Context, botType BotType) (context.Context, func(error)) {
                        botCtx, cancel := context.WithCancel(runnerCtx)
                    
                        sendAlert := func(err error) {
                            e := r.alerters.alertAll(runnerCtx, botType, err)
                    Severity: Minor
                    Found in runner.go - About 25 mins 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

                    Severity
                    Category
                    Status
                    Source
                    Language