Method has too many lines. [57/10] (https://github.com/voxable-labs/voxable-style-guide#short-methods) Open
def perform(user_id, redis_namespace, bot_class_name)
# Retrieve the latest message for this user.
raw_message = pop_raw_message(user_id, redis_namespace)
# Do nothing if no message available. This could be due to multiple
- Read upRead up
- Create a ticketCreate a ticket
- Exclude checks
This cop checks if the length of a method exceeds some maximum value. Comment lines can optionally be ignored. The maximum allowed length is configurable.
Assignment Branch Condition size for perform is too high. [57.39/15] (http://c2.com/cgi/wiki?AbcMetric) Open
def perform(user_id, redis_namespace, bot_class_name)
# Retrieve the latest message for this user.
raw_message = pop_raw_message(user_id, redis_namespace)
# Do nothing if no message available. This could be due to multiple
- Read upRead up
- Create a ticketCreate a ticket
- Exclude checks
This cop checks that the ABC size of methods is not higher than the configured maximum. The ABC size is based on assignments, branches (method calls), and conditions. See http://c2.com/cgi/wiki?AbcMetric
Method perform
has a Cognitive Complexity of 34 (exceeds 5 allowed). Consider refactoring. Open
def perform(user_id, redis_namespace, bot_class_name)
# Retrieve the latest message for this user.
raw_message = pop_raw_message(user_id, redis_namespace)
# Do nothing if no message available. This could be due to multiple
- Read upRead up
- Create a ticketCreate a ticket
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
Perceived complexity for perform is too high. [18/7] Open
def perform(user_id, redis_namespace, bot_class_name)
# Retrieve the latest message for this user.
raw_message = pop_raw_message(user_id, redis_namespace)
# Do nothing if no message available. This could be due to multiple
- Read upRead up
- Create a ticketCreate a ticket
- Exclude checks
This cop tries to produce a complexity score that's a measure of the
complexity the reader experiences when looking at a method. For that
reason it considers when
nodes as something that doesn't add as much
complexity as an if
or a &&
. Except if it's one of those special
case
/when
constructs where there's no expression after case
. Then
the cop treats it as an if
/elsif
/elsif
... and lets all the when
nodes count. In contrast to the CyclomaticComplexity cop, this cop
considers else
nodes as adding complexity.
Example:
def my_method # 1
if cond # 1
case var # 2 (0.8 + 4 * 0.2, rounded)
when 1 then func_one
when 2 then func_two
when 3 then func_three
when 4..10 then func_other
end
else # 1
do_something until a && b # 2
end # ===
end # 7 complexity points
Cyclomatic complexity for perform is too high. [15/6] Open
def perform(user_id, redis_namespace, bot_class_name)
# Retrieve the latest message for this user.
raw_message = pop_raw_message(user_id, redis_namespace)
# Do nothing if no message available. This could be due to multiple
- Read upRead up
- Create a ticketCreate a ticket
- Exclude checks
This cop checks that the cyclomatic complexity of methods is not higher than the configured maximum. The cyclomatic complexity is the number of linearly independent paths through a method. The algorithm counts decision points and adds one.
An if statement (or unless or ?:) increases the complexity by one. An else branch does not, since it doesn't add a decision point. The && operator (or keyword and) can be converted to a nested if statement, and ||/or is shorthand for a sequence of ifs, so they also add one. Loops can be said to have an exit condition, so they add one.
Method perform
has 57 lines of code (exceeds 25 allowed). Consider refactoring. Open
def perform(user_id, redis_namespace, bot_class_name)
# Retrieve the latest message for this user.
raw_message = pop_raw_message(user_id, redis_namespace)
# Do nothing if no message available. This could be due to multiple
- Create a ticketCreate a ticket
Method has too many lines. [12/10] (https://github.com/voxable-labs/voxable-style-guide#short-methods) Open
def build_dialog_request(user, message)
# Fetch the information from the user's context.
action = user.context[:dialog_action]
parameters = user.context[:dialog_parameters]
- Read upRead up
- Create a ticketCreate a ticket
- Exclude checks
This cop checks if the length of a method exceeds some maximum value. Comment lines can optionally be ignored. The maximum allowed length is configurable.
Avoid deeply nested control flow statements. Open
@client.set_chatbase_fields(
request.intent,
message.text,
false
) if ENV['CHATBASE_API_KEY']
- Create a ticketCreate a ticket
Avoid deeply nested control flow statements. Open
if ENV['CHATBASE_API_KEY']
@client.set_chatbase_fields(
request.action,
message.text,
false)
- Create a ticketCreate a ticket
Avoid deeply nested control flow statements. Open
if ENV['CHATBASE_API_KEY']
if !nlu_response[:intent] || request.intent == 'Default'
@client.not_handled = true
else
@client.set_chatbase_fields(request.intent, message.text, false)
- Create a ticketCreate a ticket
Avoid more than 3 levels of block nesting. (https://github.com/voxable-labs/voxable-style-guide#three-is-the-number-thou-shalt-count) Open
if !nlu_response[:intent] || request.intent == 'Default'
@client.not_handled = true
else
@client.set_chatbase_fields(request.intent, message.text, false)
end
- Read upRead up
- Create a ticketCreate a ticket
- Exclude checks
This cop checks for excessive nesting of conditional and looping constructs.
You can configure if blocks are considered using the CountBlocks
option. When set to false
(the default) blocks are not counted
towards the nesting level. Set to true
to count blocks as well.
The maximum level of nesting allowed is configurable.
Avoid more than 3 levels of block nesting. (https://github.com/voxable-labs/voxable-style-guide#three-is-the-number-thou-shalt-count) Open
@client.set_chatbase_fields(
request.intent,
message.text,
false
) if ENV['CHATBASE_API_KEY']
- Read upRead up
- Create a ticketCreate a ticket
- Exclude checks
This cop checks for excessive nesting of conditional and looping constructs.
You can configure if blocks are considered using the CountBlocks
option. When set to false
(the default) blocks are not counted
towards the nesting level. Set to true
to count blocks as well.
The maximum level of nesting allowed is configurable.
TODO found Open
# TODO: pass in a `user_id_field` to indicate how to find user in order to
- Create a ticketCreate a ticket
- Exclude checks
TODO found Open
# TODO: Make number of retries configurable.
- Create a ticketCreate a ticket
- Exclude checks
TODO found Open
# TODO: What should we do if attachments aren't recognized?
- Create a ticketCreate a ticket
- Exclude checks
Use ==
if you meant to do a comparison or wrap the expression in parentheses to indicate you meant to assign in a condition. (https://github.com/voxable-labs/voxable-style-guide#safe-assignment-in-condition) Open
if quick_reply_payload = message.quick_reply
- Read upRead up
- Create a ticketCreate a ticket
- Exclude checks
This cop checks for assignments in the conditions of if/while/until.
Example:
# bad
if some_var = true
do_something
end
Example:
# good
if some_var == true
do_something
end
Redundant else
-clause. Open
else
- Read upRead up
- Create a ticketCreate a ticket
- Exclude checks
Checks for empty else-clauses, possibly including comments and/or an
explicit nil
depending on the EnforcedStyle.
Example: EnforcedStyle: empty
# warn only on empty else
# bad
if condition
statement
else
end
# good
if condition
statement
else
nil
end
# good
if condition
statement
else
statement
end
# good
if condition
statement
end
Example: EnforcedStyle: nil
# warn on else with nil in it
# bad
if condition
statement
else
nil
end
# good
if condition
statement
else
end
# good
if condition
statement
else
statement
end
# good
if condition
statement
end
Example: EnforcedStyle: both (default)
# warn on empty else and else with nil in it
# bad
if condition
statement
else
nil
end
# bad
if condition
statement
else
end
# good
if condition
statement
else
statement
end
# good
if condition
statement
end
Line is too long. [82/80] (https://github.com/voxable-labs/voxable-style-guide#80-character-limits) Open
# TODO: pass in a `user_id_field` to indicate how to find user in order to
- Create a ticketCreate a ticket
- Exclude checks
Trailing whitespace detected. (https://github.com/voxable-labs/voxable-style-guide#no-trailing-whitespace) Open
- Create a ticketCreate a ticket
- Exclude checks
Trailing whitespace detected. (https://github.com/voxable-labs/voxable-style-guide#no-trailing-whitespace) Open
- Create a ticketCreate a ticket
- Exclude checks
Trailing whitespace detected. (https://github.com/voxable-labs/voxable-style-guide#no-trailing-whitespace) Open
- Create a ticketCreate a ticket
- Exclude checks
Closing method call brace must be on the line after the last argument when opening brace is on a separate line from the first argument. Open
false)
- Read upRead up
- Create a ticketCreate a ticket
- Exclude checks
This cop checks that the closing brace in a method call is either on the same line as the last method argument, or a new line.
When using the symmetrical
(default) style:
If a method call's opening brace is on the same line as the first argument of the call, then the closing brace should be on the same line as the last argument of the call.
If an method call's opening brace is on the line above the first argument of the call, then the closing brace should be on the line below the last argument of the call.
When using the new_line
style:
The closing brace of a multi-line method call must be on the line after the last argument of the call.
When using the same_line
style:
The closing brace of a multi-line method call must be on the same line as the last argument of the call.
Example:
# symmetrical: bad
# new_line: good
# same_line: bad
foo(a,
b
)
# symmetrical: bad
# new_line: bad
# same_line: good
foo(
a,
b)
# symmetrical: good
# new_line: bad
# same_line: good
foo(a,
b)
# symmetrical: good
# new_line: good
# same_line: bad
foo(
a,
b
)
if
condition requires an else
-clause. Open
if ENV['CHATBASE_API_KEY']
if !nlu_response[:intent] || request.intent == 'Default'
@client.not_handled = true
else
@client.set_chatbase_fields(request.intent, message.text, false)
- Read upRead up
- Create a ticketCreate a ticket
- Exclude checks
Checks for if
expressions that do not have an else
branch.
SupportedStyles
if
Example:
# bad
if condition
statement
end
case
Example:
# bad
case var
when condition
statement
end
Example:
# good
if condition
statement
else
# the content of the else branch will be determined by Style/EmptyElse
end
Favor a normal if-statement over a modifier clause in a multiline statement. (https://github.com/voxable-labs/voxable-style-guide#no-multiline-if-modifiers) Open
@client.set_chatbase_fields(
request.action,
message.text,
false
) if ENV['CHATBASE_API_KEY']
- Read upRead up
- Create a ticketCreate a ticket
- Exclude checks
Checks for uses of if/unless modifiers with multiple-lines bodies.
Example:
# bad
{
result: 'this should not happen'
} unless cond
# good
{ result: 'ok' } if cond
if
condition requires an else
-clause. Open
if ENV['CHATBASE_API_KEY']
@client.set_chatbase_fields(
request.action,
message.text,
false)
- Read upRead up
- Create a ticketCreate a ticket
- Exclude checks
Checks for if
expressions that do not have an else
branch.
SupportedStyles
if
Example:
# bad
if condition
statement
end
case
Example:
# bad
case var
when condition
statement
end
Example:
# good
if condition
statement
else
# the content of the else branch will be determined by Style/EmptyElse
end
Favor a normal if-statement over a modifier clause in a multiline statement. (https://github.com/voxable-labs/voxable-style-guide#no-multiline-if-modifiers) Open
@client.set_chatbase_fields(
request.intent,
message.text,
false
) if ENV['CHATBASE_API_KEY']
- Read upRead up
- Create a ticketCreate a ticket
- Exclude checks
Checks for uses of if/unless modifiers with multiple-lines bodies.
Example:
# bad
{
result: 'this should not happen'
} unless cond
# good
{ result: 'ok' } if cond