Method replace_right_cell
has a Cognitive Complexity of 153 (exceeds 5 allowed). Consider refactoring. Open
def replace_right_cell(options = {})
@explorer = true
action = options[:action]
replace_trees = options[:replace_trees] || []
get_node_info unless @in_a_form
- 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
File report_controller.rb
has 814 lines of code (exceeds 400 allowed). Consider refactoring. Open
require 'yaml'
class ReportController < ApplicationController
DEFAULT_SORT_COLUMN_NUMBER = 2
DEFAULT_SORT_ORDER = "DESC".freeze
- Create a ticketCreate a ticket
Cyclomatic complexity for replace_right_cell is too high. [86/11] Open
def replace_right_cell(options = {})
@explorer = true
action = options[:action]
replace_trees = options[:replace_trees] || []
get_node_info unless @in_a_form
- Read upRead up
- Create a ticketCreate a ticket
- Exclude checks
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. Blocks that are calls to builtin iteration methods (e.g. `ary.map{...}) also add one, others are ignored.
def each_child_node(*types) # count begins: 1
unless block_given? # unless: +1
return to_enum(__method__, *types)
children.each do |child| # each{}: +1
next unless child.is_a?(Node) # unless: +1
yield child if types.empty? || # if: +1, ||: +1
types.include?(child.type)
end
self
end # total: 6
Method replace_right_cell
has 213 lines of code (exceeds 25 allowed). Consider refactoring. Open
def replace_right_cell(options = {})
@explorer = true
action = options[:action]
replace_trees = options[:replace_trees] || []
get_node_info unless @in_a_form
- Create a ticketCreate a ticket
Class ReportController
has 40 methods (exceeds 20 allowed). Consider refactoring. Open
class ReportController < ApplicationController
DEFAULT_SORT_COLUMN_NUMBER = 2
DEFAULT_SORT_ORDER = "DESC".freeze
include Dashboards
- Create a ticketCreate a ticket
Method set_form_locals
has a Cognitive Complexity of 27 (exceeds 5 allowed). Consider refactoring. Open
def set_form_locals
locals = {}
if x_active_tree == :export_tree
locals[:no_reset] = locals[:no_cancel] = locals[:multi_record] = true
if x_node == "xx-exportwidgets"
- 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 reports_get_node_info
has a Cognitive Complexity of 25 (exceeds 5 allowed). Consider refactoring. Open
def reports_get_node_info
nodes = x_node.split('-')
if nodes.length == 2
@right_cell_text ||= _("%{typ} Reports") % {:typ => @sb[:rpt_menu][nodes[1].to_i][0]}
- 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
Cyclomatic complexity for reports_get_node_info is too high. [17/11] Open
def reports_get_node_info
nodes = x_node.split('-')
if nodes.length == 2
@right_cell_text ||= _("%{typ} Reports") % {:typ => @sb[:rpt_menu][nodes[1].to_i][0]}
- Read upRead up
- Create a ticketCreate a ticket
- Exclude checks
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. Blocks that are calls to builtin iteration methods (e.g. `ary.map{...}) also add one, others are ignored.
def each_child_node(*types) # count begins: 1
unless block_given? # unless: +1
return to_enum(__method__, *types)
children.each do |child| # each{}: +1
next unless child.is_a?(Node) # unless: +1
yield child if types.empty? || # if: +1, ||: +1
types.include?(child.type)
end
self
end # total: 6
Cyclomatic complexity for set_form_locals is too high. [15/11] Open
def set_form_locals
locals = {}
if x_active_tree == :export_tree
locals[:no_reset] = locals[:no_cancel] = locals[:multi_record] = true
if x_node == "xx-exportwidgets"
- Read upRead up
- Create a ticketCreate a ticket
- Exclude checks
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. Blocks that are calls to builtin iteration methods (e.g. `ary.map{...}) also add one, others are ignored.
def each_child_node(*types) # count begins: 1
unless block_given? # unless: +1
return to_enum(__method__, *types)
children.each do |child| # each{}: +1
next unless child.is_a?(Node) # unless: +1
yield child if types.empty? || # if: +1, ||: +1
types.include?(child.type)
end
self
end # total: 6
Method report_selection_menus
has a Cognitive Complexity of 16 (exceeds 5 allowed). Consider refactoring. Open
def report_selection_menus
@folders = []
@menu.each do |r|
@folders.push(r[0])
next if @edit[:new][:filter].blank?
- 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
Cyclomatic complexity for explorer is too high. [13/11] Open
def explorer
@explorer = true
@lastaction = "explorer"
@ght_type = nil
@report = nil
- Read upRead up
- Create a ticketCreate a ticket
- Exclude checks
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. Blocks that are calls to builtin iteration methods (e.g. `ary.map{...}) also add one, others are ignored.
def each_child_node(*types) # count begins: 1
unless block_given? # unless: +1
return to_enum(__method__, *types)
children.each do |child| # each{}: +1
next unless child.is_a?(Node) # unless: +1
yield child if types.empty? || # if: +1, ||: +1
types.include?(child.type)
end
self
end # total: 6
Cyclomatic complexity for get_node_info is too high. [12/11] Open
def get_node_info(_node = {}, _show_list = true)
treenodeid = valid_active_node(x_node)
if %i[db_tree reports_tree saved_tree savedreports_tree widgets_tree].include?(x_active_tree)
@nodetype = case x_active_tree
when :savedreports_tree
- Read upRead up
- Create a ticketCreate a ticket
- Exclude checks
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. Blocks that are calls to builtin iteration methods (e.g. `ary.map{...}) also add one, others are ignored.
def each_child_node(*types) # count begins: 1
unless block_given? # unless: +1
return to_enum(__method__, *types)
children.each do |child| # each{}: +1
next unless child.is_a?(Node) # unless: +1
yield child if types.empty? || # if: +1, ||: +1
types.include?(child.type)
end
self
end # total: 6
Method features
has 40 lines of code (exceeds 25 allowed). Consider refactoring. Open
def features
[
{
:role => "miq_report_saved_reports",
:role_any => true,
- Create a ticketCreate a ticket
Method explorer
has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring. Open
def explorer
@explorer = true
@lastaction = "explorer"
@ght_type = nil
@report = nil
- 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 set_form_locals
has 36 lines of code (exceeds 25 allowed). Consider refactoring. Open
def set_form_locals
locals = {}
if x_active_tree == :export_tree
locals[:no_reset] = locals[:no_cancel] = locals[:multi_record] = true
if x_node == "xx-exportwidgets"
- Create a ticketCreate a ticket
Method reports_get_node_info
has 33 lines of code (exceeds 25 allowed). Consider refactoring. Open
def reports_get_node_info
nodes = x_node.split('-')
if nodes.length == 2
@right_cell_text ||= _("%{typ} Reports") % {:typ => @sb[:rpt_menu][nodes[1].to_i][0]}
- Create a ticketCreate a ticket
Method explorer
has 33 lines of code (exceeds 25 allowed). Consider refactoring. Open
def explorer
@explorer = true
@lastaction = "explorer"
@ght_type = nil
@report = nil
- Create a ticketCreate a ticket
Method upload
has 30 lines of code (exceeds 25 allowed). Consider refactoring. Open
def upload
assert_privileges("miq_report_export")
@sb[:flash_msg] = []
if params.fetch_path(:upload, :file) && File.size(params[:upload][:file].tempfile).zero?
- Create a ticketCreate a ticket
Method upload
has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring. Open
def upload
assert_privileges("miq_report_export")
@sb[:flash_msg] = []
if params.fetch_path(:upload, :file) && File.size(params[:upload][:file].tempfile).zero?
- 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 get_node_info
has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring. Open
def get_node_info(_node = {}, _show_list = true)
treenodeid = valid_active_node(x_node)
if %i[db_tree reports_tree saved_tree savedreports_tree widgets_tree].include?(x_active_tree)
@nodetype = case x_active_tree
when :savedreports_tree
- 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 accordion_select
has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring. Open
def accordion_select
@sb[:flash_msg] = []
@schedules = nil
@edit = nil
if params[: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 import_widgets
has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring. Open
def import_widgets
assert_privileges("miq_report_export")
if params[:commit] == _('Commit')
import_file_upload = ImportFileUpload.where(:id => params[:import_file_upload_id]).first
- 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
Avoid deeply nested control flow statements. Open
elsif x_active_tree == :reports_tree
action_url = "miq_report_edit"
record_id = @edit[:rpt_id] ? @edit[:rpt_id] : nil
elsif x_active_tree == :roles_tree
action_url = "menu_update"
- Create a ticketCreate a ticket
Avoid deeply nested control flow statements. Open
@right_cell_text = if @rpt.id
_("Editing Report \"%{name}\"") % {:name => @rpt.name}
else
_("Adding a new Report")
end
- Create a ticketCreate a ticket
Avoid deeply nested control flow statements. Open
elsif nodetype == "menu_commit_reports"
presenter.replace(:flash_msg_div, r[:partial => "layouts/flash_msg"]) if @flash_array
presenter.scroll_top if @flash_array.present?
if @refresh_div
presenter.hide(:flash_msg_div)
- Create a ticketCreate a ticket
Avoid deeply nested control flow statements. Open
@right_cell_text = @schedule.id ? _("Editing Schedule \"%{name}\"") % {:name => @schedule.name} : _("Adding a new Schedule")
- Create a ticketCreate a ticket
Method tree_select
has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring. Open
def tree_select
@edit = nil
@sb[:select_node] = false
if @sb.key?(:flash_msg)
@flash_array = @sb[:flash_msg]
- 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
Avoid deeply nested control flow statements. Open
presenter.scroll_top if @flash_array.present?
- Create a ticketCreate a ticket
Avoid deeply nested control flow statements. Open
if @edit[:new] && @edit[:new][:dashboard_order]
action_url = "db_seq_edit"
locals[:multi_record] = true
else
action_url = "db_edit"
- Create a ticketCreate a ticket
Method open_parent_nodes
has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring. Open
def open_parent_nodes
existing_node = nil
nodes = params[:id].split('_')
nodes.pop
parents = []
- 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
Avoid deeply nested control flow statements. Open
presenter.replace(:flash_msg_div, r[:partial => "layouts/flash_msg"]) if @flash_array
- Create a ticketCreate a ticket
Method get_subfilter_reports
has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring. Open
def get_subfilter_reports(reps)
reports = MiqReport.where(:name => reps)
reports.each do |report|
next if x_active_tree == :widgets_tree && report.db == "VimPerformanceTrend"
temp_arr = []
- 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 determine_root_node_info
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
def determine_root_node_info
case x_active_tree
when :db_tree
db_get_node_info
when :export_tree
- 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
Avoid more than 3 levels of block nesting. Open
if @in_a_form
presenter[:build_calendar] = true
@right_cell_text = @schedule.id ? _("Editing Schedule \"%{name}\"") % {:name => @schedule.name} : _("Adding a new Schedule")
end
- Read upRead up
- Create a ticketCreate a ticket
- Exclude checks
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. Open
if @sb[:wtype] == 'm'
presenter[:miq_widget_dd_url] = 'report/widget_shortcut_dd_done'
presenter[:init_dashboard] = true
end
- Read upRead up
- Create a ticketCreate a ticket
- Exclude checks
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. Open
@right_cell_text = @schedule.id ? _("Editing Schedule \"%{name}\"") % {:name => @schedule.name} : _("Adding a new Schedule")
- Read upRead up
- Create a ticketCreate a ticket
- Exclude checks
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. Open
@right_cell_text = if @rpt.id
_("Editing Report \"%{name}\"") % {:name => @rpt.name}
else
_("Adding a new Report")
end
- Read upRead up
- Create a ticketCreate a ticket
- Exclude checks
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. Open
@right_cell_text = @widget.id ? _("Editing Widget \"%{title}\"") % {:title => @widget.title} : _("Adding a new Widget")
- Read upRead up
- Create a ticketCreate a ticket
- Exclude checks
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. Open
@right_cell_text = if @edit[:new][:dashboard_order]
_("Editing Dashboard sequence for \"%{name}\"") % {:name => @sb[:group_desc]}
else
@dashboard.id ? _("Editing Dashboard \"%{name}\"") % {:name => @dashboard.name} : _("Adding a new dashboard")
end
- Read upRead up
- Create a ticketCreate a ticket
- Exclude checks
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.
Duplicate branch body detected. Open
else 'role_list'
- Read upRead up
- Create a ticketCreate a ticket
- Exclude checks
Checks that there are no repeated bodies
within if/unless
, case-when
, case-in
and rescue
constructs.
With IgnoreLiteralBranches: true
, branches are not registered
as offenses if they return a basic literal value (string, symbol,
integer, float, rational, complex, true
, false
, or nil
), or
return an array, hash, regexp or range that only contains one of
the above basic literal values.
With IgnoreConstantBranches: true
, branches are not registered
as offenses if they return a constant value.
Example:
# bad
if foo
do_foo
do_something_else
elsif bar
do_foo
do_something_else
end
# good
if foo || bar
do_foo
do_something_else
end
# bad
case x
when foo
do_foo
when bar
do_foo
else
do_something_else
end
# good
case x
when foo, bar
do_foo
else
do_something_else
end
# bad
begin
do_something
rescue FooError
handle_error
rescue BarError
handle_error
end
# good
begin
do_something
rescue FooError, BarError
handle_error
end
Example: IgnoreLiteralBranches: true
# good
case size
when "small" then 100
when "medium" then 250
when "large" then 1000
else 250
end
Example: IgnoreConstantBranches: true
# good
case size
when "small" then SMALL_SIZE
when "medium" then MEDIUM_SIZE
when "large" then LARGE_SIZE
else MEDIUM_SIZE
end
Duplicate branch body detected. Open
when "ws" then determine_xx_node_info
- Read upRead up
- Create a ticketCreate a ticket
- Exclude checks
Checks that there are no repeated bodies
within if/unless
, case-when
, case-in
and rescue
constructs.
With IgnoreLiteralBranches: true
, branches are not registered
as offenses if they return a basic literal value (string, symbol,
integer, float, rational, complex, true
, false
, or nil
), or
return an array, hash, regexp or range that only contains one of
the above basic literal values.
With IgnoreConstantBranches: true
, branches are not registered
as offenses if they return a constant value.
Example:
# bad
if foo
do_foo
do_something_else
elsif bar
do_foo
do_something_else
end
# good
if foo || bar
do_foo
do_something_else
end
# bad
case x
when foo
do_foo
when bar
do_foo
else
do_something_else
end
# good
case x
when foo, bar
do_foo
else
do_something_else
end
# bad
begin
do_something
rescue FooError
handle_error
rescue BarError
handle_error
end
# good
begin
do_something
rescue FooError, BarError
handle_error
end
Example: IgnoreLiteralBranches: true
# good
case size
when "small" then 100
when "medium" then 250
when "large" then 1000
else 250
end
Example: IgnoreConstantBranches: true
# good
case size
when "small" then SMALL_SIZE
when "medium" then MEDIUM_SIZE
when "large" then LARGE_SIZE
else MEDIUM_SIZE
end