Similar blocks of code found in 2 locations. Consider refactoring. Open
search(:node, "roles:hadoop-secondarynamenode") do |nsec|
# search(:node, "roles:hadoop-secondarynamenode#{env_filter}") do |nsec|
if !nsec[:fqdn].nil? && !nsec[:fqdn].empty?
Chef::Log.info("HADOOP : SECONDARY [#{nsec[:fqdn]}") if debug
secondary_name_nodes << nsec[: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 51.
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
search(:node, "roles:hadoop-masternamenode") do |nmas|
# search(:node, "roles:hadoop-masternamenode#{env_filter}") do |nmas|
if !nmas[:fqdn].nil? && !nmas[:fqdn].empty?
Chef::Log.info("HADOOP : MASTER [#{nmas[:fqdn]}") if debug
master_name_nodes << nmas[: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 51.
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
search(:node, "roles:hadoop-edgenode") do |nedge|
# search(:node, "roles:hadoop-edgenode#{env_filter}") do |nedge|
if !nedge[:fqdn].nil? && !nedge[:fqdn].empty?
Chef::Log.info("HADOOP : EDGE [#{nedge[:fqdn]}") if debug
edge_nodes << nedge[: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 48.
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
search(:node, "roles:hadoop-slavenode") do |nslave|
# search(:node, "roles:hadoop-slavenode#{env_filter}") do |nslave|
if !nslave[:fqdn].nil? && !nslave[:fqdn].empty?
Chef::Log.info("HADOOP : SLAVE [#{nslave[:fqdn]}") if debug
slave_nodes << nslave[: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 48.
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
if secondary_name_nodes.length == 0
Chef::Log.info("HADOOP : WARNING - Cannot find Hadoop secondary name node")
node[:hadoop][:cluster][:valid_config] = false
elsif secondary_name_nodes.length > 1
Chef::Log.info("HADOOP : WARNING - More than one secondary name node found}")
- 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 36.
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
if master_name_nodes.length == 0
Chef::Log.info("HADOOP : WARNING - Cannot find Hadoop master name node")
node[:hadoop][:cluster][:valid_config] = false
elsif master_name_nodes.length > 1
Chef::Log.info("HADOOP : WARNING - More than one master name node found")
- 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 36.
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
if master_node_ip.nil? || master_node_ip.empty? || master_node_ip == "0.0.0.0"
Chef::Log.info("HADOOP : WARNING - Invalid master name node IP #{master_node_ip}")
node[:hadoop][:cluster][:valid_config] = false
else
Chef::Log.info("HADOOP : MASTER NAME NODE IP #{master_node_ip}") if debug
- 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 33.
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
if secondary_node_ip.nil? || secondary_node_ip.empty? || secondary_node_ip == "0.0.0.0"
Chef::Log.info("HADOOP : WARNING - Invalid secondary name node IP #{secondary_node_ip}")
node[:hadoop][:cluster][:valid_config] = false
else
Chef::Log.info("HADOOP : SECONDARY NAME NODE IP #{secondary_node_ip}") if debug
- 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 33.
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
Favor modifier if
usage when having a single-line body. Another good alternative is the usage of control flow &&
/||
. (https://github.com/bbatsov/ruby-style-guide#if-as-a-modifier) Open
if slave_nodes.length == 0
- Read upRead up
- Create a ticketCreate a ticket
- Exclude checks
Checks for if and unless statements that would fit on one line
if written as a modifier if/unless. The maximum line length is
configured in the Metrics/LineLength
cop.
Example:
# bad
if condition
do_stuff(bar)
end
unless qux.empty?
Foo.do_something
end
# good
do_stuff(bar) if condition
Foo.do_something unless qux.empty?
Use next
to skip iteration. (https://github.com/bbatsov/ruby-style-guide#no-nested-conditionals) Open
unless v.nil?
- Read upRead up
- Create a ticketCreate a ticket
- Exclude checks
Use next
to skip iteration instead of a condition at the end.
Example: EnforcedStyle: skipmodifierifs (default)
# bad
[1, 2].each do |a|
if a == 1
puts a
end
end
# good
[1, 2].each do |a|
next unless a == 1
puts a
end
# good
[1, 2].each do |o|
puts o unless o == 1
end
Example: EnforcedStyle: always
# With `always` all conditions at the end of an iteration needs to be
# replaced by next - with `skip_modifier_ifs` the modifier if like
# this one are ignored: `[1, 2].each { |a| return 'yes' if a == 1 }`
# bad
[1, 2].each do |o|
puts o unless o == 1
end
# bad
[1, 2].each do |a|
if a == 1
puts a
end
end
# good
[1, 2].each do |a|
next unless a == 1
puts a
end
Line is too long. [114/100] (https://github.com/SUSE/style-guides/blob/master/Ruby.md#metricslinelength) Open
Chef::Log.info("HADOOP : MASTER_NAME_NODES {" + node[:hadoop][:cluster][:master_name_nodes] .join(",") + "}")
- Create a ticketCreate a ticket
- Exclude checks
Use !empty?
instead of length > 0
. Open
if master_name_nodes.length > 0
- Read upRead up
- Create a ticketCreate a ticket
- Exclude checks
This cop checks for numeric comparisons that can be replaced by a predicate method, such as receiver.length == 0, receiver.length > 0, receiver.length != 0, receiver.length < 1 and receiver.size == 0 that can be replaced by receiver.empty? and !receiver.empty.
Example:
# bad
[1, 2, 3].length == 0
0 == "foobar".length
array.length < 1
{a: 1, b: 2}.length != 0
string.length > 0
hash.size > 0
# good
[1, 2, 3].empty?
"foobar".empty?
array.empty?
!{a: 1, b: 2}.empty?
!string.empty?
!hash.empty?
Line is too long. [116/100] (https://github.com/SUSE/style-guides/blob/master/Ruby.md#metricslinelength) Open
Chef::Log.info("HADOOP : SECONDARY_NAME_NODES {" + node[:hadoop][:cluster][:secondary_name_nodes].join(",") + "}")
- Create a ticketCreate a ticket
- Exclude checks
Use array literal []
instead of Array.new
. (https://github.com/bbatsov/ruby-style-guide#literal-array-hash) Open
secondary_name_nodes = Array.new
- Read upRead up
- Create a ticketCreate a ticket
- Exclude checks
This cop checks for the use of a method, the result of which would be a literal, like an empty array, hash or string.
Example:
# bad
a = Array.new
h = Hash.new
s = String.new
# good
a = []
h = {}
s = ''
Use master_name_nodes.length.zero?
instead of master_name_nodes.length == 0
. (https://github.com/bbatsov/ruby-style-guide#predicate-methods) Open
if master_name_nodes.length == 0
- Read upRead up
- Create a ticketCreate a ticket
- 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
Avoid using rescue
in its modifier form. (https://github.com/bbatsov/ruby-style-guide#no-rescue-modifiers) Open
keys[nsec.name] = nsec["crowbar"]["ssh"]["root_pub_key"] rescue nil
- Read upRead up
- Create a ticketCreate a ticket
- Exclude checks
This cop checks for uses of rescue in its modifier form.
Example:
# bad
some_method rescue handle_error
# good
begin
some_method
rescue
handle_error
end
Space missing after comma. (https://github.com/bbatsov/ruby-style-guide#spaces-operators) Open
keys.each do |k,v|
- Read upRead up
- Create a ticketCreate a ticket
- Exclude checks
Checks for comma (,) not followed by some kind of space.
Example:
# bad
[1,2]
{ foo:bar,}
# good
[1, 2]
{ foo:bar, }
Line is too long. [120/100] (https://github.com/SUSE/style-guides/blob/master/Ruby.md#metricslinelength) Open
master_node_ip = BarclampLibrary::Barclamp::Inventory.get_network_by_type(master_name_node_objects[0],"admin").address
- Create a ticketCreate a ticket
- Exclude checks
Convert if
nested inside else
to elsif
. Open
Chef::Log.info("HADOOP : SECONDARY NAME NODE IP #{secondary_node_ip}") if debug
- Read upRead up
- Create a ticketCreate a ticket
- Exclude checks
If the else
branch of a conditional consists solely of an if
node,
it can be combined with the else
to become an elsif
.
This helps to keep the nesting level from getting too deep.
Example:
# bad
if condition_a
action_a
else
if condition_b
action_b
else
action_c
end
end
# good
if condition_a
action_a
elsif condition_b
action_b
else
action_c
end
Use array literal []
instead of Array.new
. (https://github.com/bbatsov/ruby-style-guide#literal-array-hash) Open
edge_nodes = Array.new
- Read upRead up
- Create a ticketCreate a ticket
- Exclude checks
This cop checks for the use of a method, the result of which would be a literal, like an empty array, hash or string.
Example:
# bad
a = Array.new
h = Hash.new
s = String.new
# good
a = []
h = {}
s = ''
Avoid using rescue
in its modifier form. (https://github.com/bbatsov/ruby-style-guide#no-rescue-modifiers) Open
keys[nedge.name] = nedge["crowbar"]["ssh"]["root_pub_key"] rescue nil
- Read upRead up
- Create a ticketCreate a ticket
- Exclude checks
This cop checks for uses of rescue in its modifier form.
Example:
# bad
some_method rescue handle_error
# good
begin
some_method
rescue
handle_error
end
Use array literal []
instead of Array.new
. (https://github.com/bbatsov/ruby-style-guide#literal-array-hash) Open
master_name_nodes = Array.new
- Read upRead up
- Create a ticketCreate a ticket
- Exclude checks
This cop checks for the use of a method, the result of which would be a literal, like an empty array, hash or string.
Example:
# bad
a = Array.new
h = Hash.new
s = String.new
# good
a = []
h = {}
s = ''
Use empty?
instead of length == 0
. Open
if slave_nodes.length == 0
- Read upRead up
- Create a ticketCreate a ticket
- Exclude checks
This cop checks for numeric comparisons that can be replaced by a predicate method, such as receiver.length == 0, receiver.length > 0, receiver.length != 0, receiver.length < 1 and receiver.size == 0 that can be replaced by receiver.empty? and !receiver.empty.
Example:
# bad
[1, 2, 3].length == 0
0 == "foobar".length
array.length < 1
{a: 1, b: 2}.length != 0
string.length > 0
hash.size > 0
# good
[1, 2, 3].empty?
"foobar".empty?
array.empty?
!{a: 1, b: 2}.empty?
!string.empty?
!hash.empty?
Avoid using rescue
in its modifier form. (https://github.com/bbatsov/ruby-style-guide#no-rescue-modifiers) Open
keys[nmas.name] = nmas["crowbar"]["ssh"]["root_pub_key"] rescue nil
- Read upRead up
- Create a ticketCreate a ticket
- Exclude checks
This cop checks for uses of rescue in its modifier form.
Example:
# bad
some_method rescue handle_error
# good
begin
some_method
rescue
handle_error
end
Use !empty?
instead of length > 0
. Open
if !master_name_node_objects.nil? && master_name_node_objects.length > 0
- Read upRead up
- Create a ticketCreate a ticket
- Exclude checks
This cop checks for numeric comparisons that can be replaced by a predicate method, such as receiver.length == 0, receiver.length > 0, receiver.length != 0, receiver.length < 1 and receiver.size == 0 that can be replaced by receiver.empty? and !receiver.empty.
Example:
# bad
[1, 2, 3].length == 0
0 == "foobar".length
array.length < 1
{a: 1, b: 2}.length != 0
string.length > 0
hash.size > 0
# good
[1, 2, 3].empty?
"foobar".empty?
array.empty?
!{a: 1, b: 2}.empty?
!string.empty?
!hash.empty?
Use !empty?
instead of length > 0
. Open
if !secondary_name_node_objects.nil? && secondary_name_node_objects.length > 0
- Read upRead up
- Create a ticketCreate a ticket
- Exclude checks
This cop checks for numeric comparisons that can be replaced by a predicate method, such as receiver.length == 0, receiver.length > 0, receiver.length != 0, receiver.length < 1 and receiver.size == 0 that can be replaced by receiver.empty? and !receiver.empty.
Example:
# bad
[1, 2, 3].length == 0
0 == "foobar".length
array.length < 1
{a: 1, b: 2}.length != 0
string.length > 0
hash.size > 0
# good
[1, 2, 3].empty?
"foobar".empty?
array.empty?
!{a: 1, b: 2}.empty?
!string.empty?
!hash.empty?
Use array literal []
instead of Array.new
. (https://github.com/bbatsov/ruby-style-guide#literal-array-hash) Open
slave_nodes = Array.new
- Read upRead up
- Create a ticketCreate a ticket
- Exclude checks
This cop checks for the use of a method, the result of which would be a literal, like an empty array, hash or string.
Example:
# bad
a = Array.new
h = Hash.new
s = String.new
# good
a = []
h = {}
s = ''
Use empty?
instead of length == 0
. Open
if master_name_nodes.length == 0
- Read upRead up
- Create a ticketCreate a ticket
- Exclude checks
This cop checks for numeric comparisons that can be replaced by a predicate method, such as receiver.length == 0, receiver.length > 0, receiver.length != 0, receiver.length < 1 and receiver.size == 0 that can be replaced by receiver.empty? and !receiver.empty.
Example:
# bad
[1, 2, 3].length == 0
0 == "foobar".length
array.length < 1
{a: 1, b: 2}.length != 0
string.length > 0
hash.size > 0
# good
[1, 2, 3].empty?
"foobar".empty?
array.empty?
!{a: 1, b: 2}.empty?
!string.empty?
!hash.empty?
Use empty?
instead of length == 0
. Open
if secondary_name_nodes.length == 0
- Read upRead up
- Create a ticketCreate a ticket
- Exclude checks
This cop checks for numeric comparisons that can be replaced by a predicate method, such as receiver.length == 0, receiver.length > 0, receiver.length != 0, receiver.length < 1 and receiver.size == 0 that can be replaced by receiver.empty? and !receiver.empty.
Example:
# bad
[1, 2, 3].length == 0
0 == "foobar".length
array.length < 1
{a: 1, b: 2}.length != 0
string.length > 0
hash.size > 0
# good
[1, 2, 3].empty?
"foobar".empty?
array.empty?
!{a: 1, b: 2}.empty?
!string.empty?
!hash.empty?
Use array literal []
instead of Array.new
. (https://github.com/bbatsov/ruby-style-guide#literal-array-hash) Open
secondary_name_node_objects = Array.new
- Read upRead up
- Create a ticketCreate a ticket
- Exclude checks
This cop checks for the use of a method, the result of which would be a literal, like an empty array, hash or string.
Example:
# bad
a = Array.new
h = Hash.new
s = String.new
# good
a = []
h = {}
s = ''
Line is too long. [106/100] (https://github.com/SUSE/style-guides/blob/master/Ruby.md#metricslinelength) Open
Chef::Log.info("HADOOP : EDGE_NODES {" + node[:hadoop][:cluster][:edge_nodes].join(",") + "}")
- Create a ticketCreate a ticket
- Exclude checks
Line is too long. [107/100] (https://github.com/SUSE/style-guides/blob/master/Ruby.md#metricslinelength) Open
Chef::Log.info("HADOOP : SLAVE_NODES {" + node[:hadoop][:cluster][:slave_nodes].join(",") + "}")
- Create a ticketCreate a ticket
- Exclude checks
Convert if
nested inside else
to elsif
. Open
Chef::Log.info("HADOOP : MASTER NAME NODE IP #{master_node_ip}") if debug
- Read upRead up
- Create a ticketCreate a ticket
- Exclude checks
If the else
branch of a conditional consists solely of an if
node,
it can be combined with the else
to become an elsif
.
This helps to keep the nesting level from getting too deep.
Example:
# bad
if condition_a
action_a
else
if condition_b
action_b
else
action_c
end
end
# good
if condition_a
action_a
elsif condition_b
action_b
else
action_c
end
Don't use parentheses around the condition of an if
. (https://github.com/bbatsov/ruby-style-guide#no-parens-around-condition) Open
next if (d.nil? || d.empty?)
- Read upRead up
- Create a ticketCreate a ticket
- Exclude checks
This cop checks for the presence of superfluous parentheses around the condition of if/unless/while/until.
Example:
# bad
x += 1 while (x < 10)
foo unless (bar || baz)
if (x > 10)
elsif (x < 3)
end
# good
x += 1 while x < 10
foo unless bar || baz
if x > 10
elsif x < 3
end
Avoid using rescue
in its modifier form. (https://github.com/bbatsov/ruby-style-guide#no-rescue-modifiers) Open
keys[nslave.name] = nslave["crowbar"]["ssh"]["root_pub_key"] rescue nil
- Read upRead up
- Create a ticketCreate a ticket
- Exclude checks
This cop checks for uses of rescue in its modifier form.
Example:
# bad
some_method rescue handle_error
# good
begin
some_method
rescue
handle_error
end
Space missing after comma. (https://github.com/bbatsov/ruby-style-guide#spaces-operators) Open
master_node_ip = BarclampLibrary::Barclamp::Inventory.get_network_by_type(master_name_node_objects[0],"admin").address
- Read upRead up
- Create a ticketCreate a ticket
- Exclude checks
Checks for comma (,) not followed by some kind of space.
Example:
# bad
[1,2]
{ foo:bar,}
# good
[1, 2]
{ foo:bar, }
Space missing after comma. (https://github.com/bbatsov/ruby-style-guide#spaces-operators) Open
secondary_node_ip = BarclampLibrary::Barclamp::Inventory.get_network_by_type(secondary_name_node_objects[0],"admin").address
- Read upRead up
- Create a ticketCreate a ticket
- Exclude checks
Checks for comma (,) not followed by some kind of space.
Example:
# bad
[1,2]
{ foo:bar,}
# good
[1, 2]
{ foo:bar, }
Use array literal []
instead of Array.new
. (https://github.com/bbatsov/ruby-style-guide#literal-array-hash) Open
master_name_node_objects = Array.new
- Read upRead up
- Create a ticketCreate a ticket
- Exclude checks
This cop checks for the use of a method, the result of which would be a literal, like an empty array, hash or string.
Example:
# bad
a = Array.new
h = Hash.new
s = String.new
# good
a = []
h = {}
s = ''
Line is too long. [126/100] (https://github.com/SUSE/style-guides/blob/master/Ruby.md#metricslinelength) Open
secondary_node_ip = BarclampLibrary::Barclamp::Inventory.get_network_by_type(secondary_name_node_objects[0],"admin").address
- Create a ticketCreate a ticket
- Exclude checks
Line is too long. [105/100] (https://github.com/SUSE/style-guides/blob/master/Ruby.md#metricslinelength) Open
# Create mapred_local_dir and set ownership/permissions (/var/lib/hadoop-0.20/cache/mapred/mapred/local).
- Create a ticketCreate a ticket
- Exclude checks
Use secondary_name_nodes.length.zero?
instead of secondary_name_nodes.length == 0
. (https://github.com/bbatsov/ruby-style-guide#predicate-methods) Open
if secondary_name_nodes.length == 0
- Read upRead up
- Create a ticketCreate a ticket
- 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 slave_nodes.length.zero?
instead of slave_nodes.length == 0
. (https://github.com/bbatsov/ruby-style-guide#predicate-methods) Open
if slave_nodes.length == 0
- Read upRead up
- Create a ticketCreate a ticket
- 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