Method has too many lines. [23/10] Open
def self.included(klass)
klass.send :has_many, :contributions, as: :contributed_item, dependent: :destroy
# :select => "distinct contributions.role, users.*",
# creator is intended to be just one, but we need :through functionality
klass.send :has_many, :creators, through: :contributions,
- 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 has too many lines. [19/10] Open
def submitter_of(version)
submitter = nil
if version == 1
submitter = creator
else
- 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 creator=
has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring. Open
def creator=(user)
creators << user
if user.present? && user.anonymous?
contribution = contributions.find_by_version(1)
contribution.email_for_anonymous = user.email
- 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
Method creator
has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring. Open
def creator
creator = creators.first
if creator.present? && creator.anonymous?
contribution = contributions.find_by_version(1)
- 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
Method submitter_of
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
def submitter_of(version)
submitter = nil
if version == 1
submitter = creator
else
- 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: assumes user has a version method (virtual attribute on user set before this is called)
- Exclude checks
Avoid rescuing without specifying an error class. Open
rescue
- Read upRead up
- Exclude checks
This cop checks for rescuing StandardError
. There are two supported
styles implicit
and explicit
. This cop will not register an offense
if any error other than StandardError
is specified.
Example: EnforcedStyle: implicit
# `implicit` will enforce using `rescue` instead of
# `rescue StandardError`.
# bad
begin
foo
rescue StandardError
bar
end
# good
begin
foo
rescue
bar
end
# good
begin
foo
rescue OtherError
bar
end
# good
begin
foo
rescue StandardError, SecurityError
bar
end
Example: EnforcedStyle: explicit (default)
# `explicit` will enforce using `rescue StandardError`
# instead of `rescue`.
# bad
begin
foo
rescue
bar
end
# good
begin
foo
rescue StandardError
bar
end
# good
begin
foo
rescue OtherError
bar
end
# good
begin
foo
rescue StandardError, SecurityError
bar
end
Method definitions must not be nested. Use lambda
instead. Open
def <<(user)
# TODO: assumes user has a version method (virtual attribute on user set before this is called)
Contribution.add_as_to(user, 'contributor', self)
rescue
- Read upRead up
- Exclude checks
This cop checks for nested method definitions.
Example:
# bad
# `bar` definition actually produces methods in the same scope
# as the outer `foo` method. Furthermore, the `bar` method
# will be redefined every time `foo` is invoked.
def foo
def bar
end
end
Example:
# good
def foo
bar = -> { puts 'hello' }
bar.call
end
Example:
# good
def foo
self.class_eval do
def bar
end
end
end
def foo
self.module_exec do
def bar
end
end
end
Example:
# good
def foo
class << self
def bar
end
end
end
Prefer $ERROR_INFO
from the stdlib 'English' module (don't forget to require it) over $!
. Open
logger.debug('what is contrib error: ' + $!.to_s)
- Exclude checks
Use a guard clause instead of wrapping the code inside a conditional expression. Open
if user.present? && user.anonymous?
- Read upRead up
- Exclude checks
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
Method definitions must not be nested. Use lambda
instead. Open
def <<(user)
user.version = 1
Contribution.add_as_to(user, 'creator', self)
rescue
logger.debug('what is contrib error: ' + $!.to_s)
- Read upRead up
- Exclude checks
This cop checks for nested method definitions.
Example:
# bad
# `bar` definition actually produces methods in the same scope
# as the outer `foo` method. Furthermore, the `bar` method
# will be redefined every time `foo` is invoked.
def foo
def bar
end
end
Example:
# good
def foo
bar = -> { puts 'hello' }
bar.call
end
Example:
# good
def foo
self.class_eval do
def bar
end
end
end
def foo
self.module_exec do
def bar
end
end
end
Example:
# good
def foo
class << self
def bar
end
end
end
Avoid rescuing without specifying an error class. Open
rescue
- Read upRead up
- Exclude checks
This cop checks for rescuing StandardError
. There are two supported
styles implicit
and explicit
. This cop will not register an offense
if any error other than StandardError
is specified.
Example: EnforcedStyle: implicit
# `implicit` will enforce using `rescue` instead of
# `rescue StandardError`.
# bad
begin
foo
rescue StandardError
bar
end
# good
begin
foo
rescue
bar
end
# good
begin
foo
rescue OtherError
bar
end
# good
begin
foo
rescue StandardError, SecurityError
bar
end
Example: EnforcedStyle: explicit (default)
# `explicit` will enforce using `rescue StandardError`
# instead of `rescue`.
# bad
begin
foo
rescue
bar
end
# good
begin
foo
rescue StandardError
bar
end
# good
begin
foo
rescue OtherError
bar
end
# good
begin
foo
rescue StandardError, SecurityError
bar
end
Avoid rescuing without specifying an error class. Open
rescue
- Read upRead up
- Exclude checks
This cop checks for rescuing StandardError
. There are two supported
styles implicit
and explicit
. This cop will not register an offense
if any error other than StandardError
is specified.
Example: EnforcedStyle: implicit
# `implicit` will enforce using `rescue` instead of
# `rescue StandardError`.
# bad
begin
foo
rescue StandardError
bar
end
# good
begin
foo
rescue
bar
end
# good
begin
foo
rescue OtherError
bar
end
# good
begin
foo
rescue StandardError, SecurityError
bar
end
Example: EnforcedStyle: explicit (default)
# `explicit` will enforce using `rescue StandardError`
# instead of `rescue`.
# bad
begin
foo
rescue
bar
end
# good
begin
foo
rescue StandardError
bar
end
# good
begin
foo
rescue OtherError
bar
end
# good
begin
foo
rescue StandardError, SecurityError
bar
end
Prefer $ERROR_INFO
from the stdlib 'English' module (don't forget to require it) over $!
. Open
logger.debug('what is contrib error: ' + $!.to_s)
- Exclude checks