Method has too many lines. [14/10] Open
def extract_formatter(formatter, &block)
if formatter.is_a?(Symbol) || formatter.is_a?(String)
Sapience.constantize_symbol(formatter, "Sapience::Formatters").new
elsif formatter.is_a?(Hash) && !formatter.empty?
fmt, options = formatter.first
- Read upRead up
- Exclude checks
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 extract_formatter
has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring. Open
def extract_formatter(formatter, &block)
if formatter.is_a?(Symbol) || formatter.is_a?(String)
Sapience.constantize_symbol(formatter, "Sapience::Formatters").new
elsif formatter.is_a?(Hash) && !formatter.empty?
fmt, options = formatter.first
- Read upRead up
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
TODO found Open
# TODO: Check this valid? method before using appender, output above error message if not valid?
- Exclude checks
TODO found Open
# TODO: Implement a format string with class name and interesting values
- Exclude checks
TODO found Open
# TODO: Wait with adding appenders until they are needed solve this by below
- Exclude checks
TODO found Open
# TODO: Output relevant message when appender isn't valid
- Exclude checks
TODO found Open
# TODO: Implement this mehtod in all appenders
- Exclude checks
TODO found Open
# TODO: Implement possibility of finding and deleting appenders by env
- Exclude checks
Always use raise
to signal exceptions. Open
fail(ArgumentError, "Unknown options: #{options.inspect}") unless options.empty?
- Read upRead up
- Exclude checks
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
fail NotImplementedError, "needs to be implemented in appender"
- Read upRead up
- Exclude checks
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
Sapience.constantize_symbol(formatter, "Sapience::Formatters").new
- Read upRead up
- Exclude checks
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. [86/80] Open
# An instance of a class that implements #call, or a Proc to be used to format
- Exclude checks
Add an empty line after magic comments. Open
# Abstract Subscriber
- Read upRead up
- Exclude checks
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. [100/80] Open
# TODO: Check this valid? method before using appender, output above error message if not valid?
- Exclude checks
Line is too long. [84/80] Open
Sapience.constantize_symbol(fmt.to_sym, "Sapience::Formatters").new(options)
- Exclude checks
Missing top-level class documentation comment. Open
class Subscriber < Sapience::Base
- Read upRead up
- Exclude checks
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. [84/80] Open
# Returns the current log level if set, otherwise it logs everything it receives
- Exclude checks
Always use raise
to signal exceptions. Open
fail NotImplementedError, "needs to be implemented in appender"
- Read upRead up
- Exclude checks
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. [84/80] Open
# Subscribers don't take a class name, so use this class name if an subscriber
- Exclude checks
Line is too long. [86/80] Open
fail(ArgumentError, "Unknown options: #{options.inspect}") unless options.empty?
- Exclude checks
Prefer single-quoted strings when you don't need string interpolation or special symbols. Open
Sapience.constantize_symbol(fmt.to_sym, "Sapience::Formatters").new(options)
- Read upRead up
- Exclude checks
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. [83/80] Open
# Returns [Sapience::Formatters::Default] formatter default for this subscriber
- Exclude checks
Line is too long. [89/80] Open
# - If none of the above apply, then the supplied block is returned as the formatter.
- Exclude checks
Line is too long. [86/80] Open
# RegExp: Only include log messages where the class name matches the supplied.
- Exclude checks