ManageIQ/manageiq

View on GitHub

Showing 1,430 of 1,430 total issues

Avoid more than 3 levels of block nesting.
Open

            attrs[:mem_usage_absolute_average] = 100.0 / total_mem * attrs[:derived_memory_used] if total_mem > 0 && !attrs[:derived_memory_used].nil?
Severity: Minor
Found in app/models/metric/processing.rb by rubocop

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}\"")
Severity: Minor
Found in app/models/miq_alert.rb by rubocop

Checks for the use of Kernel#eval and Binding#eval.

Example:

# bad

eval(something)
binding.eval(something)

Avoid immutable Array literals in loops. It is better to extract it into a local variable or a constant.
Open

        next(hh) if ["timestamp", "v_date", "v_time", "resource_name"].include?(col)
Severity: Minor
Found in app/models/miq_alert.rb by rubocop

Duplicate branch body detected.
Open

    when ManageIQ::Providers::Kubernetes::ContainerManager::ContainerNode then true

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

Use filter_map instead.
Open

      cls.ae_instances.sort_by(&:fqname).collect do |inst|
        next if name_set.include?(inst.name)
        name_set << inst.name
        inst
      end.compact.flatten
Severity: Minor
Found in app/models/miq_ae_class.rb by rubocop

Use filter_map instead.
Open

    ae_values_sorted.collect(&:to_export_yaml).compact
Severity: Minor
Found in app/models/miq_ae_instance.rb by rubocop

Prefer using YAML.safe_load over YAML.load.
Open

    input = YAML.load(fd)
Severity: Minor
Found in app/models/miq_alert.rb by rubocop

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)

Use filter_map instead.
Open

    results = current.collect do |c|
      return [] unless c.respond_to?(attr)
      c.send(attr)
    end.compact
Severity: Minor
Found in app/models/miq_bulk_import.rb by rubocop

Use inputs['MiqEvent::miq_event'] = event_obj.id; inputs[:miq_event_id] = event_obj.id instead of inputs.merge!('MiqEvent::miq_event' => event_obj.id, :miq_event_id => event_obj.id).
Open

    inputs.merge!('MiqEvent::miq_event' => event_obj.id, :miq_event_id => event_obj.id)
Severity: Minor
Found in app/models/miq_event.rb by rubocop

This cop identifies places where Hash#merge! can be replaced by Hash#[]=.

Example:

hash.merge!(a: 1)
hash.merge!({'key' => 'value'})
hash.merge!(a: 1, b: 2)

Prefer using YAML.safe_load over YAML.load.
Open

        eventData = YAML.load(row.attributes["event_data"])
Severity: Minor
Found in app/models/miq_event_definition.rb by rubocop

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)

Duplicate branch body detected.
Open

    when Service then true

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

Avoid immutable Array literals in loops. It is better to extract it into a local variable or a constant.
Open

      [:on, :off].each do |mode|
Severity: Minor
Found in app/models/metric/rollup.rb by rubocop

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',
Severity: Minor
Found in app/models/miq_alert.rb by rubocop

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"

Use filter_map instead.
Open

    verified_tags = tags.collect { |t| t if header.include?(t) }.compact
Severity: Minor
Found in app/models/miq_bulk_import.rb by rubocop

Use filter_map instead.
Open

        @results.each_value { |result| columns.concat(result[section].collect { |k, v| k if k.to_s[0, 1] != '_' && v[:_value_] }.compact) }
Severity: Minor
Found in app/models/miq_compare.rb by rubocop

Use filter_map instead.
Open

      policy.conditions.collect do |c|
        rec_model = rec.class.base_model.name
        rec_model = "Vm" if rec_model.downcase.match("template")
        next unless rec_model == c["towhat"]

Severity: Minor
Found in app/models/miq_policy.rb by rubocop

Use filter_map instead.
Open

      @values[:src_vm_lans] = vm.lans.collect(&:name).compact

Use filter_map instead.
Open

      spec_hash[:wins_servers] = [adapter['primaryWINS'], adapter['secondaryWINS']].collect { |s| s unless s.blank? }.compact.join(', ')

Variable ScanItem used in void context.
Open

    ScanItem  # Cause the ScanItemSet class to load, if not already loaded
Severity: Minor
Found in app/models/miq_action.rb by rubocop

Checks for operators, variables, literals, lambda, proc and nonmutating methods used in void context.

Example: CheckForMethodsWithNoSideEffects: false (default)

# bad
def some_method
  some_num * 10
  do_something
end

def some_method(some_var)
  some_var
  do_something
end

Example: CheckForMethodsWithNoSideEffects: true

# bad
def some_method(some_array)
  some_array.sort
  do_something(some_array)
end

# good
def some_method
  do_something
  some_num * 10
end

def some_method(some_var)
  do_something
  some_var
end

def some_method(some_array)
  some_array.sort!
  do_something(some_array)
end

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")
Severity: Minor
Found in app/models/miq_ae_method.rb by rubocop
Severity
Category
Status
Source
Language