ManageIQ/manageiq-gems-pending

View on GitHub
lib/gems/pending/util/mount/miq_generic_mount_session.rb

Summary

Maintainability
D
2 days
Test Coverage
F
46%

Class MiqGenericMountSession has 45 methods (exceeds 20 allowed). Consider refactoring.
Open

class MiqGenericMountSession < MiqFileStorage::Interface
  class NoSuchFileOrDirectory < RuntimeError; end

  class << self
    def run_command(command, args)
Severity: Minor
Found in lib/gems/pending/util/mount/miq_generic_mount_session.rb - About 6 hrs to fix

File miq_generic_mount_session.rb has 397 lines of code (exceeds 250 allowed). Consider refactoring.
Open

require 'active_support/core_ext/object/blank'
require 'fileutils'
require 'logger'
require 'sys-uname'
require 'uri'
Severity: Minor
Found in lib/gems/pending/util/mount/miq_generic_mount_session.rb - About 5 hrs to fix

Method verify has 38 lines of code (exceeds 25 allowed). Consider refactoring.
Open

  def verify
    log_header = "MIQ(#{self.class.name}-verify)"
    logger.info("#{log_header} [#{@settings[:uri]}]...")
    res = true

Severity: Minor
Found in lib/gems/pending/util/mount/miq_generic_mount_session.rb - About 1 hr to fix

Method disconnect has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
Open

  def self.disconnect(mnt_point, logger = $log)
    return if mnt_point.nil?
    log_header = "MIQ(#{self.class.name}-disconnect)"
    logger.info("#{log_header} Disconnecting mount point: #{mnt_point}") if logger
    begin
Severity: Minor
Found in lib/gems/pending/util/mount/miq_generic_mount_session.rb - About 1 hr 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 remove has 29 lines of code (exceeds 25 allowed). Consider refactoring.
Open

  def remove(log_uri)
    log_header = "MIQ(#{self.class.name}-remove)"

    unless self.log_uri_still_configured?(log_uri)
      logger.info("#{log_header} Skipping remove because log URI: [#{log_uri}] does not originate from the currently configured base URI: [#{@settings[:uri]}]")
Severity: Minor
Found in lib/gems/pending/util/mount/miq_generic_mount_session.rb - About 1 hr to fix

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

  def pingable?
    log_header = "MIQ(#{self.class.name}-pingable?)"
    return true unless self.do_ping?
    return true unless @settings[:ports].kind_of?(Array)

Severity: Minor
Found in lib/gems/pending/util/mount/miq_generic_mount_session.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 log_uri_still_configured? has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
Open

  def log_uri_still_configured?(log_uri)
    # Only remove the log file if the current depot @settings are based on the same base URI as the log_uri to be removed
    return false if log_uri.nil? || @settings[:uri].nil?

    scheme, userinfo, host, port, registry, share, opaque, query, fragment = URI.split(URI::DEFAULT_PARSER.escape(@settings[:uri]))
Severity: Minor
Found in lib/gems/pending/util/mount/miq_generic_mount_session.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

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

  def connect
    log_header = "MIQ(#{self.class.name}-connect)"

    # Replace any encoded spaces back into spaces since the mount commands accepts quoted spaces
    @mount_path = @mount_path.to_s.gsub('%20', ' ')
Severity: Minor
Found in lib/gems/pending/util/mount/miq_generic_mount_session.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 @settings[:uri] = File.dirname(File.dirname(log_uri)) instead of @settings.merge!(:uri => File.dirname(File.dirname(log_uri))).
Open

      @settings.merge!(:uri => File.dirname(File.dirname(log_uri)))

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 match? instead of =~ when MatchData is not used.
Open

      unless err.message =~ /not found|mounted/

In Ruby 2.4, String#match?, Regexp#match? and Symbol#match? have been added. The methods are faster than match. Because the methods avoid creating a MatchData object or saving backref. So, when MatchData is not used, use match? instead of match.

Example:

# bad
def foo
  if x =~ /re/
    do_something
  end
end

# bad
def foo
  if x.match(/re/)
    do_something
  end
end

# bad
def foo
  if /re/ === x
    do_something
  end
end

# good
def foo
  if x.match?(/re/)
    do_something
  end
end

# good
def foo
  if x =~ /re/
    do_something(Regexp.last_match)
  end
end

# good
def foo
  if x.match(/re/)
    do_something($~)
  end
end

# good
def foo
  if /re/ === x
    do_something($~)
  end
end

Check block argument explicitly instead of using block_given?.
Open

    raise "requires a block" unless block_given?

Check block argument explicitly instead of using block_given?.
Open

    raise "No block provided!" unless block_given?

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

      if err.kind_of?(RuntimeError) && err.message =~ /No such file or directory/

Similar blocks of code found in 2 locations. Consider refactoring.
Open

    rescue => err
      msg = "Downloading [#{remote_file}] to [#{local_file}], failed due to error: '#{err.message}'"
      logger.error("#{log_header} #{msg}")
      raise
    ensure
Severity: Minor
Found in lib/gems/pending/util/mount/miq_generic_mount_session.rb and 1 other location - About 15 mins to fix
lib/gems/pending/util/mount/miq_generic_mount_session.rb on lines 366..370

Duplicated Code

Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

Tuning

This issue has a mass of 25.

We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

