Showing 10 of 18 total issues
Function SlackCommandFunc
has 127 lines of code (exceeds 50 allowed). Consider refactoring. Open
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)
Function buildScheduledTask
has 59 lines of code (exceeds 50 allowed). Consider refactoring. Open
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
Function buildScheduledTask
has 7 return statements (exceeds 4 allowed). Open
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
Method Client.Get
has 6 return statements (exceeds 4 allowed). Open
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)
Method command.inputTime
has 6 return statements (exceeds 4 allowed). Open
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)
Function guessFunc
has 5 return statements (exceeds 4 allowed). Open
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)
}
Method command.inputDate
has 5 return statements (exceeds 4 allowed). Open
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)
Method RestAPIClient.Post
has 5 return statements (exceeds 4 allowed). Open
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)
}
Function buildCommand
has 5 return statements (exceeds 4 allowed). Open
Open
func buildCommand(ctx context.Context, props *CommandProps, watcher ConfigWatcher) (Command, error) {
if props.config == nil {
return &defaultCommand{
identifier: props.identifier,
matchFunc: props.matchFunc,
Method runner.superviseBot
has a Cognitive Complexity of 21 (exceeds 20 allowed). Consider refactoring. Open
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)
- Read upRead up
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"