reevoo/sapience-rb

View on GitHub
lib/sapience/formatters/base.rb

Summary

Maintainability
A
1 hr
Test Coverage

Method parse_options has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
Open

      def parse_options(options)
        @time_format     = options.key?(:time_format) ? options.delete(:time_format) : default_time_format
        @log_host        = options.key?(:log_host) ? options.delete(:log_host) : true
        @log_application = options.key?(:log_application) ? options.delete(:log_application) : true
        @exclude_fields  = options.key?(:exclude_fields) ? options.delete(:exclude_fields).map(&:to_sym) : {}
Severity: Minor
Found in lib/sapience/formatters/base.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

Line is too long. [106/80]
Open

        @time_format     = options.key?(:time_format) ? options.delete(:time_format) : default_time_format
Severity: Minor
Found in lib/sapience/formatters/base.rb by rubocop

Line is too long. [88/80]
Open

        fail(ArgumentError, "Unknown options: #{options.inspect}") unless options.empty?
Severity: Minor
Found in lib/sapience/formatters/base.rb by rubocop

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

          ""
Severity: Minor
Found in lib/sapience/formatters/base.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 Base
Severity: Minor
Found in lib/sapience/formatters/base.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

Line is too long. [109/80]
Open

        @exclude_fields  = options.key?(:exclude_fields) ? options.delete(:exclude_fields).map(&:to_sym) : {}
Severity: Minor
Found in lib/sapience/formatters/base.rb by rubocop

Add an empty line after magic comments.
Open

module Sapience
Severity: Minor
Found in lib/sapience/formatters/base.rb by rubocop

Checks for a newline after the final magic comment.

Example:

# good
# frozen_string_literal: true

# Some documentation for Person
class Person
  # Some code
end

# bad
# frozen_string_literal: true
# Some documentation for Person
class Person
  # Some code
end

Line is too long. [85/80]
Open

        @log_host        = options.key?(:log_host) ? options.delete(:log_host) : true
Severity: Minor
Found in lib/sapience/formatters/base.rb by rubocop

Always use raise to signal exceptions.
Open

        fail(ArgumentError, "Unknown options: #{options.inspect}") unless options.empty?
Severity: Minor
Found in lib/sapience/formatters/base.rb by rubocop

This cop checks for uses of fail and raise.

Example: EnforcedStyle: only_raise (default)

# The `only_raise` style enforces the sole use of `raise`.
# bad
begin
  fail
rescue Exception
  # handle it
end

def watch_out
  fail
rescue Exception
  # handle it
end

Kernel.fail

# good
begin
  raise
rescue Exception
  # handle it
end

def watch_out
  raise
rescue Exception
  # handle it
end

Kernel.raise

Example: EnforcedStyle: only_fail

# The `only_fail` style enforces the sole use of `fail`.
# bad
begin
  raise
rescue Exception
  # handle it
end

def watch_out
  raise
rescue Exception
  # handle it
end

Kernel.raise

# good
begin
  fail
rescue Exception
  # handle it
end

def watch_out
  fail
rescue Exception
  # handle it
end

Kernel.fail

Example: EnforcedStyle: semantic

# The `semantic` style enforces the use of `fail` to signal an
# exception, then will use `raise` to trigger an offense after
# it has been rescued.
# bad
begin
  raise
rescue Exception
  # handle it
end

def watch_out
  # Error thrown
rescue Exception
  fail
end

Kernel.fail
Kernel.raise

# good
begin
  fail
rescue Exception
  # handle it
end

def watch_out
  fail
rescue Exception
  raise 'Preferably with descriptive message'
end

explicit_receiver.fail
explicit_receiver.raise

Line is too long. [99/80]
Open

        @log_application = options.key?(:log_application) ? options.delete(:log_application) : true
Severity: Minor
Found in lib/sapience/formatters/base.rb by rubocop

Line is too long. [112/80]
Open

      attr_accessor :time_format, :default_time_format, :precision, :log_host, :log_application, :exclude_fields
Severity: Minor
Found in lib/sapience/formatters/base.rb by rubocop

There are no issues that match your filters.

Category
Status