bio-miga/miga

View on GitHub
lib/miga/remote_dataset/download.rb

Summary

Maintainability
A
3 hrs
Test Coverage
F
55%

Class has too many lines. [129/100]
Open

class MiGA::RemoteDataset
  include MiGA::RemoteDataset::Base

  # Class-level
  class << self
Severity: Minor
Found in lib/miga/remote_dataset/download.rb by rubocop

This cop checks if the length a class exceeds some maximum value. Comment lines can optionally be ignored. The maximum allowed length is configurable.

Assignment Branch Condition size for ncbi_gb_get is too high. [33.76/15]
Open

    def ncbi_gb_get(opts)
      # Simply use defaults, but ensure that the URL can be properly formed
      o = download_rest(opts.merge(universe: :ncbi, db: :nuccore))
      return o unless o.strip.empty?

Severity: Minor
Found in lib/miga/remote_dataset/download.rb by rubocop

This cop checks that the ABC size of methods is not higher than the configured maximum. The ABC size is based on assignments, branches (method calls), and conditions. See http://c2.com/cgi/wiki?AbcMetric

Assignment Branch Condition size for ncbi_asm_get is too high. [31.92/15]
Open

    def ncbi_asm_get(opts)
      require 'tempfile'
      require 'zip'

      zipped = download(
Severity: Minor
Found in lib/miga/remote_dataset/download.rb by rubocop

This cop checks that the ABC size of methods is not higher than the configured maximum. The ABC size is based on assignments, branches (method calls), and conditions. See http://c2.com/cgi/wiki?AbcMetric

Method has too many lines. [26/10]
Open

    def ncbi_asm_get(opts)
      require 'tempfile'
      require 'zip'

      zipped = download(
Severity: Minor
Found in lib/miga/remote_dataset/download.rb by rubocop

This cop checks if the length of a method exceeds some maximum value. Comment lines can optionally be ignored. The maximum allowed length is configurable.

Method has too many lines. [19/10]
Open

    def ncbi_gb_get(opts)
      # Simply use defaults, but ensure that the URL can be properly formed
      o = download_rest(opts.merge(universe: :ncbi, db: :nuccore))
      return o unless o.strip.empty?

Severity: Minor
Found in lib/miga/remote_dataset/download.rb by rubocop

This cop checks if the length of a method exceeds some maximum value. Comment lines can optionally be ignored. The maximum allowed length is configurable.

Method has too many lines. [12/10]
Open

    def ncbi_map(id, dbfrom, db)
      doc = download(:ncbi_map, dbfrom, id, :json, nil, db: db)
      return if doc.empty?

      begin
Severity: Minor
Found in lib/miga/remote_dataset/download.rb by rubocop

This cop checks if the length of a method exceeds some maximum value. Comment lines can optionally be ignored. The maximum allowed length is configurable.

Method has too many lines. [11/10]
Open

    def download(*params)
      opts = download_opts(*params)
      doc = send(opts[:_fun], opts)

      unless opts[:file].nil?
Severity: Minor
Found in lib/miga/remote_dataset/download.rb by rubocop

This cop checks if the length of a method exceeds some maximum value. Comment lines can optionally be ignored. The maximum allowed length is configurable.

Method has too many lines. [11/10]
Open

    def download_opts(
          universe, db, ids, format, file = nil, extra = {}, obj = nil)
      universe_hash = @@UNIVERSE[universe]
      database_hash = universe_hash.dig(:dbs, db)
      getter = database_hash[:getter] || :download
Severity: Minor
Found in lib/miga/remote_dataset/download.rb by rubocop

This cop checks if the length of a method exceeds some maximum value. Comment lines can optionally be ignored. The maximum allowed length is configurable.

Method ncbi_asm_get has 26 lines of code (exceeds 25 allowed). Consider refactoring.
Open

    def ncbi_asm_get(opts)
      require 'tempfile'
      require 'zip'

      zipped = download(
Severity: Minor
Found in lib/miga/remote_dataset/download.rb - About 1 hr to fix

Method download_opts has 7 arguments (exceeds 4 allowed). Consider refactoring.
Open

          universe, db, ids, format, file = nil, extra = {}, obj = nil)
Severity: Major
Found in lib/miga/remote_dataset/download.rb - About 50 mins to fix

Method ncbi_gb_get has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
Open

    def ncbi_gb_get(opts)
      # Simply use defaults, but ensure that the URL can be properly formed
      o = download_rest(opts.merge(universe: :ncbi, db: :nuccore))
      return o unless o.strip.empty?

Severity: Minor
Found in lib/miga/remote_dataset/download.rb - About 45 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

Avoid parameter lists longer than 5 parameters. [7/5]
Open

    def download_opts(
          universe, db, ids, format, file = nil, extra = {}, obj = nil)
Severity: Minor
Found in lib/miga/remote_dataset/download.rb by rubocop

This cop checks for methods with too many parameters. The maximum number of parameters is configurable. Keyword arguments can optionally be excluded from the total count.

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

    def ncbi_asm_get(opts)
      require 'tempfile'
      require 'zip'

      zipped = download(
Severity: Minor
Found in lib/miga/remote_dataset/download.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

Prefer annotated tokens (like %<foo>s</foo>) over unannotated tokens (like %s).
Open

        ids  = rang.map { |k| "%s%0#{a.size - pref.size}i" % [pref, k] }
Severity: Minor
Found in lib/miga/remote_dataset/download.rb by rubocop

Use a consistent style for named format string tokens.

Note: unannotated style cop only works for strings which are passed as arguments to those methods: sprintf, format, %. The reason is that unannotated format is very similar to encoded URLs or Date/Time formatting strings.

Example: EnforcedStyle: annotated (default)

# bad
format('%{greeting}', greeting: 'Hello')
format('%s', 'Hello')

# good
format('%<greeting>s', greeting: 'Hello')</greeting>

Example: EnforcedStyle: template

# bad
format('%<greeting>s', greeting: 'Hello')
format('%s', 'Hello')

# good
format('%{greeting}', greeting: 'Hello')</greeting>

Example: EnforcedStyle: unannotated

# bad
format('%<greeting>s', greeting: 'Hello')
format('%{greeting}', 'Hello')

# good
format('%s', 'Hello')</greeting>

Missing magic comment # frozen_string_literal: true.
Open

require 'miga/remote_dataset/base'
Severity: Minor
Found in lib/miga/remote_dataset/download.rb by rubocop

This cop is designed to help upgrade to Ruby 3.0. It will add the comment # frozen_string_literal: true to the top of files to enable frozen string literals. Frozen string literals may be default in Ruby 3.0. The comment will be added below a shebang and encoding comment. The frozen string literal comment is only valid in Ruby 2.3+.

Example: EnforcedStyle: when_needed (default)

# The `when_needed` style will add the frozen string literal comment
# to files only when the `TargetRubyVersion` is set to 2.3+.
# bad
module Foo
  # ...
end

# good
# frozen_string_literal: true

module Foo
  # ...
end

Example: EnforcedStyle: always

# The `always` style will always add the frozen string literal comment
# to a file, regardless of the Ruby version or if `freeze` or `<<` are
# called on a string literal.
# bad
module Bar
  # ...
end

# good
# frozen_string_literal: true

module Bar
  # ...
end

Example: EnforcedStyle: never

# The `never` will enforce that the frozen string literal comment does
# not exist in a file.
# bad
# frozen_string_literal: true

module Baz
  # ...
end

# good
module Baz
  # ...
end

Useless assignment to variable - ids.
Open

      ids = 
Severity: Minor
Found in lib/miga/remote_dataset/download.rb by rubocop

This cop 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.

Example:

# bad

def some_method
  some_var = 1
  do_something
end

Example:

# good

def some_method
  some_var = 1
  do_something(some_var)
end

Missing top-level class documentation comment.
Open

class MiGA::RemoteDataset
Severity: Minor
Found in lib/miga/remote_dataset/download.rb by rubocop

This cop checks for missing top-level documentation of classes and modules. Classes with no body are exempt from the check and so are namespace modules - modules that have nothing in their bodies except classes, other modules, or constant definitions.

The documentation requirement is annulled if the class or module has a "#:nodoc:" comment next to it. Likewise, "#:nodoc: all" does the same for all its children.

Example:

# bad
class Person
  # ...
end

# good
# Description/Explanation of Person class
class Person
  # ...
end

Space inside range literal.
Open

        rang = a[pref.size .. -1].to_i .. b[pref.size .. -1].to_i
Severity: Minor
Found in lib/miga/remote_dataset/download.rb by rubocop

Checks for spaces inside range literals.

Example:

# bad
1 .. 3

# good
1..3

# bad
'a' .. 'z'

# good
'a'..'z'

Space inside range literal.
Open

        rang = a[pref.size .. -1].to_i .. b[pref.size .. -1].to_i
Severity: Minor
Found in lib/miga/remote_dataset/download.rb by rubocop

Checks for spaces inside range literals.

Example:

# bad
1 .. 3

# good
1..3

# bad
'a' .. 'z'

# good
'a'..'z'

Avoid rescuing without specifying an error class.
Open

      rescue => e
Severity: Minor
Found in lib/miga/remote_dataset/download.rb by rubocop

This cop checks for rescuing StandardError. There are two supported styles implicit and explicit. This cop will not register an offense if any error other than StandardError is specified.

Example: EnforcedStyle: implicit

# `implicit` will enforce using `rescue` instead of
# `rescue StandardError`.

# bad
begin
  foo
rescue StandardError
  bar
end

# good
begin
  foo
rescue
  bar
end

# good
begin
  foo
rescue OtherError
  bar
end

# good
begin
  foo
rescue StandardError, SecurityError
  bar
end

Example: EnforcedStyle: explicit (default)

# `explicit` will enforce using `rescue StandardError`
# instead of `rescue`.

# bad
begin
  foo
rescue
  bar
end

# good
begin
  foo
rescue StandardError
  bar
end

# good
begin
  foo
rescue OtherError
  bar
end

# good
begin
  foo
rescue StandardError, SecurityError
  bar
end

Use next to skip iteration.
Open

          if entry.file? && entry.name =~ /_genomic\.fna$/
Severity: Minor
Found in lib/miga/remote_dataset/download.rb by rubocop

Use next to skip iteration instead of a condition at the end.

Example: EnforcedStyle: skipmodifierifs (default)

# bad
[1, 2].each do |a|
  if a == 1
    puts a
  end
end

# good
[1, 2].each do |a|
  next unless a == 1
  puts a
end

# good
[1, 2].each do |o|
  puts o unless o == 1
end

Example: EnforcedStyle: always

# With `always` all conditions at the end of an iteration needs to be
# replaced by next - with `skip_modifier_ifs` the modifier if like
# this one are ignored: `[1, 2].each { |a| return 'yes' if a == 1 }`

# bad
[1, 2].each do |o|
  puts o unless o == 1
end

# bad
[1, 2].each do |a|
  if a == 1
    puts a
  end
end

# good
[1, 2].each do |a|
  next unless a == 1
  puts a
end

Closing method definition brace must be on the line after the last parameter when opening brace is on a separate line from the first parameter.
Open

          universe, db, ids, format, file = nil, extra = {}, obj = nil)
Severity: Minor
Found in lib/miga/remote_dataset/download.rb by rubocop

This cop checks that the closing brace in a method definition is either on the same line as the last method parameter, or a new line.

When using the symmetrical (default) style:

If a method definition's opening brace is on the same line as the first parameter of the definition, then the closing brace should be on the same line as the last parameter of the definition.

If an method definition's opening brace is on the line above the first parameter of the definition, then the closing brace should be on the line below the last parameter of the definition.

When using the new_line style:

The closing brace of a multi-line method definition must be on the line after the last parameter of the definition.

When using the same_line style:

The closing brace of a multi-line method definition must be on the same line as the last parameter of the definition.

Example:

# symmetrical: bad
  # new_line: good
  # same_line: bad
  def foo(a,
    b
  )
  end

  # symmetrical: bad
  # new_line: bad
  # same_line: good
  def foo(
    a,
    b)
  end

  # symmetrical: good
  # new_line: bad
  # same_line: good
  def foo(a,
    b)
  end

  # symmetrical: good
  # new_line: good
  # same_line: bad
  def foo(
    a,
    b
  )
  end

Space inside range literal.
Open

        rang = a[pref.size .. -1].to_i .. b[pref.size .. -1].to_i
Severity: Minor
Found in lib/miga/remote_dataset/download.rb by rubocop

Checks for spaces inside range literals.

Example:

# bad
1 .. 3

# good
1..3

# bad
'a' .. 'z'

# good
'a'..'z'

Trailing whitespace detected.
Open

      ids = 
Severity: Minor
Found in lib/miga/remote_dataset/download.rb by rubocop

Missing top-level module documentation comment.
Open

module MiGA::RemoteDataset::Download
Severity: Minor
Found in lib/miga/remote_dataset/download.rb by rubocop

This cop checks for missing top-level documentation of classes and modules. Classes with no body are exempt from the check and so are namespace modules - modules that have nothing in their bodies except classes, other modules, or constant definitions.

The documentation requirement is annulled if the class or module has a "#:nodoc:" comment next to it. Likewise, "#:nodoc: all" does the same for all its children.

Example:

# bad
class Person
  # ...
end

# good
# Description/Explanation of Person class
class Person
  # ...
end

Indent the first line of the right-hand-side of a multi-line assignment.
Open

      {
        universe: universe,  db:   db,    ids: ids.is_a?(Array) ? ids : [ids],
        format:   format,    file: file,  obj: obj,
        extra:    (database_hash[:extra] || {}).merge(extra),
        _fun:     :"#{getter}_#{action}"
Severity: Minor
Found in lib/miga/remote_dataset/download.rb by rubocop

This cop checks the indentation of the first line of the right-hand-side of a multi-line assignment.

Example:

# bad
value =
if foo
  'bar'
end

# good
value =
  if foo
    'bar'
  end

The indentation of the remaining lines can be corrected with other cops such as IndentationConsistency and EndAlignment.

Avoid rescuing without specifying an error class.
Open

      rescue => e
Severity: Minor
Found in lib/miga/remote_dataset/download.rb by rubocop

This cop checks for rescuing StandardError. There are two supported styles implicit and explicit. This cop will not register an offense if any error other than StandardError is specified.

Example: EnforcedStyle: implicit

# `implicit` will enforce using `rescue` instead of
# `rescue StandardError`.

# bad
begin
  foo
rescue StandardError
  bar
end

# good
begin
  foo
rescue
  bar
end

# good
begin
  foo
rescue OtherError
  bar
end

# good
begin
  foo
rescue StandardError, SecurityError
  bar
end

Example: EnforcedStyle: explicit (default)

# `explicit` will enforce using `rescue StandardError`
# instead of `rescue`.

# bad
begin
  foo
rescue
  bar
end

# good
begin
  foo
rescue StandardError
  bar
end

# good
begin
  foo
rescue OtherError
  bar
end

# good
begin
  foo
rescue StandardError, SecurityError
  bar
end

There are no issues that match your filters.

Category
Status