Showing 509 of 509 total issues
Useless assignment to variable - env_filter
. (https://github.com/bbatsov/ruby-style-guide#underscore-unused-vars) Open
env_filter = " AND environment:#{node[:zookeeper][:config][:environment]}"
- Read upRead up
- Create a ticketCreate a ticket
- Exclude checks
This cop checks for every useless assignment to local variable in every
scope.
The basic idea for this cop was from the warning of ruby -cw
:
assigned but unused variable - foo
Currently this cop has advanced logic that detects unreferenced reassignments and properly handles varied cases such as branch, loop, rescue, ensure, etc.
Example:
# bad
def some_method
some_var = 1
do_something
end
Example:
# good
def some_method
some_var = 1
do_something(some_var)
end
Use next
to skip iteration. (https://github.com/bbatsov/ruby-style-guide#no-nested-conditionals) Open
if File.exists?(lock_file)
- 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. [102/100] (https://github.com/SUSE/style-guides/blob/master/Ruby.md#metricslinelength) Open
recipe "hadoop::masternamenode", "Installs the master name node package and prepares the file system."
- Create a ticketCreate a ticket
- Exclude checks
Surrounding space missing for operator =
. (https://github.com/bbatsov/ruby-style-guide#spaces-operators) Open
hive_packages=%w{
- 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
The name of this source file (zookeeper-site.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
Favor unless
over if
for negative conditions. (https://github.com/bbatsov/ruby-style-guide#unless-for-negatives) Open
myid = myid + 1 if !myid.nil?
- Read upRead up
- Create a ticketCreate a ticket
- Exclude checks
Checks for uses of if with a negated condition. Only ifs without else are considered. There are three different styles:
- both
- prefix
- postfix
Example: EnforcedStyle: both (default)
# enforces `unless` for `prefix` and `postfix` conditionals
# bad
if !foo
bar
end
# good
unless foo
bar
end
# bad
bar if !foo
# good
bar unless foo
Example: EnforcedStyle: prefix
# enforces `unless` for just `prefix` conditionals
# bad
if !foo
bar
end
# good
unless foo
bar
end
# good
bar if !foo
Example: EnforcedStyle: postfix
# enforces `unless` for just `postfix` conditionals
# bad
bar if !foo
# good
bar unless foo
# good
if !foo
bar
end
Line is too long. [109/100] (https://github.com/SUSE/style-guides/blob/master/Ruby.md#metricslinelength) Open
recipe "hadoop::slavenode", "Installs the slave node and task tracker packages and prepares the file system."
- Create a ticketCreate a ticket
- Exclude checks
Favor unless
over if
for negative conditions. (https://github.com/bbatsov/ruby-style-guide#unless-for-negatives) Open
if !is_ok
found_disks.each { |disk|
if pid == disk[:pid]
disk[:valid] = false
Chef::Log.info("HI - disk format failed for #{disk[:name]}") if debug
- Read upRead up
- Create a ticketCreate a ticket
- Exclude checks
Checks for uses of if with a negated condition. Only ifs without else are considered. There are three different styles:
- both
- prefix
- postfix
Example: EnforcedStyle: both (default)
# enforces `unless` for `prefix` and `postfix` conditionals
# bad
if !foo
bar
end
# good
unless foo
bar
end
# bad
bar if !foo
# good
bar unless foo
Example: EnforcedStyle: prefix
# enforces `unless` for just `prefix` conditionals
# bad
if !foo
bar
end
# good
unless foo
bar
end
# good
bar if !foo
Example: EnforcedStyle: postfix
# enforces `unless` for just `postfix` conditionals
# bad
bar if !foo
# good
bar unless foo
# good
if !foo
bar
end
File.exists?
is deprecated in favor of File.exist?
. Open
if File.exists?(rc_local_path)
- Read upRead up
- Create a ticketCreate a ticket
- Exclude checks
This cop checks for uses of the deprecated class method usages.
Example:
# bad
File.exists?(some_path)
Example:
# good
File.exist?(some_path)
Use &&
instead of and
. (https://github.com/bbatsov/ruby-style-guide#no-and-or-or) Open
if n[:fqdn] and not n[:fqdn].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
Use !
instead of not
. (https://github.com/bbatsov/ruby-style-guide#bang-not-not) Open
if n[:fqdn] and not n[:fqdn].empty?
- Read upRead up
- Create a ticketCreate a ticket
- Exclude checks
This cop checks for uses of the keyword not
instead of !
.
Example:
# bad - parentheses are required because of op precedence
x = (not something)
# good
x = !something
Use %r
around regular expression. (https://github.com/SUSE/style-guides/blob/master/Ruby.md#styleregexpliteral) Open
new_buff = cur_buff.gsub(/^[\t ]*echo\s*(.+?)\s*>\s*\/sys\/kernel\/mm\/redhat_transparent_hugepage\/defrag[\t ]*$/, rep_str)
- Read upRead up
- Create a ticketCreate a ticket
- Exclude checks
This cop enforces using // or %r around regular expressions.
Example: EnforcedStyle: slashes (default)
# bad
snake_case = %r{^[\dA-Z_]+$}
# bad
regex = %r{
foo
(bar)
(baz)
}x
# good
snake_case = /^[\dA-Z_]+$/
# good
regex = /
foo
(bar)
(baz)
/x
Example: EnforcedStyle: percent_r
# bad
snake_case = /^[\dA-Z_]+$/
# bad
regex = /
foo
(bar)
(baz)
/x
# good
snake_case = %r{^[\dA-Z_]+$}
# good
regex = %r{
foo
(bar)
(baz)
}x
Example: EnforcedStyle: mixed
# bad
snake_case = %r{^[\dA-Z_]+$}
# bad
regex = /
foo
(bar)
(baz)
/x
# good
snake_case = /^[\dA-Z_]+$/
# good
regex = %r{
foo
(bar)
(baz)
}x
Example: AllowInnerSlashes: false (default)
# If `false`, the cop will always recommend using `%r` if one or more
# slashes are found in the regexp string.
# bad
x =~ /home\//
# good
x =~ %r{home/}
Example: AllowInnerSlashes: true
# good
x =~ /home\//
%w
-literals should be delimited by [
and ]
. (https://github.com/bbatsov/ruby-style-guide#percent-literal-braces) Open
nfs_packages=%w{
nfs-utils
}
- Read upRead up
- Create a ticketCreate a ticket
- Exclude checks
This cop enforces the consistent usage of %
-literal delimiters.
Specify the 'default' key to set all preferred delimiters at once. You can continue to specify individual preferred delimiters to override the default.
Example:
# Style/PercentLiteralDelimiters:
# PreferredDelimiters:
# default: '[]'
# '%i': '()'
# good
%w[alpha beta] + %i(gamma delta)
# bad
%W(alpha #{beta})
# bad
%I(alpha beta)
Use next
to skip iteration. (https://github.com/bbatsov/ruby-style-guide#no-nested-conditionals) Open
unless v.nil? or v.empty?
- 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. [103/100] (https://github.com/SUSE/style-guides/blob/master/Ruby.md#metricslinelength) Open
license "Apache 2.0 License, Copyright (c) 2011 Dell Inc. - http://www.apache.org/licenses/LICENSE-2.0"
- Create a ticketCreate a ticket
- Exclude checks
Use hash literal {}
instead of Hash.new
. (https://github.com/bbatsov/ruby-style-guide#literal-array-hash) Open
disk = Hash.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 = ''
Prefer double-quoted strings inside interpolations. (https://github.com/SUSE/style-guides/blob/master/Ruby.md#stylestringliteralsininterpolation) Open
Chef::Log.info("HI - found disk: #{to_use_disks.join(':')} fs_type: [#{fs_type}]") if debug
- 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"}"
Avoid using rescue
in its modifier form. (https://github.com/bbatsov/ruby-style-guide#no-rescue-modifiers) Open
ssh_key = n[: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 []
for an array of words. (https://github.com/SUSE/style-guides/blob/master/Ruby.md#stylewordarray) Open
xfs_packages=%w{
xfsprogs
}
- Read upRead up
- Create a ticketCreate a ticket
- Exclude checks
This cop can check for array literals made up of word-like strings, that are not using the %w() syntax.
Alternatively, it can check for uses of the %w() syntax, in projects which do not want to include that syntax.
Configuration option: MinSize
If set, arrays with fewer elements than this value will not trigger the
cop. For example, a MinSize
of 3
will not enforce a style on an
array of 2 or fewer elements.
Example: EnforcedStyle: percent (default)
# good
%w[foo bar baz]
# bad
['foo', 'bar', 'baz']
Example: EnforcedStyle: brackets
# good
['foo', 'bar', 'baz']
# bad
%w[foo bar baz]
%w
-literals should be delimited by [
and ]
. (https://github.com/bbatsov/ruby-style-guide#percent-literal-braces) Open
hive_packages=%w{
hive
hive-metastore
hive-server2
}
- Read upRead up
- Create a ticketCreate a ticket
- Exclude checks
This cop enforces the consistent usage of %
-literal delimiters.
Specify the 'default' key to set all preferred delimiters at once. You can continue to specify individual preferred delimiters to override the default.
Example:
# Style/PercentLiteralDelimiters:
# PreferredDelimiters:
# default: '[]'
# '%i': '()'
# good
%w[alpha beta] + %i(gamma delta)
# bad
%W(alpha #{beta})
# bad
%I(alpha beta)