Method merge_sections
has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring. Open
def merge_sections(sections)
sections.each do |section|
position = nil
parent = if section.parent_id && @id_to_section.key?(section.parent_id)
- 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
Method section_for_item_id
has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring. Open
def section_for_item_id(item_id)
found = nil
@id_to_section.each do |_id, section|
next unless section.contains_item_id?(item_id)
- 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
Method item
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
def item(item_id)
@menu.each do |menu_section|
return menu_section if menu_section.kind_of?(Menu::Item) && menu_section.id == item_id
menu_section.items.each do |el|
- 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
Inherit from StandardError
instead of Exception
. Open
class InvalidMenuDefinition < Exception
- Read upRead up
- Create a ticketCreate a ticket
- Exclude checks
Looks for error classes inheriting from Exception
.
It is configurable to suggest using either StandardError
(default) or
RuntimeError
instead.
Safety:
This cop's autocorrection is unsafe because rescue
that omit
exception class handle StandardError
and its subclasses,
but not Exception
and its subclasses.
Example: EnforcedStyle: standard_error (default)
# bad
class C < Exception; end
C = Class.new(Exception)
# good
class C < StandardError; end
C = Class.new(StandardError)
Example: EnforcedStyle: runtime_error
# bad
class C < Exception; end
C = Class.new(Exception)
# good
class C < RuntimeError; end
C = Class.new(RuntimeError)