ManageIQ/manageiq-gems-pending

View on GitHub
lib/gems/pending/util/require_with_logging.rb

Summary

Maintainability
A
1 hr
Test Coverage

Method require has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
Open

    def require(path) # :doc:
      with_require_logging(path) { gem_original_require(path) }
    rescue LoadError => load_error
      if load_error.message =~ /#{Regexp.escape path}\z/ &&
         spec = Gem.searcher.find(path)
Severity: Minor
Found in lib/gems/pending/util/require_with_logging.rb - About 35 mins to fix

Cognitive Complexity

Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

A method's cognitive complexity is based on a few simple rules:

  • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
  • Code is considered more complex for each "break in the linear flow of the code"
  • Code is considered more complex when "flow breaking structures are nested"

Further reading

Method require has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
Open

    def require(path) # :doc:
      with_require_logging(path) { gem_original_require(path) }
    rescue LoadError => load_error
      if load_error.message.end_with?(path) && Gem.try_activate(path)
        return with_require_logging(path, :reenter) { gem_original_require(path) }
Severity: Minor
Found in lib/gems/pending/util/require_with_logging.rb - About 25 mins to fix

Cognitive Complexity

Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

A method's cognitive complexity is based on a few simple rules:

  • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
  • Code is considered more complex for each "break in the linear flow of the code"
  • Code is considered more complex when "flow breaking structures are nested"

Further reading

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

         spec = Gem.searcher.find(path)

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 rescuing the Exception class. Perhaps you meant to rescue StandardError?
Open

    rescue Exception
      log_require(path, :fail, Time.now - t) rescue nil
      raise

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

There are no issues that match your filters.

Category
Status