tomlobato/sys_watchdog

View on GitHub
lib/sys_watchdog/setup.rb

Summary

Maintainability
A
0 mins
Test Coverage

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

class Setup
  SYSTEMD_SERVICES_DIR = "/lib/systemd/system/"
  SYSTEMD_SERVICE_FILE = "#{SYSTEMD_SERVICES_DIR}/sys-watchdog.service"

  def initialize
Severity: Minor
Found in lib/sys_watchdog/setup.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.

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

  def setup
    check_root
    copy_sample_conf
    create_working_dir
    install_type = get_install_type
Severity: Minor
Found in lib/sys_watchdog/setup.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 install_systemd_service
    if `which systemctl`.strip.empty?
      STDERR.puts "SysWatchdog install requires systemctl. Aborting."
      exit 1
    end
Severity: Minor
Found in lib/sys_watchdog/setup.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 uninstall
    stop
    File.delete SysWatchdog::DEFAULT_CONF_FILE
    if File.exist?(SYSTEMD_SERVICE_FILE)
      run 'systemctl disable sys-watchdog'
Severity: Minor
Found in lib/sys_watchdog/setup.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.

Final newline missing.
Open

end
Severity: Minor
Found in lib/sys_watchdog/setup.rb by rubocop

Use def with parentheses when there are parameters.
Open

  def save_install_type install_type
Severity: Minor
Found in lib/sys_watchdog/setup.rb by rubocop

This cops checks for parentheses around the arguments in method definitions. Both instance and class/singleton methods are checked.

Example: EnforcedStyle: require_parentheses (default)

# The `require_parentheses` style requires method definitions
# to always use parentheses

# bad
def bar num1, num2
  num1 + num2
end

def foo descriptive_var_name,
        another_descriptive_var_name,
        last_descriptive_var_name
  do_something
end

# good
def bar(num1, num2)
  num1 + num2
end

def foo(descriptive_var_name,
        another_descriptive_var_name,
        last_descriptive_var_name)
  do_something
end

Example: EnforcedStyle: requirenoparentheses

# The `require_no_parentheses` style requires method definitions
# to never use parentheses

# bad
def bar(num1, num2)
  num1 + num2
end

def foo(descriptive_var_name,
        another_descriptive_var_name,
        last_descriptive_var_name)
  do_something
end

# good
def bar num1, num2
  num1 + num2
end

def foo descriptive_var_name,
        another_descriptive_var_name,
        last_descriptive_var_name
  do_something
end

Example: EnforcedStyle: requirenoparenthesesexceptmultiline

# The `require_no_parentheses_except_multiline` style prefers no
# parantheses when method definition arguments fit on single line,
# but prefers parantheses when arguments span multiple lines.

# bad
def bar(num1, num2)
  num1 + num2
end

def foo descriptive_var_name,
        another_descriptive_var_name,
        last_descriptive_var_name
  do_something
end

# good
def bar num1, num2
  num1 + num2
end

def foo(descriptive_var_name,
        another_descriptive_var_name,
        last_descriptive_var_name)
  do_something
end

Trailing whitespace detected.
Open

  
Severity: Minor
Found in lib/sys_watchdog/setup.rb by rubocop

Use 0o for octal literals.
Open

  def copy from, to, mod = 0600
Severity: Minor
Found in lib/sys_watchdog/setup.rb by rubocop

This cop checks for octal, hex, binary and decimal literals using uppercase prefixes and corrects them to lowercase prefix or no prefix (in case of decimals). eg. for octal use 0o instead of 0 or 0O.

Can be configured to use 0 only for octal literals using EnforcedOctalStyle => zero_only

Trailing whitespace detected.
Open

    File.exist?(`which systemctl`.strip) && 
Severity: Minor
Found in lib/sys_watchdog/setup.rb by rubocop

Do not prefix reader method names with get_.
Open

  def get_install_type
Severity: Minor
Found in lib/sys_watchdog/setup.rb by rubocop

This cop makes sure that accessor methods are named properly.

Example:

# bad
def set_attribute(value)
end

# good
def attribute=(value)
end

# bad
def get_attribute
end

# good
def attribute
end

