Showing 509 of 509 total issues
Pass &:nil?
as an argument to delete_if
instead of a block. Open
nodes.delete_if { |n| n.nil? }
- Read upRead up
- Create a ticketCreate a ticket
- Exclude checks
Use symbols as procs when possible.
Example:
# bad
something.map { |s| s.upcase }
# good
something.map(&:upcase)
Line is too long. [163/100] (https://github.com/SUSE/style-guides/blob/master/Ruby.md#metricslinelength) Open
export << I18n.t(".barclamp.hadoop_infrastructure.nodes.edgenodes") + ", #{node.ip}, #{node.name}, #{node.cpu}, #{node.memory}, #{node.number_of_drives}"
- Create a ticketCreate a ticket
- Exclude checks
1 trailing blank lines detected. (https://github.com/bbatsov/ruby-style-guide#newline-eof) Open
- Create a ticketCreate a ticket
- Exclude checks
Avoid rescuing without specifying an error class. Open
rescue
- Read upRead up
- Create a ticketCreate a ticket
- Exclude checks
This cop checks for rescuing StandardError
. There are two supported
styles implicit
and explicit
. This cop will not register an offense
if any error other than StandardError
is specified.
Example: EnforcedStyle: implicit
# `implicit` will enforce using `rescue` instead of
# `rescue StandardError`.
# bad
begin
foo
rescue StandardError
bar
end
# good
begin
foo
rescue
bar
end
# good
begin
foo
rescue OtherError
bar
end
# good
begin
foo
rescue StandardError, SecurityError
bar
end
Example: EnforcedStyle: explicit (default)
# `explicit` will enforce using `rescue StandardError`
# instead of `rescue`.
# bad
begin
foo
rescue
bar
end
# good
begin
foo
rescue StandardError
bar
end
# good
begin
foo
rescue OtherError
bar
end
# good
begin
foo
rescue StandardError, SecurityError
bar
end
1 trailing blank lines detected. (https://github.com/bbatsov/ruby-style-guide#newline-eof) Open
- 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
edge_fqdns = 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. [171/100] (https://github.com/SUSE/style-guides/blob/master/Ruby.md#metricslinelength) Open
export << I18n.t(".barclamp.hadoop_infrastructure.nodes.hajournalingnodes") + ", #{node.ip}, #{node.name}, #{node.cpu}, #{node.memory}, #{node.number_of_drives}"
- Create a ticketCreate a ticket
- Exclude checks
Prefer double-quoted strings inside interpolations. (https://github.com/SUSE/style-guides/blob/master/Ruby.md#stylestringliteralsininterpolation) Open
headers["Content-Disposition"] = "attachment; filename=\"#{I18n.t('nodes.dell.nodes.filename', default: 'hadoop_infrastructure_inventory.txt')}\""
- Read upRead up
- Create a ticketCreate a ticket
- 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"}"
1 trailing blank lines detected. (https://github.com/bbatsov/ruby-style-guide#newline-eof) Open
- Create a ticketCreate a ticket
- Exclude checks
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 simple.exist?
- 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 !empty?
instead of length > 0
. Open
if !edge_fqdns.nil? && edge_fqdns.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. [163/100] (https://github.com/SUSE/style-guides/blob/master/Ruby.md#metricslinelength) Open
export << I18n.t(".barclamp.hadoop_infrastructure.nodes.namenodes") + ", #{node.ip}, #{node.name}, #{node.cpu}, #{node.memory}, #{node.number_of_drives}"
- Create a ticketCreate a ticket
- Exclude checks
Avoid using {...}
for multi-line blocks. (https://github.com/bbatsov/ruby-style-guide#single-line-blocks) Open
slave_nodes.each { |x|
- 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("-")
Use array literal []
instead of Array.new
. (https://github.com/bbatsov/ruby-style-guide#literal-array-hash) Open
slave_fqdns = 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 = ''
Carriage return character detected. (https://github.com/bbatsov/ruby-style-guide#crlf) Open
#
# Cookbook Name: zookeeper
- Create a ticketCreate a ticket
- Exclude checks
Carriage return character detected. (https://github.com/bbatsov/ruby-style-guide#crlf) Open
#
# Cookbook Name: hadoop
- Create a ticketCreate a ticket
- Exclude checks
Pass &:nil?
as an argument to delete_if
instead of a block. Open
nodes.delete_if { |n| n.nil? }
- Read upRead up
- Create a ticketCreate a ticket
- Exclude checks
Use symbols as procs when possible.
Example:
# bad
something.map { |s| s.upcase }
# good
something.map(&:upcase)
Avoid using {...}
for multi-line blocks. (https://github.com/bbatsov/ruby-style-guide#single-line-blocks) Open
format.text {
- 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("-")
Use __dir__
to get an absolute path to the current file's directory. Open
require File.join(File.expand_path(File.dirname(__FILE__)), "barclamp_lib")
- Read upRead up
- Create a ticketCreate a ticket
- Exclude checks
This cop checks for places where the #__dir__
method can replace more
complex constructs to retrieve a canonicalized absolute path to the
current file.
Example:
# bad
path = File.expand_path(File.dirname(__FILE__))
# bad
path = File.dirname(File.realpath(__FILE__))
# good
path = __dir__
Use __dir__
to get an absolute path to the current file's directory. Open
require File.join(File.expand_path(File.dirname(__FILE__)), "barclamp_lib")
- Read upRead up
- Create a ticketCreate a ticket
- Exclude checks
This cop checks for places where the #__dir__
method can replace more
complex constructs to retrieve a canonicalized absolute path to the
current file.
Example:
# bad
path = File.expand_path(File.dirname(__FILE__))
# bad
path = File.dirname(File.realpath(__FILE__))
# good
path = __dir__