Refactorings

Further Reading

Similar blocks of code found in 2 locations. Consider refactoring.
Open

    rescue => err
      msg = "Deleting [#{relpath}] on [#{log_uri}], failed due to err '#{err.message}'"
      logger.error("#{log_header} #{msg}")
      raise
    ensure
Severity: Minor
Found in lib/gems/pending/util/mount/miq_generic_mount_session.rb and 1 other location - About 15 mins to fix
lib/gems/pending/util/mount/miq_generic_mount_session.rb on lines 308..312

Duplicated Code

Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

Tuning

This issue has a mass of 25.

We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

Refactorings

Further Reading

Useless assignment to variable - host. Use _ or _host as a variable name to indicate that it won't be used.
Open

    scheme, userinfo, host, port, registry, share, opaque, query, fragment = URI.split(URI::DEFAULT_PARSER.escape(uri))

Checks for every useless assignment to local variable in every scope. The basic idea for this cop was from the warning of ruby -cw:

assigned but unused variable - foo

Currently this cop has advanced logic that detects unreferenced reassignments and properly handles varied cases such as branch, loop, rescue, ensure, etc.

NOTE: Given the assignment foo = 1, bar = 2, removing unused variables can lead to a syntax error, so this case is not autocorrected.

Safety:

This cop's autocorrection is unsafe because removing assignment from operator assignment can cause NameError if this assignment has been used to declare local variable. For example, replacing a ||= 1 to a || 1 may cause "undefined local variable or method `a' for main:Object (NameError)".

Example:

# bad

def some_method
  some_var = 1
  do_something
end

Example:

# good

def some_method
  some_var = 1
  do_something(some_var)
end

Remove unnecessary existence check File.exist?.
Open

    FileUtils.rmdir(mnt_point) if File.exist?(mnt_point)

Checks for non-atomic file operation. And then replace it with a nearly equivalent and atomic method.

These can cause problems that are difficult to reproduce, especially in cases of frequent file operations in parallel, such as test runs with parallel_rspec.

For examples: creating a directory if there is none, has the following problems

An exception occurs when the directory didn't exist at the time of exist?, but someone else created it before mkdir was executed.

Subsequent processes are executed without the directory that should be there when the directory existed at the time of exist?, but someone else deleted it shortly afterwards.

Safety:

This cop is unsafe, because autocorrection change to atomic processing. The atomic processing of the replacement destination is not guaranteed to be strictly equivalent to that before the replacement.

Example:

# bad - race condition with another process may result in an error in `mkdir`
unless Dir.exist?(path)
  FileUtils.mkdir(path)
end

# good - atomic and idempotent creation
FileUtils.mkdir_p(path)

# bad - race condition with another process may result in an error in `remove`
if File.exist?(path)
  FileUtils.remove(path)
end

# good - atomic and idempotent removal
FileUtils.rm_f(path)

Useless assignment to variable - opaque. Use _ or _opaque as a variable name to indicate that it won't be used.
Open

    scheme, userinfo, host, port, registry, share, opaque, query, fragment = URI.split(URI::DEFAULT_PARSER.escape(uri))

Checks for every useless assignment to local variable in every scope. The basic idea for this cop was from the warning of ruby -cw:

assigned but unused variable - foo

Currently this cop has advanced logic that detects unreferenced reassignments and properly handles varied cases such as branch, loop, rescue, ensure, etc.

NOTE: Given the assignment foo = 1, bar = 2, removing unused variables can lead to a syntax error, so this case is not autocorrected.

Safety:

This cop's autocorrection is unsafe because removing assignment from operator assignment can cause NameError if this assignment has been used to declare local variable. For example, replacing a ||= 1 to a || 1 may cause "undefined local variable or method `a' for main:Object (NameError)".

Example:

# bad

def some_method
  some_var = 1
  do_something
end

Example:

# good

def some_method
  some_var = 1
  do_something(some_var)
end

Useless assignment to variable - fragment. Use _ or _fragment as a variable name to indicate that it won't be used.
Open

    scheme, userinfo, host, port, registry, share, opaque, query, fragment = URI.split(URI::DEFAULT_PARSER.escape(uri))

Checks for every useless assignment to local variable in every scope. The basic idea for this cop was from the warning of ruby -cw:

assigned but unused variable - foo

Currently this cop has advanced logic that detects unreferenced reassignments and properly handles varied cases such as branch, loop, rescue, ensure, etc.

NOTE: Given the assignment foo = 1, bar = 2, removing unused variables can lead to a syntax error, so this case is not autocorrected.

Safety:

This cop's autocorrection is unsafe because removing assignment from operator assignment can cause NameError if this assignment has been used to declare local variable. For example, replacing a ||= 1 to a || 1 may cause "undefined local variable or method `a' for main:Object (NameError)".

Example:

# bad

def some_method
  some_var = 1
  do_something
end

Example:

# good

def some_method
  some_var = 1
  do_something(some_var)
end

protected (on line 445) does not make singleton methods protected. Use protected inside a class << self block instead.
Open

  def self.raw_disconnect(mnt_point)

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

Useless assignment to variable - userinfo. Use _ or _userinfo as a variable name to indicate that it won't be used.
Open

    scheme, userinfo, host, port, registry, share, opaque, query, fragment = URI.split(URI::DEFAULT_PARSER.escape(@settings[:uri]))

