reevoo/sapience-rb

View on GitHub
lib/sapience/logger.rb

Summary

Maintainability
A
3 hrs
Test Coverage

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

    def log(log, message = nil, progname = nil, &block)
      # Compatibility with ::Logger
      return add(log, message, progname, &block) unless log.is_a?(Sapience::Log)
      if @@appender_thread
        @@appender_thread << lambda do
Severity: Minor
Found in lib/sapience/logger.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. [13/10]
Open

    def self.flush # rubocop:disable AbcSize
      return unless appender_thread
      appender_thread << lambda do
        Sapience.appenders.each do |appender|
          next unless appender.valid?
Severity: Minor
Found in lib/sapience/logger.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 self.close
      return unless appender_thread
      appender_thread << lambda do
        Sapience.appenders.each do |appender|
          next unless appender.valid?
Severity: Minor
Found in lib/sapience/logger.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 log has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
Open

    def log(log, message = nil, progname = nil, &block)
      # Compatibility with ::Logger
      return add(log, message, progname, &block) unless log.is_a?(Sapience::Log)
      if @@appender_thread
        @@appender_thread << lambda do
Severity: Minor
Found in lib/sapience/logger.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 flush has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
Open

    def self.flush # rubocop:disable AbcSize
      return unless appender_thread
      appender_thread << lambda do
        Sapience.appenders.each do |appender|
          next unless appender.valid?
Severity: Minor
Found in lib/sapience/logger.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 close has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
Open

    def self.close
      return unless appender_thread
      appender_thread << lambda do
        Sapience.appenders.each do |appender|
          next unless appender.valid?
Severity: Minor
Found in lib/sapience/logger.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. [107/80]
Open

      @@invalid_appenders_task = Concurrent::TimerTask.new(execution_interval: 120, timeout_interval: 5) do
Severity: Minor
Found in lib/sapience/logger.rb by rubocop

Line is too long. [91/80]
Open

          logger.warn { "#{appender.class} is not valid. #{appender::VALIDATION_MESSAGE}" }
Severity: Minor
Found in lib/sapience/logger.rb by rubocop

Add an empty line after magic comments.
Open

require "concurrent"
Severity: Minor
Found in lib/sapience/logger.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. [111/80]
Open

              $stderr.write("Appender thread: Failed to log to appender: #{appender.inspect}\n #{exc.inspect}")
Severity: Minor
Found in lib/sapience/logger.rb by rubocop

Line is too long. [111/80]
Open

            $stderr.write("Appender thread: Failed to flush to appender: #{appender.inspect}\n #{exc.inspect}")
Severity: Minor
Found in lib/sapience/logger.rb by rubocop

Always use raise to signal exceptions.
Open

      fail "Failed to start Appender Thread" unless @@appender_thread
Severity: Minor
Found in lib/sapience/logger.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

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

        logger.trace "Appender thread: All appenders flushed"
Severity: Minor
Found in lib/sapience/logger.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. [94/80]
Open

            logger.error "Appender thread: Failed to close appender: #{appender.inspect}", exc
Severity: Minor
Found in lib/sapience/logger.rb by rubocop

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

      if @@appender_thread
Severity: Minor
Found in lib/sapience/logger.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

Line is too long. [84/80]
Open

    #    RegExp: Only include log messages where the class name matches the supplied
Severity: Minor
Found in lib/sapience/logger.rb by rubocop

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

        logger.trace "Appender thread: All appenders flushed"
Severity: Minor
Found in lib/sapience/logger.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. [84/80]
Open

    #  All queued log messages are written and then each appender is flushed in turn
Severity: Minor
Found in lib/sapience/logger.rb by rubocop

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

require "concurrent"
Severity: Minor
Found in lib/sapience/logger.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 single-quoted strings when you don't need string interpolation or special symbols.
Open

      fail "Failed to start Appender Thread" unless @@appender_thread
Severity: Minor
Found in lib/sapience/logger.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. [85/80]
Open

            logger.trace "Appender thread: Flushing appender: #{appender.class.name}"
Severity: Minor
Found in lib/sapience/logger.rb by rubocop

There are no issues that match your filters.

Category
Status