oklahomer/go-sarah

View on GitHub

Showing 13 of 23 total issues

Method fileWatcher.run has a Cognitive Complexity of 65 (exceeds 20 allowed). Consider refactoring.
Open

func (w *fileWatcher) run(ctx context.Context, events <-chan fsnotify.Event, errs <-chan error) {
    subscriptions := map[string][]*subscription{}

OP:
    for {
Severity: Minor
Found in watchers/filewatcher.go - About 7 hrs 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 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 client instance with later execution
    conf, _ := config.(*CommandConfig)
Severity: Major
Found in _examples/simple/plugins/worldweather/weather.go - About 4 hrs to fix

    Method fileWatcher.run has 75 lines of code (exceeds 50 allowed). Consider refactoring.
    Open

    func (w *fileWatcher) run(ctx context.Context, events <-chan fsnotify.Event, errs <-chan error) {
        subscriptions := map[string][]*subscription{}
    
    OP:
        for {
    Severity: Minor
    Found in watchers/filewatcher.go - About 2 hrs to fix

      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 config struct is not set, props MUST provide settings to set schedule.
              if props.schedule == "" {
                  return nil, ErrTaskScheduleNotGiven
      Severity: Minor
      Found in task.go - About 1 hr to fix

        Avoid deeply nested control flow statements.
        Open

                        } else if err != nil {
                            logger.Warnf("Failed to locate %s: %+v", event.Name, err)
                            continue OP
                        }
        Severity: Major
        Found in watchers/filewatcher.go - About 45 mins to fix

          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 config struct is not set, props MUST provide settings to set schedule.
                  if props.schedule == "" {
                      return nil, ErrTaskScheduleNotGiven
          Severity: Major
          Found in task.go - About 45 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

              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

                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 user input 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 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 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 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

                        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