Line is too long. [81/80]
Open

    (File.exist?(SysWatchdog::CRONJOB_PATH) || File.exist?(SYSTEMD_SERVICE_FILE))
Severity: Minor
Found in lib/sys_watchdog/setup.rb by rubocop

Line is too long. [95/80]
Open

      STDERR.puts "Install requires root privileges. Run with sudo or login as root. Aborting."
Severity: Minor
Found in lib/sys_watchdog/setup.rb by rubocop

Use a guard clause instead of wrapping the code inside a conditional expression.
Open

    unless Process.uid == 0
Severity: Minor
Found in lib/sys_watchdog/setup.rb by rubocop

Use a guard clause instead of wrapping the code inside a conditional expression

Example:

# bad
def test
  if something
    work
  end
end

# good
def test
  return unless something
  work
end

# also good
def test
  work if something
end

# bad
if something
  raise 'exception'
else
  ok
end

# good
raise 'exception' if something
ok

Use 2 (not 0) spaces for indenting an expression spanning multiple lines.
Open

    File.writable?('/lib/systemd/system')
Severity: Minor
Found in lib/sys_watchdog/setup.rb by rubocop

This cop checks the indentation of the right hand side operand in binary operations that span more than one line.

Example:

# bad
if a +
b
  something
end

# good
if a +
   b
  something
end

Line is too long. [84/80]
Open

               "#* *   * * * root /bin/bash -lc 'sys_watchdog once' >> /etc/crontab"
Severity: Minor
Found in lib/sys_watchdog/setup.rb by rubocop

Use def with parentheses when there are parameters.
Open

  def run cmd
Severity: Minor
Found in lib/sys_watchdog/setup.rb by rubocop

This cops checks for parentheses around the arguments in method definitions. Both instance and class/singleton methods are checked.

Example: EnforcedStyle: require_parentheses (default)

# The `require_parentheses` style requires method definitions
# to always use parentheses

# bad
def bar num1, num2
  num1 + num2
end

def foo descriptive_var_name,
        another_descriptive_var_name,
        last_descriptive_var_name
  do_something
end

# good
def bar(num1, num2)
  num1 + num2
end

def foo(descriptive_var_name,
        another_descriptive_var_name,
        last_descriptive_var_name)
  do_something
end

Example: EnforcedStyle: requirenoparentheses

# The `require_no_parentheses` style requires method definitions
# to never use parentheses

# bad
def bar(num1, num2)
  num1 + num2
end

def foo(descriptive_var_name,
        another_descriptive_var_name,
        last_descriptive_var_name)
  do_something
end

# good
def bar num1, num2
  num1 + num2
end

def foo descriptive_var_name,
        another_descriptive_var_name,
        last_descriptive_var_name
  do_something
end

Example: EnforcedStyle: requirenoparenthesesexceptmultiline

# The `require_no_parentheses_except_multiline` style prefers no
# parantheses when method definition arguments fit on single line,
# but prefers parantheses when arguments span multiple lines.

# bad
def bar(num1, num2)
  num1 + num2
end

def foo descriptive_var_name,
        another_descriptive_var_name,
        last_descriptive_var_name
  do_something
end

# good
def bar num1, num2
  num1 + num2
end

def foo(descriptive_var_name,
        another_descriptive_var_name,
        last_descriptive_var_name)
  do_something
end

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

    puts "Now:"
Severity: Minor
Found in lib/sys_watchdog/setup.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"

Trailing whitespace detected.
Open

    copy "#{@thisdir}/../../util/sys-watchdog.service", 
Severity: Minor
Found in lib/sys_watchdog/setup.rb by rubocop

Line is too long. [191/80]
Open

    puts "1) Edit #{SysWatchdog::DEFAULT_CONF_FILE} to customize your system tests. You can run 'sys_watchdog test' to adjust your system tests and get a grasp of the sys_watchdog operation."
Severity: Minor
Found in lib/sys_watchdog/setup.rb by rubocop

Rename is_setup? to setup?.
Open

  def is_setup?
Severity: Minor
Found in lib/sys_watchdog/setup.rb by rubocop

This cop makes sure that predicates are named properly.

Example:

# bad
def is_even?(value)
end

# good
def even?(value)
end

# bad
def has_value?
end

# good
def value?
end

Use def with parentheses when there are parameters.
Open

  def copy from, to, mod = 0600
Severity: Minor
Found in lib/sys_watchdog/setup.rb by rubocop

This cops checks for parentheses around the arguments in method definitions. Both instance and class/singleton methods are checked.

Example: EnforcedStyle: require_parentheses (default)

# The `require_parentheses` style requires method definitions
# to always use parentheses

# bad
def bar num1, num2
  num1 + num2
end

def foo descriptive_var_name,
        another_descriptive_var_name,
        last_descriptive_var_name
  do_something
end

# good
def bar(num1, num2)
  num1 + num2
end

def foo(descriptive_var_name,
        another_descriptive_var_name,
        last_descriptive_var_name)
  do_something
end

Example: EnforcedStyle: requirenoparentheses

# The `require_no_parentheses` style requires method definitions
# to never use parentheses

# bad
def bar(num1, num2)
  num1 + num2
end

def foo(descriptive_var_name,
        another_descriptive_var_name,
        last_descriptive_var_name)
  do_something
end

# good
def bar num1, num2
  num1 + num2
end

def foo descriptive_var_name,
        another_descriptive_var_name,
        last_descriptive_var_name
  do_something
end

Example: EnforcedStyle: requirenoparenthesesexceptmultiline

# The `require_no_parentheses_except_multiline` style prefers no
# parantheses when method definition arguments fit on single line,
# but prefers parantheses when arguments span multiple lines.

# bad
def bar(num1, num2)
  num1 + num2
end

def foo descriptive_var_name,
        another_descriptive_var_name,
        last_descriptive_var_name
  do_something
end

# good
def bar num1, num2
  num1 + num2
end

def foo(descriptive_var_name,
        another_descriptive_var_name,
        last_descriptive_var_name)
  do_something
end

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

    puts "Uninstall complete."
Severity: Minor
Found in lib/sys_watchdog/setup.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"

Line is too long. [87/80]
Open

      STDERR.puts "SysWatchdog install requires dir #{SYSTEMD_SERVICES_DIR}. Aborting."
Severity: Minor
Found in lib/sys_watchdog/setup.rb by rubocop

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

      STDERR.puts "SysWatchdog install requires systemctl. Aborting."
Severity: Minor
Found in lib/sys_watchdog/setup.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"

Freeze mutable objects assigned to constants.
Open

  SYSTEMD_SERVICES_DIR = "/lib/systemd/system/"
Severity: Minor
Found in lib/sys_watchdog/setup.rb by rubocop

This cop checks whether some constant value isn't a mutable literal (e.g. array or hash).

Example:

# bad
CONST = [1, 2, 3]

# good
CONST = [1, 2, 3].freeze

Trailing whitespace detected.
Open

    File.write SysWatchdog::CRONJOB_PATH, 
Severity: Minor
Found in lib/sys_watchdog/setup.rb by rubocop

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

  SYSTEMD_SERVICES_DIR = "/lib/systemd/system/"
Severity: Minor
Found in lib/sys_watchdog/setup.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"

Missing top-level class documentation comment.
Open

class Setup
Severity: Minor
Found in lib/sys_watchdog/setup.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

Extra empty line detected at class body end.
Open


end
Severity: Minor
Found in lib/sys_watchdog/setup.rb by rubocop

This cops checks if empty lines around the bodies of classes match the configuration.

Example: EnforcedStyle: empty_lines

# good

class Foo

  def bar
    # ...
  end

end

Example: EnforcedStyle: emptylinesexcept_namespace

# good

class Foo
  class Bar

    # ...

  end
end

Example: EnforcedStyle: emptylinesspecial

# good
class Foo

  def bar; end

end

Example: EnforcedStyle: noemptylines (default)

# good

class Foo
  def bar
    # ...
  end
end

Trailing whitespace detected.
Open

    copy "#{@thisdir}/../../util/sys_watchdog_sample.yml", 
Severity: Minor
Found in lib/sys_watchdog/setup.rb by rubocop