Checks for every useless assignment to local variable in every scope. The basic idea for this cop was from the warning of ruby -cw:

assigned but unused variable - foo

Currently this cop has advanced logic that detects unreferenced reassignments and properly handles varied cases such as branch, loop, rescue, ensure, etc.

NOTE: Given the assignment foo = 1, bar = 2, removing unused variables can lead to a syntax error, so this case is not autocorrected.

Safety:

This cop's autocorrection is unsafe because removing assignment from operator assignment can cause NameError if this assignment has been used to declare local variable. For example, replacing a ||= 1 to a || 1 may cause "undefined local variable or method `a' for main:Object (NameError)".

Example:

# bad

def some_method
  some_var = 1
  do_something
end

Example:

# good

def some_method
  some_var = 1
  do_something(some_var)
end

Use atomic file operation method FileUtils.rm_f.
Open

    FileUtils.rmdir(mnt_point) if File.exist?(mnt_point)

Checks for non-atomic file operation. And then replace it with a nearly equivalent and atomic method.

These can cause problems that are difficult to reproduce, especially in cases of frequent file operations in parallel, such as test runs with parallel_rspec.

For examples: creating a directory if there is none, has the following problems

An exception occurs when the directory didn't exist at the time of exist?, but someone else created it before mkdir was executed.

Subsequent processes are executed without the directory that should be there when the directory existed at the time of exist?, but someone else deleted it shortly afterwards.

Safety:

This cop is unsafe, because autocorrection change to atomic processing. The atomic processing of the replacement destination is not guaranteed to be strictly equivalent to that before the replacement.

Example:

# bad - race condition with another process may result in an error in `mkdir`
unless Dir.exist?(path)
  FileUtils.mkdir(path)
end

# good - atomic and idempotent creation
FileUtils.mkdir_p(path)

# bad - race condition with another process may result in an error in `remove`
if File.exist?(path)
  FileUtils.remove(path)
end

# good - atomic and idempotent removal
FileUtils.rm_f(path)

Useless assignment to variable - share. Use _ or _share as a variable name to indicate that it won't be used.
Open

    scheme, userinfo, host, port, registry, share, opaque, query, fragment = URI.split(URI::DEFAULT_PARSER.escape(uri))

Checks for every useless assignment to local variable in every scope. The basic idea for this cop was from the warning of ruby -cw:

assigned but unused variable - foo

Currently this cop has advanced logic that detects unreferenced reassignments and properly handles varied cases such as branch, loop, rescue, ensure, etc.

NOTE: Given the assignment foo = 1, bar = 2, removing unused variables can lead to a syntax error, so this case is not autocorrected.

Safety:

This cop's autocorrection is unsafe because removing assignment from operator assignment can cause NameError if this assignment has been used to declare local variable. For example, replacing a ||= 1 to a || 1 may cause "undefined local variable or method `a' for main:Object (NameError)".

Example:

# bad

def some_method
  some_var = 1
  do_something
end

Example:

# good

def some_method
  some_var = 1
  do_something(some_var)
end

Useless assignment to variable - opts.
Open

      opts = ::VMDB::Config.new("vmdb").config[:log][:collection] if defined?(::VMDB) && defined?(::VMDB::CONFIG)

Checks for every useless assignment to local variable in every scope. The basic idea for this cop was from the warning of ruby -cw:

assigned but unused variable - foo

Currently this cop has advanced logic that detects unreferenced reassignments and properly handles varied cases such as branch, loop, rescue, ensure, etc.

NOTE: Given the assignment foo = 1, bar = 2, removing unused variables can lead to a syntax error, so this case is not autocorrected.

Safety:

This cop's autocorrection is unsafe because removing assignment from operator assignment can cause NameError if this assignment has been used to declare local variable. For example, replacing a ||= 1 to a || 1 may cause "undefined local variable or method `a' for main:Object (NameError)".

Example:

# bad

def some_method
  some_var = 1
  do_something
end

Example:

# good

def some_method
  some_var = 1
  do_something(some_var)
end

Useless assignment to variable - port. Use _ or _port as a variable name to indicate that it won't be used.
Open

    scheme, userinfo, host, port, registry, share, opaque, query, fragment = URI.split(URI::DEFAULT_PARSER.escape(@settings[:uri]))

Checks for every useless assignment to local variable in every scope. The basic idea for this cop was from the warning of ruby -cw:

assigned but unused variable - foo

Currently this cop has advanced logic that detects unreferenced reassignments and properly handles varied cases such as branch, loop, rescue, ensure, etc.

NOTE: Given the assignment foo = 1, bar = 2, removing unused variables can lead to a syntax error, so this case is not autocorrected.

Safety:

This cop's autocorrection is unsafe because removing assignment from operator assignment can cause NameError if this assignment has been used to declare local variable. For example, replacing a ||= 1 to a || 1 may cause "undefined local variable or method `a' for main:Object (NameError)".

Example:

# bad

def some_method
  some_var = 1
  do_something
end

Example:

# good

def some_method
  some_var = 1
  do_something(some_var)
end

Useless assignment to variable - query. Use _ or _query as a variable name to indicate that it won't be used.
Open

    scheme, userinfo, host, port, registry, share, opaque, query, fragment = URI.split(URI::DEFAULT_PARSER.escape(uri))

