Method has too many lines. [39/10] Open
def self.included(klass)
# each topic or content item lives in exactly one basket
klass.send :belongs_to, :basket
klass.send :scope, :in_basket, lambda { |basket| { conditions: { basket_id: basket } } }
- 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.
Assignment Branch Condition size for included is too high. [26.02/15] Open
def self.included(klass)
# each topic or content item lives in exactly one basket
klass.send :belongs_to, :basket
klass.send :scope, :in_basket, lambda { |basket| { conditions: { basket_id: basket } } }
- Read upRead up
- Exclude checks
This cop checks that the ABC size of methods is not higher than the configured maximum. The ABC size is based on assignments, branches (method calls), and conditions. See http://c2.com/cgi/wiki?AbcMetric
Method included
has 39 lines of code (exceeds 25 allowed). Consider refactoring. Open
def self.included(klass)
# each topic or content item lives in exactly one basket
klass.send :belongs_to, :basket
klass.send :scope, :in_basket, lambda { |basket| { conditions: { basket_id: basket } } }
Pass __FILE__
and __LINE__
to eval
method, as they are used by backtraces. Open
Module.class_eval("#{klass.name}::Version").class_eval <<-RUBY
- Read upRead up
- Exclude checks
This cop checks eval
method usage. eval
can receive source location
metadata, that are filename and line number. The metadata is used by
backtraces. This cop recommends to pass the metadata to eval
method.
Example:
# bad
eval <<-RUBY
def do_something
end
RUBY
# bad
C.class_eval <<-RUBY
def do_something
end
RUBY
# good
eval <<-RUBY, binding, __FILE__, __LINE__ + 1
def do_something
end
RUBY
# good
C.class_eval <<-RUBY, __FILE__, __LINE__ + 1
def do_something
end
RUBY
Use the -> { ... }
lambda literal syntax for single line lambdas. Open
klass.send :scope, :in_basket, lambda { |basket| { conditions: { basket_id: basket } } }
- Read upRead up
- Exclude checks
This cop (by default) checks for uses of the lambda literal syntax for single line lambdas, and the method call syntax for multiline lambdas. It is configurable to enforce one of the styles for both single line and multiline lambdas as well.
Example: EnforcedStyle: linecountdependent (default)
# bad
f = lambda { |x| x }
f = ->(x) do
x
end
# good
f = ->(x) { x }
f = lambda do |x|
x
end
Example: EnforcedStyle: lambda
# bad
f = ->(x) { x }
f = ->(x) do
x
end
# good
f = lambda { |x| x }
f = lambda do |x|
x
end
Example: EnforcedStyle: literal
# bad
f = lambda { |x| x }
f = lambda do |x|
x
end
# good
f = ->(x) { x }
f = ->(x) do
x
end
Pass __FILE__
and __LINE__
to eval
method, as they are used by backtraces. Open
Module.class_eval("#{klass.name}::Version").class_eval <<-RUBY
- Read upRead up
- Exclude checks
This cop checks eval
method usage. eval
can receive source location
metadata, that are filename and line number. The metadata is used by
backtraces. This cop recommends to pass the metadata to eval
method.
Example:
# bad
eval <<-RUBY
def do_something
end
RUBY
# bad
C.class_eval <<-RUBY
def do_something
end
RUBY
# good
eval <<-RUBY, binding, __FILE__, __LINE__ + 1
def do_something
end
RUBY
# good
C.class_eval <<-RUBY, __FILE__, __LINE__ + 1
def do_something
end
RUBY
Use a guard clause instead of wrapping the code inside a conditional expression. Open
if old_basket_id != basket_id
- 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