ManageIQ/manageiq

View on GitHub

Showing 1,314 of 1,314 total issues

Avoid more than 3 levels of block nesting.
Open

              tags2desc[tag] = entry.nil? ? tag.titleize : entry.description
Severity: Minor
Found in app/models/miq_report/generator.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.

Use filter_map instead.
Open

    class_array = user.current_tenant.visible_domains.pluck(:name).collect do |domain|
      fq_ns = domain + "/" + partial_ns
      ae_ns = MiqAeNamespace.lookup_by_fqname(fq_ns)
      next if ae_ns.nil?

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

Prefer using YAML.safe_load over YAML.load.
Open

    YAML.load(data)
Severity: Minor
Found in app/models/miq_ae_method.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)

Interpolation in single quoted string detected. Use double quoted strings if you need interpolation.
Open

      {:name => "ems_alarm", :description => N_("VMware Alarm"), :db => ["Vm", "Host", "EmsCluster"], :responds_to_events => 'AlarmStatusChangedEvent_#{hash_expression[:options][:ems_id]}_#{hash_expression[:options][:ems_alarm_mor]}',
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"

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

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)

Use filter_map instead.
Open

    miq_policy_contents.collect(&:miq_event_definition).compact.uniq
Severity: Minor
Found in app/models/miq_policy.rb by rubocop

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)
Severity: Minor
Found in app/models/miq_report/search.rb by rubocop

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_class.rb by rubocop

Interpolation in single quoted string detected. Use double quoted strings if you need interpolation.
Open

      {:name => "event_threshold", :description => N_("Event Threshold"), :db => ["Vm"], :responds_to_events => '#{hash_expression[:options][:event_types]}',
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"

Do not suppress exceptions.
Open

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

Checks for rescue blocks with no body.

Example:

# bad
def some_method
  do_something
rescue
end

# bad
begin
  do_something
rescue
end

# good
def some_method
  do_something
rescue
  handle_exception
end

# good
begin
  do_something
rescue
  handle_exception
end

Example: AllowComments: true (default)

# good
def some_method
  do_something
rescue
  # do nothing
end

# good
begin
  do_something
rescue
  # do nothing
end

Example: AllowComments: false

# bad
def some_method
  do_something
rescue
  # do nothing
end

# bad
begin
  do_something
rescue
  # do nothing
end

Example: AllowNil: true (default)

# good
def some_method
  do_something
rescue
  nil
end

# good
begin
  do_something
rescue
  # do nothing
end

# good
do_something rescue nil

Example: AllowNil: false

# bad
def some_method
  do_something
rescue
  nil
end

# bad
begin
  do_something
rescue
  nil
end

# bad
do_something rescue nil

Use filter_map instead.
Open

    miq_policy_contents.collect(&:miq_action).compact.uniq
Severity: Minor
Found in app/models/miq_policy.rb by rubocop

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

        ["qualifier", "success_sequence", "failure_sequence", "success_synchronous", "failure_synchronous"].each do |k|

Avoid using Marshal.load.
Open

    msg_data && Marshal.load(msg_data)
Severity: Minor
Found in app/models/miq_queue.rb by rubocop

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

Use filter_map instead.
Open

    Array(sorting_columns).collect do |attr|
      if cols_for_report.include?(attr)
        attr
      else
        raise ArgumentError, N_("%{attribute} is not a valid attribute for %{name}") % {:attribute => attr, :name => name}
Severity: Minor
Found in app/models/miq_report.rb by rubocop

Use all?(0) instead of block.
Open

    return if arr.all? { |a| a == 0 }
Severity: Minor
Found in app/models/miq_report/formatting.rb by rubocop

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

        if ["y", "c"].include?(group) && !sortby.nil? && save_val != d.data[sortby[0]].to_s

Remove redundant sort.
Open

    Dir.glob(SCRIPT_DIR.join("*")).sort.each do |f|
Severity: Minor
Found in app/models/miq_action.rb by rubocop

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[id created_on updated_on updated_by].include?(cname) || cname.ends_with?("_id")
Severity: Minor
Found in app/models/miq_ae_field.rb by rubocop
Severity
Category
Status
Source
Language