Checks for every useless assignment to local variable in every scope. The basic idea for this cop was from the warning of ruby -cw:

assigned but unused variable - foo

Currently this cop has advanced logic that detects unreferenced reassignments and properly handles varied cases such as branch, loop, rescue, ensure, etc.

NOTE: Given the assignment foo = 1, bar = 2, removing unused variables can lead to a syntax error, so this case is not autocorrected.

Safety:

This cop's autocorrection is unsafe because removing assignment from operator assignment can cause NameError if this assignment has been used to declare local variable. For example, replacing a ||= 1 to a || 1 may cause "undefined local variable or method `a' for main:Object (NameError)".

Example:

# bad

def some_method
  some_var = 1
  do_something
end

Example:

# good

def some_method
  some_var = 1
  do_something(some_var)
end

Useless assignment to variable - port. Use _ or _port as a variable name to indicate that it won't be used.
Open

    scheme, userinfo, host, port, registry, share, opaque, query, fragment = URI.split(URI::DEFAULT_PARSER.escape(uri))

Checks for every useless assignment to local variable in every scope. The basic idea for this cop was from the warning of ruby -cw:

assigned but unused variable - foo

Currently this cop has advanced logic that detects unreferenced reassignments and properly handles varied cases such as branch, loop, rescue, ensure, etc.

NOTE: Given the assignment foo = 1, bar = 2, removing unused variables can lead to a syntax error, so this case is not autocorrected.

Safety:

This cop's autocorrection is unsafe because removing assignment from operator assignment can cause NameError if this assignment has been used to declare local variable. For example, replacing a ||= 1 to a || 1 may cause "undefined local variable or method `a' for main:Object (NameError)".

Example:

# bad

def some_method
  some_var = 1
  do_something
end

Example:

# good

def some_method
  some_var = 1
  do_something(some_var)
end

Useless assignment to variable - registry. Use _ or _registry as a variable name to indicate that it won't be used.
Open

    scheme, userinfo, host, port, registry, share, opaque, query, fragment = URI.split(URI::DEFAULT_PARSER.escape(uri))

Checks for every useless assignment to local variable in every scope. The basic idea for this cop was from the warning of ruby -cw:

assigned but unused variable - foo

Currently this cop has advanced logic that detects unreferenced reassignments and properly handles varied cases such as branch, loop, rescue, ensure, etc.

NOTE: Given the assignment foo = 1, bar = 2, removing unused variables can lead to a syntax error, so this case is not autocorrected.

Safety:

This cop's autocorrection is unsafe because removing assignment from operator assignment can cause NameError if this assignment has been used to declare local variable. For example, replacing a ||= 1 to a || 1 may cause "undefined local variable or method `a' for main:Object (NameError)".

Example:

# bad

def some_method
  some_var = 1
  do_something
end

Example:

# good

def some_method
  some_var = 1
  do_something(some_var)
end

Useless assignment to variable - opaque. Use _ or _opaque as a variable name to indicate that it won't be used.
Open

    scheme, userinfo, host, port, registry, share, opaque, query, fragment = URI.split(URI::DEFAULT_PARSER.escape(@settings[:uri]))

Checks for every useless assignment to local variable in every scope. The basic idea for this cop was from the warning of ruby -cw:

assigned but unused variable - foo

Currently this cop has advanced logic that detects unreferenced reassignments and properly handles varied cases such as branch, loop, rescue, ensure, etc.

NOTE: Given the assignment foo = 1, bar = 2, removing unused variables can lead to a syntax error, so this case is not autocorrected.

Safety:

This cop's autocorrection is unsafe because removing assignment from operator assignment can cause NameError if this assignment has been used to declare local variable. For example, replacing a ||= 1 to a || 1 may cause "undefined local variable or method `a' for main:Object (NameError)".

Example:

# bad

def some_method
  some_var = 1
  do_something
end

Example:

# good

def some_method
  some_var = 1
  do_something(some_var)
end

Call super to initialize state of the parent class.
Open

  def initialize(log_settings)
    raise "URI missing" unless log_settings.key?(:uri)
    @settings  = log_settings.dup
    @mnt_point = nil
  end

Checks for the presence of constructors and lifecycle callbacks without calls to super.

This cop does not consider method_missing (and respond_to_missing?) because in some cases it makes sense to overtake what is considered a missing method. In other cases, the theoretical ideal handling could be challenging or verbose for no actual gain.

Autocorrection is not supported because the position of super cannot be determined automatically.

Object and BasicObject are allowed by this cop because of their stateless nature. However, sometimes you might want to allow other parent classes from this cop, for example in the case of an abstract class that is not meant to be called with super. In those cases, you can use the AllowedParentClasses option to specify which classes should be allowed in addition to Object and BasicObject.

Example:

# bad
class Employee < Person
  def initialize(name, salary)
    @salary = salary
  end
end

# good
class Employee < Person
  def initialize(name, salary)
    super(name)
    @salary = salary
  end
end

# bad
Employee = Class.new(Person) do
  def initialize(name, salary)
    @salary = salary
  end
end

# good
Employee = Class.new(Person) do
  def initialize(name, salary)
    super(name)
    @salary = salary
  end
end

# bad
class Parent
  def self.inherited(base)
    do_something
  end
end

