ManageIQ/manageiq-providers-ibm_cloud

View on GitHub

Showing 61 of 61 total issues

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

  def resource_groups_to_resource_groups(_options = {})
    return {} if ar_ems.nil?

    @resource_groups_to_resource_groups ||= string_dropdown(ar_ems.resource_groups)
  rescue => e
app/models/manageiq/providers/ibm_cloud/vpc/cloud_manager/provision_workflow/general.rb on lines 8..14
app/models/manageiq/providers/ibm_cloud/vpc/cloud_manager/provision_workflow/general.rb on lines 36..42
app/models/manageiq/providers/ibm_cloud/vpc/cloud_manager/provision_workflow/network.rb on lines 8..14
app/models/manageiq/providers/ibm_cloud/vpc/cloud_manager/provision_workflow/network.rb on lines 19..25

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

                      {
                        :component  => "textarea",
                        :id         => "endpoints.prometheus.certificate_authority",
                        :name       => "endpoints.prometheus.certificate_authority",
                        :label      => _("Trusted CA Certificates"),
Severity: Minor
Found in app/models/manageiq/providers/ibm_cloud/container_manager.rb and 1 other location - About 15 mins to fix
app/models/manageiq/providers/ibm_cloud/container_manager.rb on lines 185..195

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

                      {
                        :component  => "textarea",
                        :id         => "endpoints.default.certificate_authority",
                        :name       => "endpoints.default.certificate_authority",
                        :label      => _("Trusted CA Certificates"),
Severity: Minor
Found in app/models/manageiq/providers/ibm_cloud/container_manager.rb and 1 other location - About 15 mins to fix
app/models/manageiq/providers/ibm_cloud/container_manager.rb on lines 316..326

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 5 locations. Consider refactoring.
Open

  def guest_access_key_pairs_to_keys(_options = {})
    return {} if ar_ems.nil?

    @guest_access_key_pairs_to_keys ||= string_dropdown(ar_ems.key_pairs)
  rescue => e
app/models/manageiq/providers/ibm_cloud/vpc/cloud_manager/provision_workflow/general.rb on lines 8..14
app/models/manageiq/providers/ibm_cloud/vpc/cloud_manager/provision_workflow/general.rb on lines 47..53
app/models/manageiq/providers/ibm_cloud/vpc/cloud_manager/provision_workflow/network.rb on lines 8..14
app/models/manageiq/providers/ibm_cloud/vpc/cloud_manager/provision_workflow/network.rb on lines 19..25

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 5 locations. Consider refactoring.
Open

  def placement_availability_zone_to_zone(_options = {})
    return {} if ar_ems.nil?

    @placement_availability_zone_to_zone ||= index_dropdown(ar_ems.availability_zones)
  rescue => e
app/models/manageiq/providers/ibm_cloud/vpc/cloud_manager/provision_workflow/general.rb on lines 8..14
app/models/manageiq/providers/ibm_cloud/vpc/cloud_manager/provision_workflow/general.rb on lines 36..42
app/models/manageiq/providers/ibm_cloud/vpc/cloud_manager/provision_workflow/general.rb on lines 47..53
app/models/manageiq/providers/ibm_cloud/vpc/cloud_manager/provision_workflow/network.rb on lines 19..25

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

Duplicate branch body detected.
Open

    when /^pvm-instance\.update/
      targets << ems_event.ext_management_system

Checks that there are no repeated bodies within if/unless, case-when, case-in and rescue constructs.

With IgnoreLiteralBranches: true, branches are not registered as offenses if they return a basic literal value (string, symbol, integer, float, rational, complex, true, false, or nil), or return an array, hash, regexp or range that only contains one of the above basic literal values.

With IgnoreConstantBranches: true, branches are not registered as offenses if they return a constant value.

Example:

# bad
if foo
  do_foo
  do_something_else
elsif bar
  do_foo
  do_something_else
end

# good
if foo || bar
  do_foo
  do_something_else
end

# bad
case x
when foo
  do_foo
when bar
  do_foo
else
  do_something_else
end

# good
case x
when foo, bar
  do_foo
else
  do_something_else
end

# bad
begin
  do_something
rescue FooError
  handle_error
rescue BarError
  handle_error
end

# good
begin
  do_something
rescue FooError, BarError
  handle_error
end

Example: IgnoreLiteralBranches: true

# good
case size
when "small" then 100
when "medium" then 250
when "large" then 1000
else 250
end

Example: IgnoreConstantBranches: true

# good
case size
when "small" then SMALL_SIZE
when "medium" then MEDIUM_SIZE
when "large" then LARGE_SIZE
else MEDIUM_SIZE
end

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

      dataset[:net_usage_rate_average] << (datapoint["d"][2] + datapoint["d"][3]) / 1.kilobyte

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

metadata['rubygems_mfa_required'] must be set to 'true'.
Open

Gem::Specification.new do |spec|
  spec.name          = "manageiq-providers-ibm_cloud"
  spec.version       = ManageIQ::Providers::IbmCloud::VERSION
  spec.authors       = ["ManageIQ Authors"]

Requires a gemspec to have rubygems_mfa_required metadata set.

This setting tells RubyGems that MFA (Multi-Factor Authentication) is required for accounts to be able perform privileged operations, such as (see RubyGems' documentation for the full list of privileged operations):

  • gem push
  • gem yank
  • gem owner --add/remove
  • adding or removing owners using gem ownership page

This helps make your gem more secure, as users can be more confident that gem updates were pushed by maintainers.

Example:

# bad
Gem::Specification.new do |spec|
  # no `rubygems_mfa_required` metadata specified
end

# good
Gem::Specification.new do |spec|
  spec.metadata = {
    'rubygems_mfa_required' => 'true'
  }
end

# good
Gem::Specification.new do |spec|
  spec.metadata['rubygems_mfa_required'] = 'true'
end

# bad
Gem::Specification.new do |spec|
  spec.metadata = {
    'rubygems_mfa_required' => 'false'
  }
end

# good
Gem::Specification.new do |spec|
  spec.metadata = {
    'rubygems_mfa_required' => 'true'
  }
end

# bad
Gem::Specification.new do |spec|
  spec.metadata['rubygems_mfa_required'] = 'false'
end

# good
Gem::Specification.new do |spec|
  spec.metadata['rubygems_mfa_required'] = 'true'
end

Dependencies should be sorted in an alphabetical order within their section of the gemspec. Dependency ibm_cloud_activity_tracker should appear before ibm-cloud-sdk.
Open

  spec.add_dependency "ibm_cloud_activity_tracker", "~> 0.1", ">= 0.1.2"

Dependencies in the gemspec should be alphabetically sorted.

Example:

# bad
spec.add_dependency 'rubocop'
spec.add_dependency 'rspec'

# good
spec.add_dependency 'rspec'
spec.add_dependency 'rubocop'

# good
spec.add_dependency 'rubocop'

spec.add_dependency 'rspec'

# bad
spec.add_development_dependency 'rubocop'
spec.add_development_dependency 'rspec'

# good
spec.add_development_dependency 'rspec'
spec.add_development_dependency 'rubocop'

# good
spec.add_development_dependency 'rubocop'

spec.add_development_dependency 'rspec'

# bad
spec.add_runtime_dependency 'rubocop'
spec.add_runtime_dependency 'rspec'

# good
spec.add_runtime_dependency 'rspec'
spec.add_runtime_dependency 'rubocop'

# good
spec.add_runtime_dependency 'rubocop'

spec.add_runtime_dependency 'rspec'

Example: TreatCommentsAsGroupSeparators: true (default)

# good
# For code quality
spec.add_dependency 'rubocop'
# For tests
spec.add_dependency 'rspec'

Example: TreatCommentsAsGroupSeparators: false

# bad
# For code quality
spec.add_dependency 'rubocop'
# For tests
spec.add_dependency 'rspec'

Use filter_map instead.
Open

    ext_management_system.flavors.map do |ems_flavor|
      # include only flavors with root disks at least as big as the instance's current root disk.
      next if flavor && (ems_flavor == flavor || ems_flavor.root_disk_size < flavor.root_disk_size)

      {:label => ems_flavor.name_with_details, :value => ems_flavor.name}

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

      dataset[:disk_usage_rate_average] << (datapoint["d"][4] + datapoint["d"][5]) / 1.kilobyte

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

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

      ldesc << " - (%d User Licenses)" % [software_licenses.ibmi_rds_users] if software_licenses.ibmi_rds_users

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

Call super to initialize state of the parent class.
Open

  def initialize(target, start_time, end_time, interval)
    @target = target
    @starts = start_time.to_i.in_milliseconds
    @ends = end_time.to_i.in_milliseconds if end_time
    @interval = interval.to_i

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

Use filter_map instead.
Open

    @images ||= references(:miq_templates).map do |ems_ref|
      images_api.pcloud_cloudinstances_images_get(cloud_instance_id, ems_ref)
    rescue IbmCloudPower::ApiError => err
      error_message = JSON.parse(err.response_body)["description"]
      _log.debug("ImageID not found: #{error_message}")

Use filter_map instead.
Open

    @pvm_instances ||= references(:vms).map do |ems_ref|
      pvm_instances_api.pcloud_pvminstances_get(cloud_instance_id, ems_ref)
    rescue IbmCloudPower::ApiError => err
      error_message = JSON.parse(err.response_body)["description"]
      _log.debug("PVMInstanceID not found: #{error_message}")

Ensure you correctly provided all the arguments.
Open

              enum_for(:each_resource, call_back, **kwargs)

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 filter_map instead.
Open

    @volumes ||= references(:cloud_volumes).map do |ems_ref|
      volumes_api.pcloud_cloudinstances_volumes_get(cloud_instance_id, ems_ref)
    rescue IbmCloudPower::ApiError => err
      error_message = JSON.parse(err.response_body)["description"]
      _log.debug("VolumeID not found: #{error_message}")

Useless rescue detected.
Open

      rescue => error
        raise error
Severity: Minor
Found in lib/tasks_private/vpc.rake by rubocop

Checks for useless rescues, which only reraise rescued exceptions.

Example:

# bad
def foo
  do_something
rescue
  raise
end

# bad
def foo
  do_something
rescue => e
  raise # or 'raise e', or 'raise $!', or 'raise $ERROR_INFO'
end

# good
def foo
  do_something
rescue
  do_cleanup
  raise
end

# bad (latest rescue)
def foo
  do_something
rescue ArgumentError
  # noop
rescue
  raise
end

# good (not the latest rescue)
def foo
  do_something
rescue ArgumentError
  raise
rescue
  # noop
end

Use filter_map instead.
Open

    @networks ||= references(:cloud_networks).map do |ems_ref|
      networks_api.pcloud_networks_get(cloud_instance_id, ems_ref)
    rescue IbmCloudPower::ApiError => err
      error_message = JSON.parse(err.response_body)["description"]
      _log.debug("NetworkID not found: #{error_message}")

Use filter_map instead.
Open

      references(:vms).map do |ems_ref|
        vpc.request(:get_instance, :id => ems_ref)
      rescue IBMCloudSdkCore::ApiException
        nil
      end.compact
Severity
Category
Status
Source
Language