Showing 1,311 of 1,311 total issues
Avoid using Marshal.load
. Open
msg_data && Marshal.load(msg_data)
- Read upRead up
- Create a ticketCreate a ticket
- Exclude checks
Checks for the use of Marshal class methods which have potential security issues leading to remote code execution when loading from an untrusted source.
Example:
# bad
Marshal.load("{}")
Marshal.restore("{}")
# good
Marshal.dump("{}")
# okish - deep copy hack
Marshal.load(Marshal.dump({}))
Avoid immutable Array literals in loops. It is better to extract it into a local variable or a constant. Open
unless options.values.all? { |v| [true, false].include?(v) }
- Create a ticketCreate a ticket
- Exclude checks
Avoid immutable Array literals in loops. It is better to extract it into a local variable or a constant. Open
key.data.except!(*(%w[id] + hidden_columns))
- Create a ticketCreate a ticket
- Exclude checks
Avoid immutable Array literals in loops. It is better to extract it into a local variable or a constant. Open
next if %w[id created_on updated_on updated_by].include?(cname) || cname.ends_with?("_id")
- Create a ticketCreate a ticket
- Exclude checks
Use Array.new(scaling_min)
with a block instead of .times.collect
only if scaling_min
is always 0 or more. Open
scaling_min.times.collect do |idx|
create_request_task(idx) do |req_task|
req_task.miq_request_id = service_task.miq_request.id
req_task.userid = service_task.userid
- Read upRead up
- Create a ticketCreate a ticket
- Exclude checks
This cop checks for .times.map calls. In most cases such calls can be replaced with an explicit array creation.
Example:
# bad
9.times.map do |i|
i.to_s
end
# good
Array.new(9) do |i|
i.to_s
end
Use filter_map
instead. Open
@values[:src_vm_nics] = vm.hardware && vm.hardware.nics.collect(&:device_name).compact
- Create a ticketCreate a ticket
- Exclude checks
Avoid more than 3 levels of block nesting. Open
assoc_klass = (assoc_reflection.options[:polymorphic] ? k : assoc_reflection.klass) if assoc_reflection
- Read upRead up
- Create a ticketCreate a ticket
- Exclude checks
Checks for excessive nesting of conditional and looping constructs.
You can configure if blocks are considered using the CountBlocks
option. When set to false
(the default) blocks are not counted
towards the nesting level. Set to true
to count blocks as well.
The maximum level of nesting allowed is configurable.
Use filter_map
instead. Open
when :date then @table.data.collect { |d| d.data[sb] }.compact.max.try(:+, 1)
- Create a ticketCreate a ticket
- Exclude checks
Avoid more than 3 levels of block nesting. Open
if method == "type"
subst = rec.class.to_s
elsif method == "ems" && rec.respond_to?(:ext_management_system)
ems = rec.ext_management_system
subst = "vCenter #{ems.hostname}/#{ems.ipaddress}" unless ems.nil?
- Read upRead up
- Create a ticketCreate a ticket
- Exclude checks
Checks for excessive nesting of conditional and looping constructs.
You can configure if blocks are considered using the CountBlocks
option. When set to false
(the default) blocks are not counted
towards the nesting level. Set to true
to count blocks as well.
The maximum level of nesting allowed is configurable.
The use of eval
is a serious security risk. Open
eval("result = \"#{str}\"")
- Read upRead up
- Create a ticketCreate a ticket
- Exclude checks
Checks for the use of Kernel#eval
and Binding#eval
.
Example:
# bad
eval(something)
binding.eval(something)
Duplicate branch body detected. Open
when :max_derived_memory_reserved
attributes = [:max_derived_memory_used, :derived_memory_used]
- Read upRead up
- Create a ticketCreate a ticket
- Exclude checks
Checks that there are no repeated bodies
within if/unless
, case-when
, case-in
and rescue
constructs.
With IgnoreLiteralBranches: true
, branches are not registered
as offenses if they return a basic literal value (string, symbol,
integer, float, rational, complex, true
, false
, or nil
), or
return an array, hash, regexp or range that only contains one of
the above basic literal values.
With IgnoreConstantBranches: true
, branches are not registered
as offenses if they return a constant value.
Example:
# bad
if foo
do_foo
do_something_else
elsif bar
do_foo
do_something_else
end
# good
if foo || bar
do_foo
do_something_else
end
# bad
case x
when foo
do_foo
when bar
do_foo
else
do_something_else
end
# good
case x
when foo, bar
do_foo
else
do_something_else
end
# bad
begin
do_something
rescue FooError
handle_error
rescue BarError
handle_error
end
# good
begin
do_something
rescue FooError, BarError
handle_error
end
Example: IgnoreLiteralBranches: true
# good
case size
when "small" then 100
when "medium" then 250
when "large" then 1000
else 250
end
Example: IgnoreConstantBranches: true
# good
case size
when "small" then SMALL_SIZE
when "medium" then MEDIUM_SIZE
when "large" then LARGE_SIZE
else MEDIUM_SIZE
end
Remove redundant sort
. Open
Dir.glob(SCRIPT_DIR.join("*")).sort.each do |f|
- Read upRead up
- Create a ticketCreate a ticket
- Exclude checks
Sort globbed results by default in Ruby 3.0.
This cop checks for redundant sort
method to Dir.glob
and Dir[]
.
Safety:
This cop is unsafe, in case of having a file and a directory with
identical names, since directory will be loaded before the file, which
will break exe/files.rb
that rely on exe.rb
file.
Example:
# bad
Dir.glob('./lib/**/*.rb').sort.each do |file|
end
Dir['./lib/**/*.rb'].sort.each do |file|
end
# good
Dir.glob('./lib/**/*.rb').each do |file|
end
Dir['./lib/**/*.rb'].each do |file|
end
Avoid immutable Array literals in loops. It is better to extract it into a local variable or a constant. Open
next if %w[name namespace].include?(cname)
- Create a ticketCreate a ticket
- Exclude checks
Use filter_map
instead. Open
ae_values_sorted.collect(&:to_export_yaml).compact
- Create a ticketCreate a ticket
- Exclude checks
Interpolation in single quoted string detected. Use double quoted strings if you need interpolation. Open
{:name => "realtime_performance", :description => N_("Real Time Performance"), :db => (dbs = ["Vm", "Host", "EmsCluster"]), :responds_to_events => '#{db.underscore}_perf_complete',
- Read upRead up
- Create a ticketCreate a ticket
- Exclude checks
Checks for interpolation in a single quoted string.
Safety:
This cop's autocorrection is unsafe because although it always replaces single quotes as
if it were miswritten double quotes, it is not always the case. For example,
'#{foo} bar'
would be replaced by "#{foo} bar"
, so the replaced code would evaluate
the expression foo
.
Example:
# bad
foo = 'something with #{interpolation} inside'
Example:
# good
foo = "something with #{interpolation} inside"
Argument inputs
was shadowed by a local variable before it was used. Open
inputs = {
:miq_alert_description => description,
:miq_alert_id => id,
:alert_guid => guid,
'EventStream::event_stream' => event_obj.id,
- Read upRead up
- Create a ticketCreate a ticket
- Exclude checks
Checks for shadowed arguments.
This cop has IgnoreImplicitReferences
configuration option.
It means argument shadowing is used in order to pass parameters
to zero arity super
when IgnoreImplicitReferences
is true
.
Example:
# bad
do_something do |foo|
foo = 42
puts foo
end
def do_something(foo)
foo = 42
puts foo
end
# good
do_something do |foo|
foo = foo + 42
puts foo
end
def do_something(foo)
foo = foo + 42
puts foo
end
def do_something(foo)
puts foo
end
Example: IgnoreImplicitReferences: false (default)
# bad
def do_something(foo)
foo = 42
super
end
def do_something(foo)
foo = super
bar
end
Example: IgnoreImplicitReferences: true
# good
def do_something(foo)
foo = 42
super
end
def do_something(foo)
foo = super
bar
end
Prefer using YAML.safe_load
over YAML.load
. Open
input = YAML.load(fd)
- Read upRead up
- Create a ticketCreate a ticket
- Exclude checks
Checks for the use of YAML class methods which have potential security issues leading to remote code execution when loading from an untrusted source.
NOTE: Ruby 3.1+ (Psych 4) uses Psych.load
as Psych.safe_load
by default.
Safety:
The behavior of the code might change depending on what was
in the YAML payload, since YAML.safe_load
is more restrictive.
Example:
# bad
YAML.load("--- !ruby/object:Foo {}") # Psych 3 is unsafe by default
# good
YAML.safe_load("--- !ruby/object:Foo {}", [Foo]) # Ruby 2.5 (Psych 3)
YAML.safe_load("--- !ruby/object:Foo {}", permitted_classes: [Foo]) # Ruby 3.0- (Psych 3)
YAML.load("--- !ruby/object:Foo {}", permitted_classes: [Foo]) # Ruby 3.1+ (Psych 4)
YAML.dump(foo)
Remove redundant sort
. Open
Dir.glob(plugin.root.join("content/miq_dialogs/*.{yml,yaml}")).sort
- Read upRead up
- Create a ticketCreate a ticket
- Exclude checks
Sort globbed results by default in Ruby 3.0.
This cop checks for redundant sort
method to Dir.glob
and Dir[]
.
Safety:
This cop is unsafe, in case of having a file and a directory with
identical names, since directory will be loaded before the file, which
will break exe/files.rb
that rely on exe.rb
file.
Example:
# bad
Dir.glob('./lib/**/*.rb').sort.each do |file|
end
Dir['./lib/**/*.rb'].sort.each do |file|
end
# good
Dir.glob('./lib/**/*.rb').each do |file|
end
Dir['./lib/**/*.rb'].each do |file|
end
Avoid immutable Array literals in loops. It is better to extract it into a local variable or a constant. Open
sql_col = Arel::Nodes::NamedFunction.new('LOWER', [sql_col]) if [:string, :text].include?(sql_type)
- Create a ticketCreate a ticket
- Exclude checks
Avoid more than 3 levels of block nesting. Open
if method == "description"
subst = "Policy: #{inputs[:policy].description}" if inputs[:policy].kind_of?(MiqPolicy)
subst = "Alert: #{inputs[:policy].description}" if inputs[:policy].kind_of?(MiqAlert)
end
- Read upRead up
- Create a ticketCreate a ticket
- Exclude checks
Checks for excessive nesting of conditional and looping constructs.
You can configure if blocks are considered using the CountBlocks
option. When set to false
(the default) blocks are not counted
towards the nesting level. Set to true
to count blocks as well.
The maximum level of nesting allowed is configurable.