# good
class Parent
  def self.inherited(base)
    super
    do_something
  end
end

# good
class ClassWithNoParent
  def initialize
    do_something
  end
end

Example: AllowedParentClasses: [MyAbstractClass]

# good
class MyConcreteClass < MyAbstractClass
  def initialize
    do_something
  end
end

Useless assignment to variable - userinfo. Use _ or _userinfo as a variable name to indicate that it won't be used.
Open

    scheme, userinfo, host, port, registry, share, opaque, query, fragment = URI.split(URI::DEFAULT_PARSER.escape(uri))

Checks for every useless assignment to local variable in every scope. The basic idea for this cop was from the warning of ruby -cw:

assigned but unused variable - foo

Currently this cop has advanced logic that detects unreferenced reassignments and properly handles varied cases such as branch, loop, rescue, ensure, etc.

NOTE: Given the assignment foo = 1, bar = 2, removing unused variables can lead to a syntax error, so this case is not autocorrected.

Safety:

This cop's autocorrection is unsafe because removing assignment from operator assignment can cause NameError if this assignment has been used to declare local variable. For example, replacing a ||= 1 to a || 1 may cause "undefined local variable or method `a' for main:Object (NameError)".

Example:

# bad

def some_method
  some_var = 1
  do_something
end

Example:

# good

def some_method
  some_var = 1
  do_something(some_var)
end

Useless assignment to variable - registry. Use _ or _registry as a variable name to indicate that it won't be used.
Open

    scheme, userinfo, host, port, registry, share, opaque, query, fragment = URI.split(URI::DEFAULT_PARSER.escape(@settings[:uri]))

Checks for every useless assignment to local variable in every scope. The basic idea for this cop was from the warning of ruby -cw:

assigned but unused variable - foo

Currently this cop has advanced logic that detects unreferenced reassignments and properly handles varied cases such as branch, loop, rescue, ensure, etc.

NOTE: Given the assignment foo = 1, bar = 2, removing unused variables can lead to a syntax error, so this case is not autocorrected.

Safety:

This cop's autocorrection is unsafe because removing assignment from operator assignment can cause NameError if this assignment has been used to declare local variable. For example, replacing a ||= 1 to a || 1 may cause "undefined local variable or method `a' for main:Object (NameError)".

Example:

# bad

def some_method
  some_var = 1
  do_something
end

Example:

# good

def some_method
  some_var = 1
  do_something(some_var)
end

Useless assignment to variable - fragment_log. Use _ or _fragment_log as a variable name to indicate that it won't be used.
Open

    scheme_log, userinfo_log, host_log, port_log, registry_log, share_log, opaque_log, query_log, fragment_log = URI.split(URI::DEFAULT_PARSER.escape(log_uri))

Checks for every useless assignment to local variable in every scope. The basic idea for this cop was from the warning of ruby -cw:

assigned but unused variable - foo

Currently this cop has advanced logic that detects unreferenced reassignments and properly handles varied cases such as branch, loop, rescue, ensure, etc.

NOTE: Given the assignment foo = 1, bar = 2, removing unused variables can lead to a syntax error, so this case is not autocorrected.

Safety:

This cop's autocorrection is unsafe because removing assignment from operator assignment can cause NameError if this assignment has been used to declare local variable. For example, replacing a ||= 1 to a || 1 may cause "undefined local variable or method `a' for main:Object (NameError)".

Example:

# bad

def some_method
  some_var = 1
  do_something
end

Example:

# good

def some_method
  some_var = 1
  do_something(some_var)
end

Useless assignment to variable - fragment. Use _ or _fragment as a variable name to indicate that it won't be used.
Open

    scheme, userinfo, host, port, registry, share, opaque, query, fragment = URI.split(URI::DEFAULT_PARSER.escape(@settings[:uri]))

Checks for every useless assignment to local variable in every scope. The basic idea for this cop was from the warning of ruby -cw:

assigned but unused variable - foo

Currently this cop has advanced logic that detects unreferenced reassignments and properly handles varied cases such as branch, loop, rescue, ensure, etc.

NOTE: Given the assignment foo = 1, bar = 2, removing unused variables can lead to a syntax error, so this case is not autocorrected.

Safety:

This cop's autocorrection is unsafe because removing assignment from operator assignment can cause NameError if this assignment has been used to declare local variable. For example, replacing a ||= 1 to a || 1 may cause "undefined local variable or method `a' for main:Object (NameError)".

Example:

# bad

def some_method
  some_var = 1
  do_something
end

Example:

# good

def some_method
  some_var = 1
  do_something(some_var)
end

Useless assignment to variable - port_log. Use _ or _port_log as a variable name to indicate that it won't be used.
Open

    scheme_log, userinfo_log, host_log, port_log, registry_log, share_log, opaque_log, query_log, fragment_log = URI.split(URI::DEFAULT_PARSER.escape(log_uri))

Checks for every useless assignment to local variable in every scope. The basic idea for this cop was from the warning of ruby -cw:

assigned but unused variable - foo

Currently this cop has advanced logic that detects unreferenced reassignments and properly handles varied cases such as branch, loop, rescue, ensure, etc.

NOTE: Given the assignment foo = 1, bar = 2, removing unused variables can lead to a syntax error, so this case is not autocorrected.

Safety:

