bio-miga/miga

View on GitHub
lib/miga/cli/action/init/daemon_helper.rb

Summary

Maintainability
C
7 hrs
Test Coverage

Module has too many lines. [204/100]
Open

module MiGA::Cli::Action::Init::DaemonHelper
  def configure_daemon
    cli.puts 'Default daemon configuration:'
    daemon_f = File.expand_path('.miga_daemon.json', ENV['MIGA_HOME'])
    unless File.exist?(daemon_f) and cli.ask_user(

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

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

  def configure_qsub_msub_daemon(v)
    flavor      = v[:type] == 'msub' ? 'msub' :
                  cli.ask_user('Select qsub flavor', 'torque', %w[torque sge])
    queue       = cli.ask_user('What queue should I use?', nil, nil, true)
    v[:latency] = cli.ask_user('How long should I sleep? (in secs)', '150').to_i

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.

Assignment Branch Condition size for configure_qsub_msub_daemon is too high. [45.72/15]
Open

  def configure_qsub_msub_daemon(v)
    flavor      = v[:type] == 'msub' ? 'msub' :
                  cli.ask_user('Select qsub flavor', 'torque', %w[torque sge])
    queue       = cli.ask_user('What queue should I use?', nil, nil, true)
    v[:latency] = cli.ask_user('How long should I sleep? (in secs)', '150').to_i

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. [36/10]
Open

  def configure_slurm_daemon(v)
    queue       = cli.ask_user('What queue should I use?', nil, nil, true)
    v[:latency] = cli.ask_user('How long should I sleep? (in secs)', '150').to_i
    v[:maxjobs] = cli.ask_user('How many jobs can I launch at once?', '300').to_i
    v[:ppn]     = cli.ask_user('How many CPUs can I use per job?', '2').to_i

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. [30/10]
Open

  def configure_ssh_daemon(v)
    v[:latency] = cli.ask_user('How long should I sleep? (in secs)', '3').to_i
    v[:nodelist] = cli.ask_user(
      'What environmental variable points to node list?', '$MIGA_NODELIST'
    )

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. [29/10]
Open

  def configure_bash_daemon(v)
    v[:latency] = cli.ask_user('How long should I sleep? (in secs)', '2').to_i
    v[:maxjobs] = cli.ask_user('How many jobs can I launch at once?', '6').to_i
    v[:ppn]     = cli.ask_user('How many CPUs can I use per job?', '2').to_i
    v[:nodelist] = nil # <- To enable non-default with default SSH

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. [25/10]
Open

  def configure_daemon
    cli.puts 'Default daemon configuration:'
    daemon_f = File.expand_path('.miga_daemon.json', ENV['MIGA_HOME'])
    unless File.exist?(daemon_f) and cli.ask_user(
      'A template daemon already exists, do you want to preserve it?',

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.

Assignment Branch Condition size for configure_daemon is too high. [27.66/15]
Open

  def configure_daemon
    cli.puts 'Default daemon configuration:'
    daemon_f = File.expand_path('.miga_daemon.json', ENV['MIGA_HOME'])
    unless File.exist?(daemon_f) and cli.ask_user(
      'A template daemon already exists, do you want to preserve it?',

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 configure_qsub_msub_daemon has 74 lines of code (exceeds 25 allowed). Consider refactoring.
Open

  def configure_qsub_msub_daemon(v)
    flavor      = v[:type] == 'msub' ? 'msub' :
                  cli.ask_user('Select qsub flavor', 'torque', %w[torque sge])
    queue       = cli.ask_user('What queue should I use?', nil, nil, true)
    v[:latency] = cli.ask_user('How long should I sleep? (in secs)', '150').to_i
Severity: Major
Found in lib/miga/cli/action/init/daemon_helper.rb - About 2 hrs to fix

Assignment Branch Condition size for configure_slurm_daemon is too high. [26.93/15]
Open

  def configure_slurm_daemon(v)
    queue       = cli.ask_user('What queue should I use?', nil, nil, true)
    v[:latency] = cli.ask_user('How long should I sleep? (in secs)', '150').to_i
    v[:maxjobs] = cli.ask_user('How many jobs can I launch at once?', '300').to_i
    v[:ppn]     = cli.ask_user('How many CPUs can I use per job?', '2').to_i

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 configure_bash_daemon is too high. [24.7/15]
Open

  def configure_bash_daemon(v)
    v[:latency] = cli.ask_user('How long should I sleep? (in secs)', '2').to_i
    v[:maxjobs] = cli.ask_user('How many jobs can I launch at once?', '6').to_i
    v[:ppn]     = cli.ask_user('How many CPUs can I use per job?', '2').to_i
    v[:nodelist] = nil # <- To enable non-default with default SSH

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 configure_ssh_daemon is too high. [23.41/15]
Open

  def configure_ssh_daemon(v)
    v[:latency] = cli.ask_user('How long should I sleep? (in secs)', '3').to_i
    v[:nodelist] = cli.ask_user(
      'What environmental variable points to node list?', '$MIGA_NODELIST'
    )

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

Perceived complexity for configure_qsub_msub_daemon is too high. [8/7]
Open

  def configure_qsub_msub_daemon(v)
    flavor      = v[:type] == 'msub' ? 'msub' :
                  cli.ask_user('Select qsub flavor', 'torque', %w[torque sge])
    queue       = cli.ask_user('What queue should I use?', nil, nil, true)
    v[:latency] = cli.ask_user('How long should I sleep? (in secs)', '150').to_i

This cop tries to produce a complexity score that's a measure of the complexity the reader experiences when looking at a method. For that reason it considers when nodes as something that doesn't add as much complexity as an if or a &&. Except if it's one of those special case/when constructs where there's no expression after case. Then the cop treats it as an if/elsif/elsif... and lets all the when nodes count. In contrast to the CyclomaticComplexity cop, this cop considers else nodes as adding complexity.

Example:

def my_method                   # 1
  if cond                       # 1
    case var                    # 2 (0.8 + 4 * 0.2, rounded)
    when 1 then func_one
    when 2 then func_two
    when 3 then func_three
    when 4..10 then func_other
    end
  else                          # 1
    do_something until a && b   # 2
  end                           # ===
end                             # 7 complexity points

Method configure_slurm_daemon has 36 lines of code (exceeds 25 allowed). Consider refactoring.
Open

  def configure_slurm_daemon(v)
    queue       = cli.ask_user('What queue should I use?', nil, nil, true)
    v[:latency] = cli.ask_user('How long should I sleep? (in secs)', '150').to_i
    v[:maxjobs] = cli.ask_user('How many jobs can I launch at once?', '300').to_i
    v[:ppn]     = cli.ask_user('How many CPUs can I use per job?', '2').to_i
Severity: Minor
Found in lib/miga/cli/action/init/daemon_helper.rb - About 1 hr to fix

Method configure_ssh_daemon has 30 lines of code (exceeds 25 allowed). Consider refactoring.
Open

  def configure_ssh_daemon(v)
    v[:latency] = cli.ask_user('How long should I sleep? (in secs)', '3').to_i
    v[:nodelist] = cli.ask_user(
      'What environmental variable points to node list?', '$MIGA_NODELIST'
    )
Severity: Minor
Found in lib/miga/cli/action/init/daemon_helper.rb - About 1 hr to fix

Method configure_bash_daemon has 29 lines of code (exceeds 25 allowed). Consider refactoring.
Open

  def configure_bash_daemon(v)
    v[:latency] = cli.ask_user('How long should I sleep? (in secs)', '2').to_i
    v[:maxjobs] = cli.ask_user('How many jobs can I launch at once?', '6').to_i
    v[:ppn]     = cli.ask_user('How many CPUs can I use per job?', '2').to_i
    v[:nodelist] = nil # <- To enable non-default with default SSH
Severity: Minor
Found in lib/miga/cli/action/init/daemon_helper.rb - About 1 hr to fix

Method configure_qsub_msub_daemon has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
Open

  def configure_qsub_msub_daemon(v)
    flavor      = v[:type] == 'msub' ? 'msub' :
                  cli.ask_user('Select qsub flavor', 'torque', %w[torque sge])
    queue       = cli.ask_user('What queue should I use?', nil, nil, true)
    v[:latency] = cli.ask_user('How long should I sleep? (in secs)', '150').to_i
Severity: Minor
Found in lib/miga/cli/action/init/daemon_helper.rb - About 55 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 the return of the conditional for variable assignment and comparison.
Open

      case v[:type]
      when 'bash'
        v = configure_bash_daemon(v)
      when 'ssh'
        v = configure_ssh_daemon(v)

Prefer single-quoted strings when you don't need string interpolation or special symbols.
Open

      "{{key}}={{value}}"

Checks if uses of quotes match the configured preference.

Example: EnforcedStyle: single_quotes (default)

# bad
"No special symbols"
"No string interpolation"
"Just text"

# good
'No special symbols'
'No string interpolation'
'Just text'
"Wait! What's #{this}!"

Example: EnforcedStyle: double_quotes

# bad
'Just some text'
'No special chars or interpolation'

# good
"Just some text"
"No special chars or interpolation"
"Every string in #{project} uses double_quotes"

Line is too long. [85/80]
Open

          "  {{variables}}: script, vars, cpus, log, task_name, task_name_simple\n ",

%w-literals should be delimited by [ and ].
Open

        cli[:dtype], %w(bash ssh qsub msub slurm)

This cop enforces the consistent usage of %-literal delimiters.

Specify the 'default' key to set all preferred delimiters at once. You can continue to specify individual preferred delimiters to override the default.

Example:

# Style/PercentLiteralDelimiters:
#   PreferredDelimiters:
#     default: '[]'
#     '%i':    '()'

# good
%w[alpha beta] + %i(gamma delta)

# bad
%W(alpha #{beta})

# bad
%I(alpha beta)

Prefer single-quoted strings when you don't need string interpolation or special symbols.
Open

        "| tail -n 1 | wc -l"

Checks if uses of quotes match the configured preference.

Example: EnforcedStyle: single_quotes (default)

# bad
"No special symbols"
"No string interpolation"
"Just text"

# good
'No special symbols'
'No string interpolation'
'Just text'
"Wait! What's #{this}!"

Example: EnforcedStyle: double_quotes

# bad
'Just some text'
'No special chars or interpolation'

# good
"Just some text"
"No special chars or interpolation"
"Every string in #{project} uses double_quotes"

Avoid multi-line ternary operators, use if or unless instead.
Open

    flavor      = v[:type] == 'msub' ? 'msub' :
                  cli.ask_user('Select qsub flavor', 'torque', %w[torque sge])

This cop checks for multi-line ternary op expressions.

Example:

# bad
a = cond ?
  b : c
a = cond ? b :
    c
a = cond ?
    b :
    c

# good
a = cond ? b : c
a =
  if cond
    b
  else
    c
  end

Prefer single-quoted strings when you don't need string interpolation or special symbols.
Open

      "{{key}}={{value}}"

Checks if uses of quotes match the configured preference.

Example: EnforcedStyle: single_quotes (default)

# bad
"No special symbols"
"No string interpolation"
"Just text"

# good
'No special symbols'
'No string interpolation'
'Just text'
"Wait! What's #{this}!"

Example: EnforcedStyle: double_quotes

# bad
'Just some text'
'No special chars or interpolation'

# good
"Just some text"
"No special chars or interpolation"
"Every string in #{project} uses double_quotes"

Prefer single-quoted strings when you don't need string interpolation or special symbols.
Open

      "{{key}}={{value}}"

Checks if uses of quotes match the configured preference.

Example: EnforcedStyle: single_quotes (default)

# bad
"No special symbols"
"No string interpolation"
"Just text"

# good
'No special symbols'
'No string interpolation'
'Just text'
"Wait! What's #{this}!"

Example: EnforcedStyle: double_quotes

# bad
'Just some text'
'No special chars or interpolation'

# good
"Just some text"
"No special chars or interpolation"
"Every string in #{project} uses double_quotes"

Line is too long. [81/80]
Open

    v[:maxjobs] = cli.ask_user('How many jobs can I launch at once?', '300').to_i

Line is too long. [81/80]
Open

    v[:maxjobs] = cli.ask_user('How many jobs can I launch at once?', '300').to_i

Line is too long. [85/80]
Open

          "  {{variables}}: script, vars, cpus, log, task_name, task_name_simple\n ",

Use && instead of and.
Open

    unless File.exist?(daemon_f) and cli.ask_user(

This cop checks for uses of and and or, and suggests using && and || instead. It can be configured to check only in conditions, or in all contexts.

Example: EnforcedStyle: always (default)

# bad
foo.save and return

# bad
if foo and bar
end

# good
foo.save && return

# good
if foo && bar
end

Example: EnforcedStyle: conditionals

# bad
if foo and bar
end

# good
foo.save && return

# good
foo.save and return

# good
if foo && bar
end

%w-literals should be delimited by [ and ].
Open

      'yes', %w(yes no)

This cop enforces the consistent usage of %-literal delimiters.

Specify the 'default' key to set all preferred delimiters at once. You can continue to specify individual preferred delimiters to override the default.

Example:

# Style/PercentLiteralDelimiters:
#   PreferredDelimiters:
#     default: '[]'
#     '%i':    '()'

# good
%w[alpha beta] + %i(gamma delta)

# bad
%W(alpha #{beta})

# bad
%I(alpha beta)

Prefer single-quoted strings when you don't need string interpolation or special symbols.
Open

      "{{key}}={{value}}"

Checks if uses of quotes match the configured preference.

Example: EnforcedStyle: single_quotes (default)

# bad
"No special symbols"
"No string interpolation"
"Just text"

# good
'No special symbols'
'No string interpolation'
'Just text'
"Wait! What's #{this}!"

Example: EnforcedStyle: double_quotes

# bad
'Just some text'
'No special chars or interpolation'

# good
"Just some text"
"No special chars or interpolation"
"Every string in #{project} uses double_quotes"

There are no issues that match your filters.

Category
Status