Showing 509 of 509 total issues
Space missing after comma. (https://github.com/bbatsov/ruby-style-guide#spaces-operators) Open
all_disks.each { |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, }
The name of this source file (configure-disks.rb
) should use snake_case. (https://github.com/bbatsov/ruby-style-guide#snake-case-files) Open
#
- Read upRead up
- Create a ticketCreate a ticket
- Exclude checks
This cop makes sure that Ruby source files have snake_case names. Ruby scripts (i.e. source files with a shebang in the first line) are ignored.
Example:
# bad
lib/layoutManager.rb
anything/usingCamelCase
# good
lib/layout_manager.rb
anything/using_snake_case.rake
Use &&
instead of and
. (https://github.com/bbatsov/ruby-style-guide#no-and-or-or) Open
unless ::File.exists?(disk[:mount_point]) and ::File.directory?(disk[:mount_point])
- 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
Avoid using {...}
for multi-line blocks. (https://github.com/bbatsov/ruby-style-guide#single-line-blocks) Open
IO.popen("blkid -c /dev/null -s UUID -o value #{disk}"){ |f|
- 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("-")
Don't use parentheses around an unary operation. Open
if (!File.exists?("#{hb}/meta1/current/VERSION"))
- Read upRead up
- Create a ticketCreate a ticket
- Exclude checks
This cop checks for redundant parentheses.
Example:
# bad
(x) if ((y.z).nil?)
# good
x if y.z.nil?
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, }
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
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?
Space inside parentheses detected. (https://github.com/bbatsov/ruby-style-guide#spaces-braces) Open
datanodes = nodeswithroles.find_all { |n| n.roles.include?("hadoop_infrastructure-datanode" ) }
- Read upRead up
- Create a ticketCreate a ticket
- Exclude checks
Checks for spaces inside ordinary round parentheses.
Example:
# bad
f( 3)
g = (a + 3 )
# good
f(3)
g = (a + 3)
Line is too long. [107/100] (https://github.com/SUSE/style-guides/blob/master/Ruby.md#metricslinelength) Open
namenodes = nodeswithroles.find_all { |n| n.roles.include?("hadoop_infrastructure-namenode" ) }
- 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
base["deployment"]["hadoop_infrastructure"]["elements"]["hadoop_infrastructure-namenode"] = namenodes
- Create a ticketCreate a ticket
- Exclude checks
Line is too long. [101/100] (https://github.com/SUSE/style-guides/blob/master/Ruby.md#metricslinelength) Open
default[:hadoop][:core][:io_serializations] = "org.apache.hadoop.io.serializer.WritableSerialization"
- Create a ticketCreate a ticket
- Exclude checks
Unnecessary spacing detected. Open
mount disk[:mount_point] do
- Read upRead up
- Create a ticketCreate a ticket
- Exclude checks
This cop checks for extra/unnecessary whitespace.
Example:
# good if AllowForAlignment is true
name = "RuboCop"
# Some comment and an empty line
website += "/bbatsov/rubocop" unless cond
puts "rubocop" if debug
# bad for any configuration
set_app("RuboCop")
website = "https://github.com/bbatsov/rubocop"
Surrounding space missing for operator =
. (https://github.com/bbatsov/ruby-style-guide#spaces-operators) Open
uuid=f.read.strip
- Read upRead up
- Create a ticketCreate a ticket
- Exclude checks
Checks that operators have space around them, except for ** which should not have surrounding space.
Example:
# bad
total = 3*4
"apple"+"juice"
my_number = 38/4
a ** b
# good
total = 3 * 4
"apple" + "juice"
my_number = 38 / 4
a**b
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
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 = ''
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 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
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
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?