ManageIQ/manageiq

View on GitHub

Showing 1,311 of 1,311 total issues

Use filter_map instead.
Open

    policies.collect do |p|
      next if event && !p.events.include?(event)

      policy_hash = {"result" => "N/A", "conditions" => [], "actions" => []}
      policy_hash["scope"] = MiqExpression.evaluate_atoms(p.expression, rec) unless p.expression.nil?
Severity: Minor
Found in app/models/miq_policy.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

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.

Avoid when branches without a body.
Open

        when :total, :count, :min, :max

Checks for the presence of when branches without a body.

Example:

# bad
case foo
when bar
  do_something
when baz
end

Example:

# good
case condition
when foo
  do_something
when bar
  nil
end

Example: AllowComments: true (default)

# good
case condition
when foo
  do_something
when bar
  # noop
end

Example: AllowComments: false

# bad
case condition
when foo
  do_something
when bar
  # do nothing
end

Use == if you meant to do a comparison or wrap the expression in parentheses to indicate you meant to assign in a condition.
Open

        if clickable_rows && onclick = build_row_onclick(d.data)

Checks for assignments in the conditions of if/while/until.

AllowSafeAssignment option for safe assignment. By safe assignment we mean putting parentheses around an assignment to indicate "I know I'm using an assignment as a condition. It's not a mistake."

Safety:

This cop's autocorrection is unsafe because it assumes that the author meant to use an assignment result as a condition.

Example:

# bad
if some_var = true
  do_something
end

# good
if some_var == true
  do_something
end

Example: AllowSafeAssignment: true (default)

# good
if (some_var = true)
  do_something
end

Example: AllowSafeAssignment: false

# bad
if (some_var = true)
  do_something
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 value].include?(cname)
Severity: Minor
Found in app/models/miq_ae_value.rb by rubocop

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

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|

Wrap expressions with varying precedence with parentheses to avoid ambiguity.
Open

    alignment_style = if db == 'Tenant' && TenantQuota.can_format_field?(col_name, row_data['tenant_quotas.name']) || row_data[col_name].kind_of?(Integer) || row_data[col_name].kind_of?(Float)

Looks for expressions containing multiple binary operators where precedence is ambiguous due to lack of parentheses. For example, in 1 + 2 * 3, the multiplication will happen before the addition, but lexically it appears that the addition will happen first.

The cop does not consider unary operators (ie. !a or -b) or comparison operators (ie. a =~ b) because those are not ambiguous.

NOTE: Ranges are handled by Lint/AmbiguousRange.

Example:

# bad
a + b * c
a || b && c
a ** b + c

# good (different precedence)
a + (b * c)
a || (b && c)
(a ** b) + c

# good (same precedence)
a + b + c
a * b / c % d

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

Use filter_map instead.
Open

  ROLLUP_COLS  = Metric.columns_hash.collect { |c, h| c.to_sym if h.type == :float || c[0, 7] == "derived" }.compact +
Severity: Minor
Found in app/models/metric/rollup.rb by rubocop

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

Use filter_map instead.
Open

    klass_array.collect do |klass|
      cls = find_by(:id => klass.id)
      next if cls.nil?

      cls.ae_instances.select { |a| File.fnmatch(instance, a.name, File::FNM_CASEFOLD) }
Severity: Minor
Found in app/models/miq_ae_class.rb by rubocop

Use filter_map instead.
Open

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

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

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

Prefer using YAML.safe_load over YAML.load.
Open

    input = YAML.load(fd)
Severity: Minor
Found in app/models/miq_policy_set.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 result["fields"] = "Specification"; result["file"] = "Sysprep Answer File" instead of result.merge!("fields" => "Specification", "file" => "Sysprep Answer File").
Open

    when 'windows' then result.merge!("fields" => "Specification", "file" => "Sysprep Answer File")

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 !String#include? instead of a regex match with literal-only pattern.
Open

      if col !~ /managed\./ && col !~ /virtual_custom/
Severity: Minor
Found in app/models/miq_report/generator.rb by rubocop

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
Severity
Category
Status
Source
Language