lib/rubocop/cop/style/redundant_parentheses.rb
Method find_offense_message
has a Cognitive Complexity of 25 (exceeds 5 allowed). Consider refactoring. Open
Open
def find_offense_message(begin_node, node)
return 'a keyword' if keyword_with_redundant_parentheses?(node)
return 'a literal' if disallowed_literal?(begin_node, node)
return 'a variable' if node.variable?
return 'a constant' if node.const_type?
- 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"
Further reading
Class RedundantParentheses
has 29 methods (exceeds 20 allowed). Consider refactoring. Open
Open
class RedundantParentheses < Base
include Parentheses
extend AutoCorrector
ALLOWED_NODE_TYPES = %i[and or send splat kwsplat].freeze
Avoid too many return
statements within this method. Open
Open
return 'an expression'
Avoid too many return
statements within this method. Open
Open
return if ALLOWED_NODE_TYPES.include?(begin_node.parent&.type)
Avoid too many return
statements within this method. Open
Open
return if node.semantic_operator? && begin_node.parent
Avoid too many return
statements within this method. Open
Open
return if node.multiline? && allow_in_multiline_conditions?
Avoid too many return
statements within this method. Open
Open
return unless begin_node.parent.nil?
Avoid too many return
statements within this method. Open
Open
return 'an interpolated expression' if interpolation?(begin_node)
Avoid too many return
statements within this method. Open
Open
return if begin_node.parent&.if_type? && begin_node.parent&.ternary?
Avoid too many return
statements within this method. Open
Open
return if begin_node.chained?
Method keyword_with_redundant_parentheses?
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
Open
def keyword_with_redundant_parentheses?(node)
return false unless node.keyword?
return true if node.special_keyword?
args = *node
- 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"