Showing 509 of 509 total issues
Use 2 spaces for indentation in a heredoc by using some library(e.g. ActiveSupport's String#strip_heredoc
). (https://github.com/bbatsov/ruby-style-guide#squiggly-heredocs) Open
rm -f #{lock_file}
EOH
- Read upRead up
- Create a ticketCreate a ticket
- Exclude checks
This cops checks the indentation of the here document bodies. The bodies
are indented one step.
In Ruby 2.3 or newer, squiggly heredocs (<<~
) should be used. If you
use the older rubies, you should introduce some library to your project
(e.g. ActiveSupport, Powerpack or Unindent).
Note: When Metrics/LineLength
's AllowHeredoc
is false(not default),
this cop does not add any offenses for long here documents to
avoid Metrics/LineLength
's offenses.
Example:
# bad
<<-RUBY
something
RUBY
# good
# When EnforcedStyle is squiggly, bad code is auto-corrected to the
# following code.
<<~RUBY
something
RUBY
# good
# When EnforcedStyle is active_support, bad code is auto-corrected to
# the following code.
<<-RUBY.strip_heredoc
something
RUBY
The name of this source file (cm-namenode.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
Useless assignment to variable - env_filter
. (https://github.com/bbatsov/ruby-style-guide#underscore-unused-vars) Open
env_filter = " AND environment:#{node[:hadoop_infrastructure][: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
Indent the right bracket the same as the start of the line where the left bracket is. Open
}
- Read upRead up
- Create a ticketCreate a ticket
- Exclude checks
This cop checks the indentation of the first element in an array literal where the opening bracket and the first element are on separate lines. The other elements' indentations are handled by the AlignArray cop.
By default, array literals that are arguments in a method call with parentheses, and where the opening square bracket of the array is on the same line as the opening parenthesis of the method call, shall have their first element indented one step (two spaces) more than the position inside the opening parenthesis.
Other array literals shall have their first element indented one step more than the start of the line where the opening square bracket is.
This default style is called 'specialinsideparentheses'. Alternative styles are 'consistent' and 'align_brackets'. Here are examples:
Example: EnforcedStyle: specialinsideparentheses (default)
# The `special_inside_parentheses` style enforces that the first
# element in an array literal where the opening bracket and first
# element are on seprate lines is indented one step (two spaces) more
# than the position inside the opening parenthesis.
#bad
array = [
:value
]
and_in_a_method_call([
:no_difference
])
#good
array = [
:value
]
but_in_a_method_call([
:its_like_this
])
Example: EnforcedStyle: consistent
# The `consistent` style enforces that the first element in an array
# literal where the opening bracket and the first element are on
# seprate lines is indented the same as an array literal which is not
# defined inside a method call.
#bad
# consistent
array = [
:value
]
but_in_a_method_call([
:its_like_this
])
#good
array = [
:value
]
and_in_a_method_call([
:no_difference
])
Example: EnforcedStyle: align_brackets
# The `align_brackets` style enforces that the opening and closing
# brackets are indented to the same position.
#bad
# align_brackets
and_now_for_something = [
:completely_different
]
#good
# align_brackets
and_now_for_something = [
:completely_different
]
Do not use semicolons to terminate expressions. (https://github.com/bbatsov/ruby-style-guide#no-semicolon) Open
break;
- Read upRead up
- Create a ticketCreate a ticket
- Exclude checks
This cop checks for multiple expressions placed on the same line. It also checks for lines terminated with a semicolon.
Example:
# bad
foo = 1; bar = 2;
baz = 3;
# good
foo = 1
bar = 2
baz = 3
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
Avoid using rescue
in its modifier form. (https://github.com/bbatsov/ruby-style-guide#no-rescue-modifiers) Open
key = n[:ssh_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
Line is too long. [217/100] (https://github.com/SUSE/style-guides/blob/master/Ruby.md#metricslinelength) Open
description "High-performance coordination service for distributed applications. ZooKeeper provides primitives such as distributed locks which can be used for building large scale distributed processing applications."
- Create a ticketCreate a ticket
- Exclude checks
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
The name of this source file (hadoop-env.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
Line is too long. [110/100] (https://github.com/SUSE/style-guides/blob/master/Ruby.md#metricslinelength) Open
default[:hadoop][:mapred][:mapred_map_output_compression_codec] = "org.apache.hadoop.io.compress.DefaultCodec"
- Create a ticketCreate a ticket
- Exclude checks
Use stat.exitstatus.zero?
instead of stat.exitstatus == 0
. (https://github.com/bbatsov/ruby-style-guide#predicate-methods) Open
if stat and stat.exited? and stat.exitstatus == 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
Pass &:device
as an argument to map
instead of a block. Open
to_use_disks = BarclampLibrary::Barclamp::Inventory::Disk.claimed(node,"Cloudera").map do |d|
d.device
end.sort
- 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)
File.exists?
is deprecated in favor of File.exist?
. Open
if File.exists?(defrag_file_pathname)
- 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)
Line is too long. [107/100] (https://github.com/SUSE/style-guides/blob/master/Ruby.md#metricslinelength) Open
Chef::Log.info("HI - Updating #{defrag_file_pathname} with the new THP setting [#{cur_thpval}]") if debug
- Create a ticketCreate a ticket
- Exclude checks
Convert if
nested inside else
to elsif
. Open
Chef::Log.info("HI - Current THP setting is correct [#{reg_thpval},#{cur_thpval}]") 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 cur_buff.length.zero?
instead of cur_buff.length == 0
. (https://github.com/bbatsov/ruby-style-guide#predicate-methods) Open
if cur_buff.length == 0 or cur_buff[cur_buff.length - 1] == 10
- 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
Convert if
nested inside else
to elsif
. Open
Chef::Log.info("HI - HA mount directory already exists [#{shared_edits_directory}]") 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
Convert if
nested inside else
to elsif
. Open
Chef::Log.info("HI - HA export directory already exists [#{shared_edits_directory}]") 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
Line is too long. [107/100] (https://github.com/SUSE/style-guides/blob/master/Ruby.md#metricslinelength) Open
description "Data warehouse infrastructure that provides SQL based data summarization and ad hoc querying."
- Create a ticketCreate a ticket
- Exclude checks