ManageIQ/manageiq

View on GitHub

Showing 1,313 of 1,313 total issues

Avoid rescuing the Exception class. Perhaps you meant to rescue StandardError?
Open

      rescue Exception => err
        do_exit("An error has occurred during work processing: #{err}\n#{err.backtrace.join("\n")}", 1)
Severity: Minor
Found in app/models/miq_worker/runner.rb by rubocop

Checks for rescue blocks targeting the Exception class.

Example:

# bad

begin
  do_something
rescue Exception
  handle_exception
end

Example:

# good

begin
  do_something
rescue ArgumentError
  handle_exception
end

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

      name = obj.send([:name, :description, :object_id].detect { |m| obj.respond_to?(m) })
Severity: Minor
Found in app/models/relationship.rb by rubocop

Avoid more than 3 levels of block nesting.
Open

            if f[:values].present?
              sorted_values = f[:values].sort
              selected_key = sorted_values.first.first
            end
Severity: Minor
Found in app/models/miq_request_workflow.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

    build_id_to_name_hash(sources.collect { |rp| find_cluster_above_ci(rp) }.compact)
Severity: Minor
Found in app/models/miq_request_workflow.rb by rubocop

Use String#include? instead of a regex match with literal-only pattern.
Open

        value = /array_/.match?(fld[:data_type]) ? values[f] : get_value(values[f])
Severity: Minor
Found in app/models/miq_request_workflow.rb by rubocop

Avoid rescuing the Exception class. Perhaps you meant to rescue StandardError?
Open

    rescue Exception => err
      _log.error(err.to_s)
      _log.log_backtrace(err, :debug)
      job.signal(:abort_retry, err.to_s, "error", true)
      nil

Checks for rescue blocks targeting the Exception class.

Example:

# bad

begin
  do_something
rescue Exception
  handle_exception
end

Example:

# good

begin
  do_something
rescue ArgumentError
  handle_exception
end

Ensure you correctly provided all the arguments.
Open

    return enum_for(:each_group_resource) unless block
Severity: Minor
Found in app/models/mixins/service_mixin.rb by rubocop

Ensures that to_enum/enum_for, called for the current method, has correct arguments.

Example:

# bad
def foo(x, y = 1)
  return to_enum(__callee__, x) # `y` is missing
end

# good
def foo(x, y = 1)
  # Alternatives to `__callee__` are `__method__` and `:foo`.
  return to_enum(__callee__, x, y)
end

# good
def foo(x, y = 1)
  # It is also allowed if it is wrapped in some method like Sorbet.
  return to_enum(T.must(__callee__), x, y)
end

Use sum { ... } instead of collect { ... }.sum.
Open

    service_resources.collect(&:group_idx).uniq.collect { |idx| max_group_delay(idx, delay_type(action)) }.sum
Severity: Minor
Found in app/models/mixins/service_mixin.rb by rubocop

private (on line 183) does not make singleton methods private. Use private_class_method or private inside a class << self block instead.
Open

  def self.with_universal_newline(text)

Checks for private or protected access modifiers which are applied to a singleton method. These access modifiers do not make singleton methods private/protected. private_class_method can be used for that.

Example:

# bad

class C
  private

  def self.method
    puts 'hi'
  end
end

Example:

# good

class C
  def self.method
    puts 'hi'
  end

  private_class_method :method
end

Example:

# good

class C
  class << self
    private

    def method
      puts 'hi'
    end
  end
end

Use String#include? instead of a regex match with literal-only pattern.
Open

    raise unless e.message =~ /could not connect to publisher/ || e.message =~ /replication slot .* does not exist/

Use filter_map instead.
Open

    contents.collect { |c| c.resource if c.resource.kind_of?(MiqAction) }.compact
Severity: Minor
Found in app/models/policy_event.rb by rubocop

Wrap complex range boundaries with parentheses to avoid ambiguity.
Open

          params[attr['dialog_param_'.size..-1]] = val

Checks for ambiguous ranges.

Ranges have quite low precedence, which leads to unexpected behavior when using a range with other operators. This cop avoids that by making ranges explicit by requiring parenthesis around complex range boundaries (anything that is not a literal: numerics, strings, symbols, etc.).

This cop can be configured with RequireParenthesesForMethodChains in order to specify whether method chains (including self.foo) should be wrapped in parens by this cop.

NOTE: Regardless of this configuration, if a method receiver is a basic literal value, it will be wrapped in order to prevent the ambiguity of 1..2.to_a.

Safety:

The cop autocorrects by wrapping the entire boundary in parentheses, which makes the outcome more explicit but is possible to not be the intention of the programmer. For this reason, this cop's autocorrect is unsafe (it will not change the behavior of the code, but will not necessarily match the intent of the program).

Example:

# bad
x || 1..2
(x || 1..2)
1..2.to_a

# good, unambiguous
1..2
'a'..'z'
:bar..:baz
MyClass::MIN..MyClass::MAX
@min..@max
a..b
-a..b

# good, ambiguity removed
x || (1..2)
(x || 1)..2
(x || 1)..(y || 2)
(1..2).to_a

Example: RequireParenthesesForMethodChains: false (default)

# good
a.foo..b.bar
(a.foo)..(b.bar)

Example: RequireParenthesesForMethodChains: true

# bad
a.foo..b.bar

# good
(a.foo)..(b.bar)

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

    hdr << "@page{@bottom-center{font-size: 75%;content: '" + _("Report date: %{report_date}") % {:report_date => run_date} + "'}}"
Severity: Minor
Found in app/models/miq_report_result.rb by rubocop

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 more than 3 levels of block nesting.
Open

              unless fld[:error].nil?
                valid = false
                next
              end
Severity: Minor
Found in app/models/miq_request_workflow.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

    datacenters = sources.collect do |h|
      rails_logger("host_to_folder for host #{h.name}", 0)
      result = find_datacenter_for_ci(h)
      rails_logger("host_to_folder for host #{h.name}", 1)
      result
Severity: Minor
Found in app/models/miq_request_workflow.rb by rubocop

Avoid rescuing the Exception class. Perhaps you meant to rescue StandardError?
Open

    rescue Exception => e
      safe_log("Error in releasing database connection: #{e.message}", :error)
Severity: Minor
Found in app/models/miq_worker/runner.rb by rubocop

Checks for rescue blocks targeting the Exception class.

Example:

# bad

begin
  do_something
rescue Exception
  handle_exception
end

Example:

# good

begin
  do_something
rescue ArgumentError
  handle_exception
end

Use filter_map instead.
Open

    requests.collect { |request| request unless request.id == skip_id }.compact

Prefer using YAML.safe_load over YAML.load.
Open

        reps = YAML.load(fd.read)

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

    find_all_ems_of_type(Host).collect { |h| h if host_ids.include?(h.id) }.compact
Severity: Minor
Found in app/models/miq_request_workflow.rb by rubocop

Use filter_map instead.
Open

    missing_categories_names = missing_tags.collect do |category|
      begin
        Classification.lookup_by_name(category.to_s).description
      rescue StandardError
        nil
Severity
Category
Status
Source
Language