This cop's autocorrection is unsafe because removing assignment from operator assignment can cause NameError if this assignment has been used to declare local variable. For example, replacing a ||= 1 to a || 1 may cause "undefined local variable or method `a' for main:Object (NameError)".

Example:

# bad

def some_method
  some_var = 1
  do_something
end

Example:

# good

def some_method
  some_var = 1
  do_something(some_var)
end

Useless assignment to variable - query_log. Use _ or _query_log as a variable name to indicate that it won't be used.
Open

    scheme_log, userinfo_log, host_log, port_log, registry_log, share_log, opaque_log, query_log, fragment_log = URI.split(URI::DEFAULT_PARSER.escape(log_uri))

Checks for every useless assignment to local variable in every scope. The basic idea for this cop was from the warning of ruby -cw:

assigned but unused variable - foo

Currently this cop has advanced logic that detects unreferenced reassignments and properly handles varied cases such as branch, loop, rescue, ensure, etc.

NOTE: Given the assignment foo = 1, bar = 2, removing unused variables can lead to a syntax error, so this case is not autocorrected.

Safety:

This cop's autocorrection is unsafe because removing assignment from operator assignment can cause NameError if this assignment has been used to declare local variable. For example, replacing a ||= 1 to a || 1 may cause "undefined local variable or method `a' for main:Object (NameError)".

Example:

# bad

def some_method
  some_var = 1
  do_something
end

Example:

# good

def some_method
  some_var = 1
  do_something(some_var)
end

Useless assignment to variable - port. Use _ or _port as a variable name to indicate that it won't be used.
Open

    scheme, userinfo, host, port, registry, path, opaque, query, fragment = URI.split(URI::DEFAULT_PARSER.escape(uri))

Checks for every useless assignment to local variable in every scope. The basic idea for this cop was from the warning of ruby -cw:

assigned but unused variable - foo

Currently this cop has advanced logic that detects unreferenced reassignments and properly handles varied cases such as branch, loop, rescue, ensure, etc.

NOTE: Given the assignment foo = 1, bar = 2, removing unused variables can lead to a syntax error, so this case is not autocorrected.

Safety:

This cop's autocorrection is unsafe because removing assignment from operator assignment can cause NameError if this assignment has been used to declare local variable. For example, replacing a ||= 1 to a || 1 may cause "undefined local variable or method `a' for main:Object (NameError)".

Example:

# bad

def some_method
  some_var = 1
  do_something
end

Example:

# good

def some_method
  some_var = 1
  do_something(some_var)
end

Useless assignment to variable - err.
Open

    rescue NoSuchFileOrDirectory => err

Checks for every useless assignment to local variable in every scope. The basic idea for this cop was from the warning of ruby -cw:

assigned but unused variable - foo

Currently this cop has advanced logic that detects unreferenced reassignments and properly handles varied cases such as branch, loop, rescue, ensure, etc.

NOTE: Given the assignment foo = 1, bar = 2, removing unused variables can lead to a syntax error, so this case is not autocorrected.

Safety:

This cop's autocorrection is unsafe because removing assignment from operator assignment can cause NameError if this assignment has been used to declare local variable. For example, replacing a ||= 1 to a || 1 may cause "undefined local variable or method `a' for main:Object (NameError)".

Example:

# bad

def some_method
  some_var = 1
  do_something
end

Example:

# good

def some_method
  some_var = 1
  do_something(some_var)
end

Useless assignment to variable - registry. Use _ or _registry as a variable name to indicate that it won't be used.
Open

    scheme, userinfo, host, port, registry, path, opaque, query, fragment = URI.split(URI::DEFAULT_PARSER.escape(uri))

Checks for every useless assignment to local variable in every scope. The basic idea for this cop was from the warning of ruby -cw:

assigned but unused variable - foo

Currently this cop has advanced logic that detects unreferenced reassignments and properly handles varied cases such as branch, loop, rescue, ensure, etc.

NOTE: Given the assignment foo = 1, bar = 2, removing unused variables can lead to a syntax error, so this case is not autocorrected.

Safety:

This cop's autocorrection is unsafe because removing assignment from operator assignment can cause NameError if this assignment has been used to declare local variable. For example, replacing a ||= 1 to a || 1 may cause "undefined local variable or method `a' for main:Object (NameError)".

Example:

# bad

def some_method
  some_var = 1
  do_something
end

Example:

# good

def some_method
  some_var = 1
  do_something(some_var)
end

Useless assignment to variable - userinfo. Use _ or _userinfo as a variable name to indicate that it won't be used.
Open

    scheme, userinfo, host, port, registry, path, opaque, query, fragment = URI.split(URI::DEFAULT_PARSER.escape(uri))

Checks for every useless assignment to local variable in every scope. The basic idea for this cop was from the warning of ruby -cw:

assigned but unused variable - foo

Currently this cop has advanced logic that detects unreferenced reassignments and properly handles varied cases such as branch, loop, rescue, ensure, etc.

NOTE: Given the assignment foo = 1, bar = 2, removing unused variables can lead to a syntax error, so this case is not autocorrected.

Safety:

This cop's autocorrection is unsafe because removing assignment from operator assignment can cause NameError if this assignment has been used to declare local variable. For example, replacing a ||= 1 to a || 1 may cause "undefined local variable or method `a' for main:Object (NameError)".

