Module has too many lines. [191/100] Open
module Cibtools
# Roughly equivalent to crm_element_value() in Pacemaker
def get_xml_attr(elem, name, default = nil)
return nil if elem.nil?
- Read upRead up
- Exclude checks
This cop checks if the length a module exceeds some maximum value. Comment lines can optionally be ignored. The maximum allowed length is configurable.
Assignment Branch Condition size for rsc_state_from_lrm_rsc_op is too high. [57.91/15] Open
def rsc_state_from_lrm_rsc_op(xml, node_uname, rsc_id)
xml.elements.each("cib/status/node_state[@uname='#{node_uname}']/lrm/lrm_resources/lrm_resource[@id='#{rsc_id}']") do |lrm_resource|
# logic derived somewhat from pacemaker/lib/pengine/unpack.c:unpack_rsc_op()
state = :unknown
ops = []
- Read upRead up
- 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 rsc_state_from_lrm_rsc_op
has a Cognitive Complexity of 37 (exceeds 5 allowed). Consider refactoring. Open
def rsc_state_from_lrm_rsc_op(xml, node_uname, rsc_id)
xml.elements.each("cib/status/node_state[@uname='#{node_uname}']/lrm/lrm_resources/lrm_resource[@id='#{rsc_id}']") do |lrm_resource|
# logic derived somewhat from pacemaker/lib/pengine/unpack.c:unpack_rsc_op()
state = :unknown
ops = []
- 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
Assignment Branch Condition size for sort_ops is too high. [42/15] Open
def sort_ops(a, b)
a_op = a.attributes['operation']
b_op = b.attributes['operation']
a_call_id = a.attributes['call-id'].to_i
b_call_id = b.attributes['call-id'].to_i
- Read upRead up
- 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
Cyclomatic complexity for rsc_state_from_lrm_rsc_op is too high. [18/6] Open
def rsc_state_from_lrm_rsc_op(xml, node_uname, rsc_id)
xml.elements.each("cib/status/node_state[@uname='#{node_uname}']/lrm/lrm_resources/lrm_resource[@id='#{rsc_id}']") do |lrm_resource|
# logic derived somewhat from pacemaker/lib/pengine/unpack.c:unpack_rsc_op()
state = :unknown
ops = []
- Read upRead up
- 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.
Perceived complexity for rsc_state_from_lrm_rsc_op is too high. [19/7] Open
def rsc_state_from_lrm_rsc_op(xml, node_uname, rsc_id)
xml.elements.each("cib/status/node_state[@uname='#{node_uname}']/lrm/lrm_resources/lrm_resource[@id='#{rsc_id}']") do |lrm_resource|
# logic derived somewhat from pacemaker/lib/pengine/unpack.c:unpack_rsc_op()
state = :unknown
ops = []
- Read upRead up
- 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
Method has too many lines. [40/30] Open
def rsc_state_from_lrm_rsc_op(xml, node_uname, rsc_id)
xml.elements.each("cib/status/node_state[@uname='#{node_uname}']/lrm/lrm_resources/lrm_resource[@id='#{rsc_id}']") do |lrm_resource|
# logic derived somewhat from pacemaker/lib/pengine/unpack.c:unpack_rsc_op()
state = :unknown
ops = []
- Read upRead up
- 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.
Perceived complexity for sort_ops is too high. [13/7] Open
def sort_ops(a, b)
a_op = a.attributes['operation']
b_op = b.attributes['operation']
a_call_id = a.attributes['call-id'].to_i
b_call_id = b.attributes['call-id'].to_i
- Read upRead up
- 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 sort_ops is too high. [11/6] Open
def sort_ops(a, b)
a_op = a.attributes['operation']
b_op = b.attributes['operation']
a_call_id = a.attributes['call-id'].to_i
b_call_id = b.attributes['call-id'].to_i
- Read upRead up
- 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.
Cyclomatic complexity for rc_desc is too high. [11/6] Open
def rc_desc(rc)
case rc
when 0
_('success')
when 1
- Read upRead up
- 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.
Cyclomatic complexity for determine_online_status_fencing is too high. [11/6] Open
def determine_online_status_fencing(ns)
in_ccm = get_xml_attr(ns, 'in_ccm')
crm_state = get_xml_attr(ns, 'crmd')
join_state = get_xml_attr(ns, 'join')
exp_state = get_xml_attr(ns, 'expected')
- Read upRead up
- 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.
Assignment Branch Condition size for determine_online_status_fencing is too high. [19.9/15] Open
def determine_online_status_fencing(ns)
in_ccm = get_xml_attr(ns, 'in_ccm')
crm_state = get_xml_attr(ns, 'crmd')
join_state = get_xml_attr(ns, 'join')
exp_state = get_xml_attr(ns, 'expected')
- Read upRead up
- 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
Perceived complexity for determine_online_status_fencing is too high. [10/7] Open
def determine_online_status_fencing(ns)
in_ccm = get_xml_attr(ns, 'in_ccm')
crm_state = get_xml_attr(ns, 'crmd')
join_state = get_xml_attr(ns, 'join')
exp_state = get_xml_attr(ns, 'expected')
- Read upRead up
- 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
Method rsc_state_from_lrm_rsc_op
has 40 lines of code (exceeds 25 allowed). Consider refactoring. Open
def rsc_state_from_lrm_rsc_op(xml, node_uname, rsc_id)
xml.elements.each("cib/status/node_state[@uname='#{node_uname}']/lrm/lrm_resources/lrm_resource[@id='#{rsc_id}']") do |lrm_resource|
# logic derived somewhat from pacemaker/lib/pengine/unpack.c:unpack_rsc_op()
state = :unknown
ops = []
Method sort_ops
has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring. Open
def sort_ops(a, b)
a_op = a.attributes['operation']
b_op = b.attributes['operation']
a_call_id = a.attributes['call-id'].to_i
b_call_id = b.attributes['call-id'].to_i
- 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 sort_ops
has 28 lines of code (exceeds 25 allowed). Consider refactoring. Open
def sort_ops(a, b)
a_op = a.attributes['operation']
b_op = b.attributes['operation']
a_call_id = a.attributes['call-id'].to_i
b_call_id = b.attributes['call-id'].to_i
Method determine_online_status_fencing
has 27 lines of code (exceeds 25 allowed). Consider refactoring. Open
def determine_online_status_fencing(ns)
in_ccm = get_xml_attr(ns, 'in_ccm')
crm_state = get_xml_attr(ns, 'crmd')
join_state = get_xml_attr(ns, 'join')
exp_state = get_xml_attr(ns, 'expected')
Method determine_online_status_fencing
has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring. Open
def determine_online_status_fencing(ns)
in_ccm = get_xml_attr(ns, 'in_ccm')
crm_state = get_xml_attr(ns, 'crmd')
join_state = get_xml_attr(ns, 'join')
exp_state = get_xml_attr(ns, 'expected')
- 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 determine_online_status_no_fencing
has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring. Open
def determine_online_status_no_fencing(ns)
in_ccm = get_xml_attr(ns, 'in_ccm')
crm_state = get_xml_attr(ns, 'crmd')
join_state = get_xml_attr(ns, 'join')
- 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
Extra blank line detected. Open
# transliteration of pacemaker/lib/pengine/unpack.c:determine_online_status_fencing()
- Read upRead up
- Exclude checks
This cops checks for two or more consecutive blank lines.
Example:
# bad - It has two empty lines.
some_method
# one empty line
# two empty lines
some_method
# good
some_method
# one empty line
some_method
Extra blank line detected. Open
# Format the epoch string "admin_epoch:epoch:num_updates"
- Read upRead up
- Exclude checks
This cops checks for two or more consecutive blank lines.
Example:
# bad - It has two empty lines.
some_method
# one empty line
# two empty lines
some_method
# good
some_method
# one empty line
some_method
Extra empty line detected at module body beginning. Open
# Roughly equivalent to crm_element_value() in Pacemaker
- Read upRead up
- Exclude checks
This cops checks if empty lines around the bodies of modules match the configuration.
Example: EnforcedStyle: empty_lines
# good
module Foo
def bar
# ...
end
end
Example: EnforcedStyle: emptylinesexcept_namespace
# good
module Foo
module Bar
# ...
end
end
Example: EnforcedStyle: emptylinesspecial
# good
module Foo
def bar; end
end
Example: EnforcedStyle: noemptylines (default)
# good
module Foo
def bar
# ...
end
end
Extra blank line detected. Open
module Cibtools
- Read upRead up
- Exclude checks
This cops checks for two or more consecutive blank lines.
Example:
# bad - It has two empty lines.
some_method
# one empty line
# two empty lines
some_method
# good
some_method
# one empty line
some_method
Redundant return
detected. Open
return state
- Read upRead up
- Exclude checks
This cop checks for redundant return
expressions.
Example:
def test
return something
end
def test
one
two
three
return something
end
It should be extended to handle methods whose body is if/else or a case expression with a default branch.
Use the return of the conditional for variable assignment and comparison. Open
case join_state
when 'member' # rock 'n' roll (online)
state = :online
when exp_state # coming up (!online)
state = :offline
- Exclude checks
Use a guard clause instead of wrapping the code inside a conditional expression. Open
if stonith_enabled
- Read upRead up
- Exclude checks
Use a guard clause instead of wrapping the code inside a conditional expression
Example:
# bad
def test
if something
work
end
end
# good
def test
return unless something
work
end
# also good
def test
work if something
end
# bad
if something
raise 'exception'
else
ok
end
# good
raise 'exception' if something
ok
Do not use semicolons to terminate expressions. Open
"#{Cibtools.get_xml_attr(elem, 'admin_epoch', '0')}:#{Cibtools.get_xml_attr(elem, 'epoch', '0')}:#{Cibtools.get_xml_attr(elem, 'num_updates', '0')}";
- Read upRead up
- Exclude checks
This cop checks for multiple expressions placed on the same line. It also checks for lines terminated with a semicolon.
Example:
# bad
foo = 1; bar = 2;
baz = 3;
# good
foo = 1
bar = 2
baz = 3
Redundant return
detected. Open
return state
- Read upRead up
- Exclude checks
This cop checks for redundant return
expressions.
Example:
def test
return something
end
def test
one
two
three
return something
end
It should be extended to handle methods whose body is if/else or a case expression with a default branch.
Prefer double-quoted strings inside interpolations. Open
"#{Cibtools.get_xml_attr(elem, 'admin_epoch', '0')}:#{Cibtools.get_xml_attr(elem, 'epoch', '0')}:#{Cibtools.get_xml_attr(elem, 'num_updates', '0')}";
- Read upRead up
- Exclude checks
This cop checks that quotes inside the string interpolation match the configured preference.
Example: EnforcedStyle: single_quotes (default)
# bad
result = "Tests #{success ? "PASS" : "FAIL"}"
# good
result = "Tests #{success ? 'PASS' : 'FAIL'}"
Example: EnforcedStyle: double_quotes
# bad
result = "Tests #{success ? 'PASS' : 'FAIL'}"
# good
result = "Tests #{success ? "PASS" : "FAIL"}"
Prefer double-quoted strings inside interpolations. Open
"#{Cibtools.get_xml_attr(elem, 'admin_epoch', '0')}:#{Cibtools.get_xml_attr(elem, 'epoch', '0')}:#{Cibtools.get_xml_attr(elem, 'num_updates', '0')}";
- Read upRead up
- Exclude checks
This cop checks that quotes inside the string interpolation match the configured preference.
Example: EnforcedStyle: single_quotes (default)
# bad
result = "Tests #{success ? "PASS" : "FAIL"}"
# good
result = "Tests #{success ? 'PASS' : 'FAIL'}"
Example: EnforcedStyle: double_quotes
# bad
result = "Tests #{success ? 'PASS' : 'FAIL'}"
# good
result = "Tests #{success ? "PASS" : "FAIL"}"
Prefer double-quoted strings inside interpolations. Open
"#{Cibtools.get_xml_attr(elem, 'admin_epoch', '0')}:#{Cibtools.get_xml_attr(elem, 'epoch', '0')}:#{Cibtools.get_xml_attr(elem, 'num_updates', '0')}";
- Read upRead up
- Exclude checks
This cop checks that quotes inside the string interpolation match the configured preference.
Example: EnforcedStyle: single_quotes (default)
# bad
result = "Tests #{success ? "PASS" : "FAIL"}"
# good
result = "Tests #{success ? 'PASS' : 'FAIL'}"
Example: EnforcedStyle: double_quotes
# bad
result = "Tests #{success ? 'PASS' : 'FAIL'}"
# good
result = "Tests #{success ? "PASS" : "FAIL"}"
Redundant return
detected. Open
return determine_online_status_no_fencing(ns)
- Read upRead up
- Exclude checks
This cop checks for redundant return
expressions.
Example:
def test
return something
end
def test
one
two
three
return something
end
It should be extended to handle methods whose body is if/else or a case expression with a default branch.
Redundant return
detected. Open
return determine_online_status_fencing(ns)
- Read upRead up
- Exclude checks
This cop checks for redundant return
expressions.
Example:
def test
return something
end
def test
one
two
three
return something
end
It should be extended to handle methods whose body is if/else or a case expression with a default branch.
Use the return of the conditional for variable assignment and comparison. Open
if join_state == 'member'
state = :online
else
# not ready yet (should this break down to pending/banned like
# determine_online_status_fencing? It doesn't in unpack.c...)
- Exclude checks
Prefer double-quoted strings inside interpolations. Open
"#{Cibtools.get_xml_attr(elem, 'admin_epoch', '0')}:#{Cibtools.get_xml_attr(elem, 'epoch', '0')}:#{Cibtools.get_xml_attr(elem, 'num_updates', '0')}";
- Read upRead up
- Exclude checks
This cop checks that quotes inside the string interpolation match the configured preference.
Example: EnforcedStyle: single_quotes (default)
# bad
result = "Tests #{success ? "PASS" : "FAIL"}"
# good
result = "Tests #{success ? 'PASS' : 'FAIL'}"
Example: EnforcedStyle: double_quotes
# bad
result = "Tests #{success ? 'PASS' : 'FAIL'}"
# good
result = "Tests #{success ? "PASS" : "FAIL"}"
Use get_xml_attr(ns, 'shutdown', '0').zero?
instead of get_xml_attr(ns, 'shutdown', '0') == 0
. Open
expected_up = get_xml_attr(ns, 'shutdown', '0') == 0
- Read upRead up
- Exclude checks
This cop checks for usage of comparison operators (==
,
>
, <
) to test numbers as zero, positive, or negative.
These can be replaced by their respective predicate methods.
The cop can also be configured to do the reverse.
The cop disregards #nonzero?
as it its value is truthy or falsey,
but not true
and false
, and thus not always interchangeable with
!= 0
.
The cop ignores comparisons to global variables, since they are often
populated with objects which can be compared with integers, but are
not themselves Interger
polymorphic.
Example: EnforcedStyle: predicate (default)
# bad
foo == 0
0 > foo
bar.baz > 0
# good
foo.zero?
foo.negative?
bar.baz.positive?
Example: EnforcedStyle: comparison
# bad
foo.zero?
foo.negative?
bar.baz.positive?
# good
foo == 0
0 > foo
bar.baz > 0
Use get_xml_attr(ns, 'shutdown', '0').zero?
instead of get_xml_attr(ns, 'shutdown', '0') == 0
. Open
expected_up = get_xml_attr(ns, 'shutdown', '0') == 0
- Read upRead up
- Exclude checks
This cop checks for usage of comparison operators (==
,
>
, <
) to test numbers as zero, positive, or negative.
These can be replaced by their respective predicate methods.
The cop can also be configured to do the reverse.
The cop disregards #nonzero?
as it its value is truthy or falsey,
but not true
and false
, and thus not always interchangeable with
!= 0
.
The cop ignores comparisons to global variables, since they are often
populated with objects which can be compared with integers, but are
not themselves Interger
polymorphic.
Example: EnforcedStyle: predicate (default)
# bad
foo == 0
0 > foo
bar.baz > 0
# good
foo.zero?
foo.negative?
bar.baz.positive?
Example: EnforcedStyle: comparison
# bad
foo.zero?
foo.negative?
bar.baz.positive?
# good
foo == 0
0 > foo
bar.baz > 0
Prefer double-quoted strings inside interpolations. Open
"#{Cibtools.get_xml_attr(elem, 'admin_epoch', '0')}:#{Cibtools.get_xml_attr(elem, 'epoch', '0')}:#{Cibtools.get_xml_attr(elem, 'num_updates', '0')}";
- Read upRead up
- Exclude checks
This cop checks that quotes inside the string interpolation match the configured preference.
Example: EnforcedStyle: single_quotes (default)
# bad
result = "Tests #{success ? "PASS" : "FAIL"}"
# good
result = "Tests #{success ? 'PASS' : 'FAIL'}"
Example: EnforcedStyle: double_quotes
# bad
result = "Tests #{success ? 'PASS' : 'FAIL'}"
# good
result = "Tests #{success ? "PASS" : "FAIL"}"
Prefer double-quoted strings inside interpolations. Open
"#{Cibtools.get_xml_attr(elem, 'admin_epoch', '0')}:#{Cibtools.get_xml_attr(elem, 'epoch', '0')}:#{Cibtools.get_xml_attr(elem, 'num_updates', '0')}";
- Read upRead up
- Exclude checks
This cop checks that quotes inside the string interpolation match the configured preference.
Example: EnforcedStyle: single_quotes (default)
# bad
result = "Tests #{success ? "PASS" : "FAIL"}"
# good
result = "Tests #{success ? 'PASS' : 'FAIL'}"
Example: EnforcedStyle: double_quotes
# bad
result = "Tests #{success ? 'PASS' : 'FAIL'}"
# good
result = "Tests #{success ? "PASS" : "FAIL"}"