Use 0o for octal literals. (https://github.com/bbatsov/ruby-style-guide#numeric-literal-prefixes) Open
mode 0644
- Read upRead up
- Create a ticketCreate a ticket
- Exclude checks
This cop checks for octal, hex, binary and decimal literals using
uppercase prefixes and corrects them to lowercase prefix
or no prefix (in case of decimals).
eg. for octal use 0o
instead of 0
or 0O
.
Can be configured to use 0
only for octal literals using
EnforcedOctalStyle
=> zero_only
Use 0o for octal literals. (https://github.com/bbatsov/ruby-style-guide#numeric-literal-prefixes) Open
mode 0644
- Read upRead up
- Create a ticketCreate a ticket
- Exclude checks
This cop checks for octal, hex, binary and decimal literals using
uppercase prefixes and corrects them to lowercase prefix
or no prefix (in case of decimals).
eg. for octal use 0o
instead of 0
or 0O
.
Can be configured to use 0
only for octal literals using
EnforcedOctalStyle
=> zero_only
Space missing after comma. (https://github.com/bbatsov/ruby-style-guide#spaces-operators) Open
myip = BarclampLibrary::Barclamp::Inventory.get_network_by_type(node,"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
servers = 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. [108/100] (https://github.com/SUSE/style-guides/blob/master/Ruby.md#metricslinelength) Open
search(:node, "roles:zookeeper-server AND zookeeper_cluster_name:#{node[:zookeeper][:cluster_name]}") do |n|
- 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
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
Use 2 spaces for indentation in a hash, relative to the start of the line where the left curly brace is. Open
ipaddress: ipaddress,
- Read upRead up
- Create a ticketCreate a ticket
- Exclude checks
This cops checks the indentation of the first key in a hash literal where the opening brace and the first key are on separate lines. The other keys' indentations are handled by the AlignHash cop.
By default, Hash literals that are arguments in a method call with parentheses, and where the opening curly brace of the hash is on the same line as the opening parenthesis of the method call, shall have their first key indented one step (two spaces) more than the position inside the opening parenthesis.
Other hash literals shall have their first key indented one step more than the start of the line where the opening curly brace is.
This default style is called 'specialinsideparentheses'. Alternative styles are 'consistent' and 'align_braces'. Here are examples:
Example: EnforcedStyle: specialinsideparentheses (default)
# The `special_inside_parentheses` style enforces that the first key
# in a hash literal where the opening brace and the first key are on
# separate lines is indented one step (two spaces) more than the
# position inside the opening parentheses.
# bad
hash = {
key: :value
}
and_in_a_method_call({
no: :difference
})
# good
special_inside_parentheses
hash = {
key: :value
}
but_in_a_method_call({
its_like: :this
})
Example: EnforcedStyle: consistent
# The `consistent` style enforces that the first key in a hash
# literal where the opening brace and the first key are on
# seprate lines is indented the same as a hash literal which is not
# defined inside a method call.
# bad
hash = {
key: :value
}
but_in_a_method_call({
its_like: :this
})
# good
hash = {
key: :value
}
and_in_a_method_call({
no: :difference
})
Example: EnforcedStyle: align_braces
# The `align_brackets` style enforces that the opening and closing
# braces are indented to the same position.
# bad
and_now_for_something = {
completely: :different
}
# good
and_now_for_something = {
completely: :different
}
Space missing after comma. (https://github.com/bbatsov/ruby-style-guide#spaces-operators) Open
ipaddress = BarclampLibrary::Barclamp::Inventory.get_network_by_type(n,"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, }
Line is too long. [101/100] (https://github.com/SUSE/style-guides/blob/master/Ruby.md#metricslinelength) Open
Chef::Log.info("ZOOKEEPER : FOUND SERVER [" + rec[:ipaddress] + ", " + rec[:fqdn] + "]") if debug
- Create a ticketCreate a ticket
- Exclude checks
Use !empty?
instead of size > 0
. Open
if servers.size > 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 self-assignment shorthand +=
. (https://github.com/bbatsov/ruby-style-guide#self-assignment) Open
myid = myid + 1 if !myid.nil?
- Read upRead up
- Create a ticketCreate a ticket
- Exclude checks
This cop enforces the use the shorthand for self-assignment.
Example:
# bad
x = x + 1
# good
x += 1
Use 0o for octal literals. (https://github.com/bbatsov/ruby-style-guide#numeric-literal-prefixes) Open
mode 0644
- Read upRead up
- Create a ticketCreate a ticket
- Exclude checks
This cop checks for octal, hex, binary and decimal literals using
uppercase prefixes and corrects them to lowercase prefix
or no prefix (in case of decimals).
eg. for octal use 0o
instead of 0
or 0O
.
Can be configured to use 0
only for octal literals using
EnforcedOctalStyle
=> zero_only
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