Example:

# bad

def some_method
  some_var = 1
  do_something
end

Example:

# good

def some_method
  some_var = 1
  do_something(some_var)
end

Useless assignment to variable - opaque_log. Use _ or _opaque_log as a variable name to indicate that it won't be used.
Open

    scheme_log, userinfo_log, host_log, port_log, registry_log, share_log, opaque_log, query_log, fragment_log = URI.split(URI::DEFAULT_PARSER.escape(log_uri))

Checks for every useless assignment to local variable in every scope. The basic idea for this cop was from the warning of ruby -cw:

assigned but unused variable - foo

Currently this cop has advanced logic that detects unreferenced reassignments and properly handles varied cases such as branch, loop, rescue, ensure, etc.

NOTE: Given the assignment foo = 1, bar = 2, removing unused variables can lead to a syntax error, so this case is not autocorrected.

Safety:

This cop's autocorrection is unsafe because removing assignment from operator assignment can cause NameError if this assignment has been used to declare local variable. For example, replacing a ||= 1 to a || 1 may cause "undefined local variable or method `a' for main:Object (NameError)".

Example:

# bad

def some_method
  some_var = 1
  do_something
end

Example:

# good

def some_method
  some_var = 1
  do_something(some_var)
end

Useless assignment to variable - query. Use _ or _query as a variable name to indicate that it won't be used.
Open

    scheme, userinfo, host, port, registry, path, opaque, query, fragment = URI.split(URI::DEFAULT_PARSER.escape(uri))

Checks for every useless assignment to local variable in every scope. The basic idea for this cop was from the warning of ruby -cw:

assigned but unused variable - foo

Currently this cop has advanced logic that detects unreferenced reassignments and properly handles varied cases such as branch, loop, rescue, ensure, etc.

NOTE: Given the assignment foo = 1, bar = 2, removing unused variables can lead to a syntax error, so this case is not autocorrected.

Safety:

This cop's autocorrection is unsafe because removing assignment from operator assignment can cause NameError if this assignment has been used to declare local variable. For example, replacing a ||= 1 to a || 1 may cause "undefined local variable or method `a' for main:Object (NameError)".

Example:

# bad

def some_method
  some_var = 1
  do_something
end

Example:

# good

def some_method
  some_var = 1
  do_something(some_var)
end

The use of Kernel#open is a serious security risk.
Open

      open(file, "w") { |fd| fd.write(contents) }

Checks for the use of Kernel#open and URI.open with dynamic data.

Kernel#open and URI.open enable not only file access but also process invocation by prefixing a pipe symbol (e.g., open("| ls")). So, it may lead to a serious security risk by using variable input to the argument of Kernel#open and URI.open. It would be better to use File.open, IO.popen or URI.parse#open explicitly.

NOTE: open and URI.open with literal strings are not flagged by this cop.

Safety:

This cop could register false positives if open is redefined in a class and then used without a receiver in that class.

Example:

# bad
open(something)
open("| #{something}")
URI.open(something)

# good
File.open(something)
IO.popen(something)
URI.parse(something).open

# good (literal strings)
open("foo.text")
open("| foo")
URI.open("http://example.com")

Useless assignment to variable - query. Use _ or _query as a variable name to indicate that it won't be used.
Open

    scheme, userinfo, host, port, registry, share, opaque, query, fragment = URI.split(URI::DEFAULT_PARSER.escape(@settings[:uri]))

Checks for every useless assignment to local variable in every scope. The basic idea for this cop was from the warning of ruby -cw:

assigned but unused variable - foo

Currently this cop has advanced logic that detects unreferenced reassignments and properly handles varied cases such as branch, loop, rescue, ensure, etc.

NOTE: Given the assignment foo = 1, bar = 2, removing unused variables can lead to a syntax error, so this case is not autocorrected.

Safety:

This cop's autocorrection is unsafe because removing assignment from operator assignment can cause NameError if this assignment has been used to declare local variable. For example, replacing a ||= 1 to a || 1 may cause "undefined local variable or method `a' for main:Object (NameError)".

Example:

# bad

def some_method
  some_var = 1
  do_something
end

Example:

# good

def some_method
  some_var = 1
  do_something(some_var)
end

Useless assignment to variable - opaque. Use _ or _opaque as a variable name to indicate that it won't be used.
Open

    scheme, userinfo, host, port, registry, path, opaque, query, fragment = URI.split(URI::DEFAULT_PARSER.escape(uri))

Checks for every useless assignment to local variable in every scope. The basic idea for this cop was from the warning of ruby -cw:

assigned but unused variable - foo

Currently this cop has advanced logic that detects unreferenced reassignments and properly handles varied cases such as branch, loop, rescue, ensure, etc.

NOTE: Given the assignment foo = 1, bar = 2, removing unused variables can lead to a syntax error, so this case is not autocorrected.

Safety:

This cop's autocorrection is unsafe because removing assignment from operator assignment can cause NameError if this assignment has been used to declare local variable. For example, replacing a ||= 1 to a || 1 may cause "undefined local variable or method `a' for main:Object (NameError)".

Example:

# bad

def some_method
  some_var = 1
  do_something
end

Example:

# good

def some_method
  some_var = 1
  do_something(some_var)
end

