bio-miga/miga

View on GitHub
lib/miga/common/with_daemon.rb

Summary

Maintainability
A
2 hrs
Test Coverage
A
97%

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

module MiGA::Common::WithDaemon
  # Process ID of the forked process declaring the daemon alive
  attr :declare_alive_pid

  # Loop counter
Severity: Minor
Found in lib/miga/common/with_daemon.rb by rubocop

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 declare_alive_loop has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
Open

  def declare_alive_loop(pid = Process.ppid)
    i = -1
    loop do
      i += 1
      return :no_home unless Dir.exist? daemon_home
Severity: Minor
Found in lib/miga/common/with_daemon.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 stop has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
Open

  def stop(opts = [], wait = true)
    if active?
      say 'Sending termination message'
      FileUtils.touch(terminate_file)
      sleep(0.5) while active? if wait
Severity: Minor
Found in lib/miga/common/with_daemon.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 (i % 30).zero? instead of i % 30 == 0.
Open

      write_alive_file if i % 30 == 0
Severity: Minor
Found in lib/miga/common/with_daemon.rb by rubocop

This cop checks for usage of comparison operators (==, >, <) to test numbers as zero, positive, or negative. These can be replaced by their respective predicate methods. The cop can also be configured to do the reverse.

The cop disregards #nonzero? as it its value is truthy or falsey, but not true and false, and thus not always interchangeable with != 0.

The cop ignores comparisons to global variables, since they are often populated with objects which can be compared with integers, but are not themselves Interger polymorphic.

Example: EnforcedStyle: predicate (default)

# bad

foo == 0
0 > foo
bar.baz > 0

# good

foo.zero?
foo.negative?
bar.baz.positive?

Example: EnforcedStyle: comparison

# bad

foo.zero?
foo.negative?
bar.baz.positive?

# good

foo == 0
0 > foo
bar.baz > 0

Do not use attr. Use attr_reader instead.
Open

  attr :declare_alive_pid
Severity: Minor
Found in lib/miga/common/with_daemon.rb by rubocop

This cop checks for uses of Module#attr.

Example:

# bad - creates a single attribute accessor (deprecated in Ruby 1.9)
attr :something, true
attr :one, :two, :three # behaves as attr_reader

# good
attr_accessor :something
attr_reader :one, :two, :three

Unused method argument - opts. If it's necessary, use _ or _opts as an argument name to indicate that it won't be used. You can also write as status(*) if you want the method to accept any arguments but don't care about them.
Open

  def status(opts = [], wait = true)
Severity: Minor
Found in lib/miga/common/with_daemon.rb by rubocop

This cop checks for unused method arguments.

Example:

# bad

def some_method(used, unused, _unused_but_allowed)
  puts used
end

Example:

# good

def some_method(used, _unused, _unused_but_allowed)
  puts used
end

Unused method argument - opts. If it's necessary, use _ or _opts as an argument name to indicate that it won't be used.
Open

  def stop(opts = [], wait = true)
Severity: Minor
Found in lib/miga/common/with_daemon.rb by rubocop

This cop checks for unused method arguments.

Example:

# bad

def some_method(used, unused, _unused_but_allowed)
  puts used
end

Example:

# good

def some_method(used, _unused, _unused_but_allowed)
  puts used
end

Avoid using nested modifiers.
Open

      sleep(0.5) while active? if wait
Severity: Minor
Found in lib/miga/common/with_daemon.rb by rubocop

This cop checks for nested use of if, unless, while and until in their modifier form.

Example:

# bad
something if a if b

# good
something if b && a

Do not use attr. Use attr_reader instead.
Open

  attr :loop_i
Severity: Minor
Found in lib/miga/common/with_daemon.rb by rubocop

This cop checks for uses of Module#attr.

Example:

# bad - creates a single attribute accessor (deprecated in Ruby 1.9)
attr :something, true
attr :one, :two, :three # behaves as attr_reader

# good
attr_accessor :something
attr_reader :one, :two, :three

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

      raise "Trying to declare alive an active daemon, if you think this is a" \
Severity: Minor
Found in lib/miga/common/with_daemon.rb by rubocop

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 to_s over string interpolation.
Open

    Daemons.run_proc("#{daemon_name}", options) { while in_loop; end }
Severity: Minor
Found in lib/miga/common/with_daemon.rb by rubocop

This cop checks for strings that are just an interpolated expression.

Example:

# bad
"#{@var}"

# good
@var.to_s

# good if @var is already a String
@var

Unused method argument - wait. If it's necessary, use _ or _wait as an argument name to indicate that it won't be used. You can also write as status(*) if you want the method to accept any arguments but don't care about them.
Open

  def status(opts = [], wait = true)
Severity: Minor
Found in lib/miga/common/with_daemon.rb by rubocop

This cop checks for unused method arguments.

Example:

# bad

def some_method(used, unused, _unused_but_allowed)
  puts used
end

Example:

# good

def some_method(used, _unused, _unused_but_allowed)
  puts used
end

Missing magic comment # frozen_string_literal: true.
Open

require 'daemons'
Severity: Minor
Found in lib/miga/common/with_daemon.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

There are no issues that match your filters.

Category
Status