lib/rubocop/cop/layout/space_around_keyword.rb
Class SpaceAroundKeyword
has 43 methods (exceeds 20 allowed). Consider refactoring. Open
Open
class SpaceAroundKeyword < Base
extend AutoCorrector
MSG_BEFORE = 'Space before keyword `%<range>s` is missing.'
MSG_AFTER = 'Space after keyword `%<range>s` is missing.'
Method check
has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring. Open
Open
def check(node, locations, begin_keyword = DO)
locations.each do |loc|
next unless node.loc.respond_to?(loc)
range = node.loc.public_send(loc)
- 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
Method preceded_by_operator?
has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring. Open
Open
def preceded_by_operator?(node, _range)
# regular dotted method calls bind more tightly than operators
# so we need to climb up the AST past them
node.each_ancestor do |ancestor|
return true if ancestor.and_type? || ancestor.or_type? || ancestor.range_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"