Useless assignment to variable - scheme. Use _ or _scheme as a variable name to indicate that it won't be used.
Open

    scheme, userinfo, host, port, registry, path, opaque, query, fragment = URI.split(URI::DEFAULT_PARSER.escape(uri))

Checks for every useless assignment to local variable in every scope. The basic idea for this cop was from the warning of ruby -cw:

assigned but unused variable - foo

Currently this cop has advanced logic that detects unreferenced reassignments and properly handles varied cases such as branch, loop, rescue, ensure, etc.

NOTE: Given the assignment foo = 1, bar = 2, removing unused variables can lead to a syntax error, so this case is not autocorrected.

Safety:

This cop's autocorrection is unsafe because removing assignment from operator assignment can cause NameError if this assignment has been used to declare local variable. For example, replacing a ||= 1 to a || 1 may cause "undefined local variable or method `a' for main:Object (NameError)".

Example:

# bad

def some_method
  some_var = 1
  do_something
end

Example:

# good

def some_method
  some_var = 1
  do_something(some_var)
end

Useless assignment to variable - host. Use _ or _host as a variable name to indicate that it won't be used.
Open

    scheme, userinfo, host, port, registry, path, opaque, query, fragment = URI.split(URI::DEFAULT_PARSER.escape(uri))

Checks for every useless assignment to local variable in every scope. The basic idea for this cop was from the warning of ruby -cw:

assigned but unused variable - foo

Currently this cop has advanced logic that detects unreferenced reassignments and properly handles varied cases such as branch, loop, rescue, ensure, etc.

NOTE: Given the assignment foo = 1, bar = 2, removing unused variables can lead to a syntax error, so this case is not autocorrected.

Safety:

This cop's autocorrection is unsafe because removing assignment from operator assignment can cause NameError if this assignment has been used to declare local variable. For example, replacing a ||= 1 to a || 1 may cause "undefined local variable or method `a' for main:Object (NameError)".

Example:

# bad

def some_method
  some_var = 1
  do_something
end

Example:

# good

def some_method
  some_var = 1
  do_something(some_var)
end

Useless assignment to variable - registry_log. Use _ or _registry_log as a variable name to indicate that it won't be used.
Open

    scheme_log, userinfo_log, host_log, port_log, registry_log, share_log, opaque_log, query_log, fragment_log = URI.split(URI::DEFAULT_PARSER.escape(log_uri))

Checks for every useless assignment to local variable in every scope. The basic idea for this cop was from the warning of ruby -cw:

assigned but unused variable - foo

Currently this cop has advanced logic that detects unreferenced reassignments and properly handles varied cases such as branch, loop, rescue, ensure, etc.

NOTE: Given the assignment foo = 1, bar = 2, removing unused variables can lead to a syntax error, so this case is not autocorrected.

Safety:

This cop's autocorrection is unsafe because removing assignment from operator assignment can cause NameError if this assignment has been used to declare local variable. For example, replacing a ||= 1 to a || 1 may cause "undefined local variable or method `a' for main:Object (NameError)".

Example:

# bad

def some_method
  some_var = 1
  do_something
end

Example:

# good

def some_method
  some_var = 1
  do_something(some_var)
end

Useless assignment to variable - userinfo_log. Use _ or _userinfo_log as a variable name to indicate that it won't be used.
Open

    scheme_log, userinfo_log, host_log, port_log, registry_log, share_log, opaque_log, query_log, fragment_log = URI.split(URI::DEFAULT_PARSER.escape(log_uri))

Checks for every useless assignment to local variable in every scope. The basic idea for this cop was from the warning of ruby -cw:

assigned but unused variable - foo

Currently this cop has advanced logic that detects unreferenced reassignments and properly handles varied cases such as branch, loop, rescue, ensure, etc.

NOTE: Given the assignment foo = 1, bar = 2, removing unused variables can lead to a syntax error, so this case is not autocorrected.

Safety:

This cop's autocorrection is unsafe because removing assignment from operator assignment can cause NameError if this assignment has been used to declare local variable. For example, replacing a ||= 1 to a || 1 may cause "undefined local variable or method `a' for main:Object (NameError)".

Example:

# bad

def some_method
  some_var = 1
  do_something
end

Example:

# good

def some_method
  some_var = 1
  do_something(some_var)
end

Useless assignment to variable - fragment. Use _ or _fragment as a variable name to indicate that it won't be used.
Open

    scheme, userinfo, host, port, registry, path, opaque, query, fragment = URI.split(URI::DEFAULT_PARSER.escape(uri))

Checks for every useless assignment to local variable in every scope. The basic idea for this cop was from the warning of ruby -cw:

assigned but unused variable - foo

Currently this cop has advanced logic that detects unreferenced reassignments and properly handles varied cases such as branch, loop, rescue, ensure, etc.

NOTE: Given the assignment foo = 1, bar = 2, removing unused variables can lead to a syntax error, so this case is not autocorrected.

Safety:

This cop's autocorrection is unsafe because removing assignment from operator assignment can cause NameError if this assignment has been used to declare local variable. For example, replacing a ||= 1 to a || 1 may cause "undefined local variable or method `a' for main:Object (NameError)".

Example:

# bad

def some_method
  some_var = 1
  do_something
end

Example:

# good

def some_method
  some_var = 1
  do_something(some_var)
end

There are no issues that match your filters.

Category
Status