Assignment Branch Condition size for create_proposal is too high. [95.97/30] (https://github.com/SUSE/style-guides/blob/master/Ruby.md#metricsabcsize, http://c2.com/cgi/wiki?AbcMetric) Open
def create_proposal
@logger.debug("hadoop create_proposal: entering")
base = super
# Compute the hadoop cluster node distribution.
- Read upRead up
- Create a ticketCreate a ticket
- 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 create_proposal
has a Cognitive Complexity of 39 (exceeds 5 allowed). Consider refactoring. Open
def create_proposal
@logger.debug("hadoop create_proposal: entering")
base = super
# Compute the hadoop cluster node distribution.
- 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 create_proposal is too high. [26/6] Open
def create_proposal
@logger.debug("hadoop create_proposal: entering")
base = super
# Compute the hadoop cluster node distribution.
- Read upRead up
- Create a ticketCreate a ticket
- 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 create_proposal is too high. [27/7] Open
def create_proposal
@logger.debug("hadoop create_proposal: entering")
base = super
# Compute the hadoop cluster node distribution.
- Read upRead up
- Create a ticketCreate a ticket
- 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 create_proposal
has 41 lines of code (exceeds 25 allowed). Consider refactoring. Open
def create_proposal
@logger.debug("hadoop create_proposal: entering")
base = super
# Compute the hadoop cluster node distribution.
- Create a ticketCreate a ticket
Method apply_role_pre_chef_call
has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring. Open
def apply_role_pre_chef_call(old_role, role, all_nodes)
@logger.debug("hadoop apply_role_pre_chef_call: entering #{all_nodes.inspect}")
return if all_nodes.empty?
# Make sure that the front-end pieces have public ip addreses.
- 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
master << nodes[0][:fqdn] if nodes[0][:fqdn]
- Create a ticketCreate a ticket
Avoid deeply nested control flow statements. Open
slaves << nodes[1][:fqdn] if nodes[1][:fqdn]
- Create a ticketCreate a ticket
Avoid deeply nested control flow statements. Open
slaves << n[:fqdn] if n[:fqdn]
- Create a ticketCreate a ticket
Avoid deeply nested control flow statements. Open
edge << nodes[2][:fqdn] if nodes[2][:fqdn]
- Create a ticketCreate a ticket
Similar blocks of code found in 2 locations. Consider refactoring. Open
def apply_role_pre_chef_call(old_role, role, all_nodes)
@logger.debug("hadoop apply_role_pre_chef_call: entering #{all_nodes.inspect}")
return if all_nodes.empty?
# Make sure that the front-end pieces have public ip addreses.
- Read upRead up
- Create a ticketCreate a ticket
Duplicated Code
Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:
Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.
When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).
Tuning
This issue has a mass of 56.
We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.
The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.
If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.
See codeclimate-duplication
's documentation for more information about tuning the mass threshold in your .codeclimate.yml
.
Refactorings
- Extract Method
- Extract Class
- Form Template Method
- Introduce Null Object
- Pull Up Method
- Pull Up Field
- Substitute Algorithm
Further Reading
- Don't Repeat Yourself on the C2 Wiki
- Duplicated Code on SourceMaking
- Refactoring: Improving the Design of Existing Code by Martin Fowler. Duplicated Code, p76
Similar blocks of code found in 2 locations. Consider refactoring. Open
master << nodes[0][:fqdn] if nodes[0][:fqdn]
slaves << nodes[1][:fqdn] if nodes[1][:fqdn]
- Read upRead up
- Create a ticketCreate a ticket
Duplicated Code
Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:
Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.
When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).
Tuning
This issue has a mass of 27.
We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.
The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.
If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.
See codeclimate-duplication
's documentation for more information about tuning the mass threshold in your .codeclimate.yml
.
Refactorings
- Extract Method
- Extract Class
- Form Template Method
- Introduce Null Object
- Pull Up Method
- Pull Up Field
- Substitute Algorithm
Further Reading
- Don't Repeat Yourself on the C2 Wiki
- Duplicated Code on SourceMaking
- Refactoring: Improving the Design of Existing Code by Martin Fowler. Duplicated Code, p76
Line is too long. [101/100] (https://github.com/SUSE/style-guides/blob/master/Ruby.md#metricslinelength) Open
base["deployment"]["hadoop"]["elements"]["hadoop-slavenode"] = slaves if slaves && !slaves.empty?
- Create a ticketCreate a ticket
- Exclude checks
Line is too long. [118/100] (https://github.com/SUSE/style-guides/blob/master/Ruby.md#metricslinelength) Open
base["deployment"]["hadoop"]["elements"]["hadoop-secondarynamenode"] = secondary if secondary && !secondary.empty?
- Create a ticketCreate a ticket
- Exclude checks
Avoid using {...}
for multi-line blocks. (https://github.com/bbatsov/ruby-style-guide#single-line-blocks) Open
nodes[3 .. nodes.size].each { |n|
- Read upRead up
- Create a ticketCreate a ticket
- Exclude checks
Check for uses of braces or do/end around single line or multi-line blocks.
Example: EnforcedStyle: linecountbased (default)
# bad - single line block
items.each do |item| item / 5 end
# good - single line block
items.each { |item| item / 5 }
# bad - multi-line block
things.map { |thing|
something = thing.some_method
process(something)
}
# good - multi-line block
things.map do |thing|
something = thing.some_method
process(something)
end
Example: EnforcedStyle: semantic
# Prefer `do...end` over `{...}` for procedural blocks.
# return value is used/assigned
# bad
foo = map do |x|
x
end
puts (map do |x|
x
end)
# return value is not used out of scope
# good
map do |x|
x
end
# Prefer `{...}` over `do...end` for functional blocks.
# return value is not used out of scope
# bad
each { |x|
x
}
# return value is used/assigned
# good
foo = map { |x|
x
}
map { |x|
x
}.inspect
Example: EnforcedStyle: bracesforchaining
# bad
words.each do |word|
word.flip.flop
end.join("-")
# good
words.each { |word|
word.flip.flop
}.join("-")
Line is too long. [106/100] (https://github.com/SUSE/style-guides/blob/master/Ruby.md#metricslinelength) Open
base["deployment"]["hadoop"]["elements"]["hadoop-masternamenode"] = master if master && !master.empty?
- Create a ticketCreate a ticket
- Exclude checks
Space inside empty hash literal braces detected. (https://github.com/bbatsov/ruby-style-guide#spaces-operators) Open
base["deployment"]["hadoop"]["elements"] = { }
- Read upRead up
- Create a ticketCreate a ticket
- Exclude checks
Checks that braces used for hash literals have or don't have surrounding space depending on configuration.
Example: EnforcedStyle: space
# The `space` style enforces that hash literals have
# surrounding space.
# bad
h = {a: 1, b: 2}
# good
h = { a: 1, b: 2 }
Example: EnforcedStyle: no_space
# The `no_space` style enforces that hash literals have
# no surrounding space.
# bad
h = { a: 1, b: 2 }
# good
h = {a: 1, b: 2}
Example: EnforcedStyle: compact
# The `compact` style normally requires a space inside
# hash braces, with the exception that successive left
# braces or right braces are collapsed together in nested hashes.
# bad
h = { a: { b: 2 } }
# good
h = { a: { b: 2 }}
Space inside range literal. (https://github.com/bbatsov/ruby-style-guide#no-space-inside-range-literals) Open
nodes[3 .. nodes.size].each { |n|
- Read upRead up
- Create a ticketCreate a ticket
- Exclude checks
Checks for spaces inside range literals.
Example:
# bad
1 .. 3
# good
1..3
# bad
'a' .. 'z'
# good
'a'..'z'
Use ||
instead of or
. (https://github.com/bbatsov/ruby-style-guide#no-and-or-or) Open
next if tnodes.nil? or tnodes.empty?
- Read upRead up
- Create a ticketCreate a ticket
- Exclude checks
This cop checks for uses of and
and or
, and suggests using &&
and
|| instead
. It can be configured to check only in conditions, or in
all contexts.
Example: EnforcedStyle: always (default)
# bad
foo.save and return
# bad
if foo and bar
end
# good
foo.save && return
# good
if foo && bar
end
Example: EnforcedStyle: conditionals
# bad
if foo and bar
end
# good
foo.save && return
# good
foo.save and return
# good
if foo && bar
end