Freeze mutable objects assigned to constants.
Open

  SYSTEMD_SERVICE_FILE = "#{SYSTEMD_SERVICES_DIR}/sys-watchdog.service"
Severity: Minor
Found in lib/sys_watchdog/setup.rb by rubocop

This cop checks whether some constant value isn't a mutable literal (e.g. array or hash).

Example:

# bad
CONST = [1, 2, 3]

# good
CONST = [1, 2, 3].freeze

Use Process.uid.zero? instead of Process.uid == 0.
Open

    unless Process.uid == 0
Severity: Minor
Found in lib/sys_watchdog/setup.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

Use 2 (not 0) spaces for indenting an expression spanning multiple lines.
Open

    (File.exist?(SysWatchdog::CRONJOB_PATH) || File.exist?(SYSTEMD_SERVICE_FILE))
Severity: Minor
Found in lib/sys_watchdog/setup.rb by rubocop

This cop checks the indentation of the right hand side operand in binary operations that span more than one line.

Example:

# bad
if a +
b
  something
end

# good
if a +
   b
  something
end

Trailing whitespace detected.
Open

    
Severity: Minor
Found in lib/sys_watchdog/setup.rb by rubocop

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

      STDERR.puts "Install requires root privileges. Run with sudo or login as root. Aborting."
Severity: Minor
Found in lib/sys_watchdog/setup.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"

Align the parameters of a method call if they span more than one line.
Open

          SysWatchdog::DEFAULT_CONF_FILE
Severity: Minor
Found in lib/sys_watchdog/setup.rb by rubocop

Here we check if the parameters on a multi-line method call or definition are aligned.

Example: EnforcedStyle: withfirstparameter (default)

# good

foo :bar,
    :baz

# bad

foo :bar,
  :baz

Example: EnforcedStyle: withfixedindentation

# good

foo :bar,
  :baz

# bad

foo :bar,
    :baz

Rename has_systemd? to systemd?.
Open

  def has_systemd?
Severity: Minor
Found in lib/sys_watchdog/setup.rb by rubocop

This cop makes sure that predicates are named properly.

Example:

# bad
def is_even?(value)
end

# good
def even?(value)
end

# bad
def has_value?
end

# good
def value?
end

Missing magic comment # frozen_string_literal: true.
Open


class Setup
Severity: Minor
Found in lib/sys_watchdog/setup.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

Use def with parentheses when there are parameters.
Open

  def rewrite_cronjob enable
Severity: Minor
Found in lib/sys_watchdog/setup.rb by rubocop

This cops checks for parentheses around the arguments in method definitions. Both instance and class/singleton methods are checked.

Example: EnforcedStyle: require_parentheses (default)

# The `require_parentheses` style requires method definitions
# to always use parentheses

# bad
def bar num1, num2
  num1 + num2
end

def foo descriptive_var_name,
        another_descriptive_var_name,
        last_descriptive_var_name
  do_something
end

# good
def bar(num1, num2)
  num1 + num2
end

def foo(descriptive_var_name,
        another_descriptive_var_name,
        last_descriptive_var_name)
  do_something
end

Example: EnforcedStyle: requirenoparentheses

# The `require_no_parentheses` style requires method definitions
# to never use parentheses

# bad
def bar(num1, num2)
  num1 + num2
end

def foo(descriptive_var_name,
        another_descriptive_var_name,
        last_descriptive_var_name)
  do_something
end

# good
def bar num1, num2
  num1 + num2
end

def foo descriptive_var_name,
        another_descriptive_var_name,
        last_descriptive_var_name
  do_something
end

Example: EnforcedStyle: requirenoparenthesesexceptmultiline

# The `require_no_parentheses_except_multiline` style prefers no
# parantheses when method definition arguments fit on single line,
# but prefers parantheses when arguments span multiple lines.

# bad
def bar(num1, num2)
  num1 + num2
end

def foo descriptive_var_name,
        another_descriptive_var_name,
        last_descriptive_var_name
  do_something
end

# good
def bar num1, num2
  num1 + num2
end

def foo(descriptive_var_name,
        another_descriptive_var_name,
        last_descriptive_var_name)
  do_something
end

There are no issues that match your filters.

Category
Status