Assignment Branch Condition size for define_reader_method_for is too high. [15.43/15] Open
def define_reader_method_for(setting)
method_name = setting.constant_name.downcase
class_variable_set('@@' + method_name, setting.constant_value)
- 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
Use each_value
instead of each
. Open
extensions[:blocks].each do |key, procs|
- Read upRead up
- Exclude checks
This cop checks for uses of each_key
and each_value
Hash methods.
Note: If you have an array of two-element arrays, you can put parentheses around the block arguments to indicate that you're not working with a hash, and suppress RuboCop offenses.
Example:
# bad
hash.keys.each { |k| p k }
hash.values.each { |v| p v }
hash.each { |k, _v| p k }
hash.each { |_k, v| p v }
# good
hash.each_key { |k| p k }
hash.each_value { |v| p v }
Use a guard clause instead of wrapping the code inside a conditional expression. Open
if eval_value.kind_of?(TrueClass) || eval_value.kind_of?(FalseClass)
- 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
Prefer Object#is_a?
over Object#kind_of?
. Open
if eval_value.kind_of?(TrueClass) || eval_value.kind_of?(FalseClass)
- Read upRead up
- Exclude checks
This cop enforces consistent use of Object#is_a?
or Object#kind_of?
.
Example: EnforcedStyle: is_a? (default)
# bad
var.kind_of?(Date)
var.kind_of?(Integer)
# good
var.is_a?(Date)
var.is_a?(Integer)
Example: EnforcedStyle: kind_of?
# bad
var.is_a?(Time)
var.is_a?(String)
# good
var.kind_of?(Time)
var.kind_of?(String)
Prefer Object#is_a?
over Object#kind_of?
. Open
if value.kind_of?(TrueClass) || value.kind_of?(FalseClass)
- Read upRead up
- Exclude checks
This cop enforces consistent use of Object#is_a?
or Object#kind_of?
.
Example: EnforcedStyle: is_a? (default)
# bad
var.kind_of?(Date)
var.kind_of?(Integer)
# good
var.is_a?(Date)
var.is_a?(Integer)
Example: EnforcedStyle: kind_of?
# bad
var.is_a?(Time)
var.is_a?(String)
# good
var.kind_of?(Time)
var.kind_of?(String)
Prefer Object#is_a?
over Object#kind_of?
. Open
if value.kind_of?(TrueClass) || value.kind_of?(FalseClass)
- Read upRead up
- Exclude checks
This cop enforces consistent use of Object#is_a?
or Object#kind_of?
.
Example: EnforcedStyle: is_a? (default)
# bad
var.kind_of?(Date)
var.kind_of?(Integer)
# good
var.is_a?(Date)
var.is_a?(Integer)
Example: EnforcedStyle: kind_of?
# bad
var.is_a?(Time)
var.is_a?(String)
# good
var.kind_of?(Time)
var.kind_of?(String)
Replace class var @@extensions with a class instance var. Open
@@extensions ||= { blocks: nil }
- Read upRead up
- Exclude checks
This cop checks for uses of class variables. Offenses are signaled only on assignment to class variables to reduce the number of offenses that would be reported.
Use proc
instead of Proc.new
. Open
Proc.new do
- Read upRead up
- Exclude checks
This cops checks for uses of Proc.new where Kernel#proc would be more appropriate.
Example:
# bad
p = Proc.new { |n| puts n }
# good
p = proc { |n| puts n }
Unused block argument - key
. If it's necessary, use _
or _key
as an argument name to indicate that it won't be used. Open
extensions[:blocks].each do |key, procs|
- Read upRead up
- Exclude checks
This cop checks for unused block arguments.
Example:
# bad
do_something do |used, unused|
puts used
end
do_something do |bar|
puts :foo
end
define_method(:foo) do |bar|
puts :baz
end
Example:
#good
do_something do |used, _unused|
puts used
end
do_something do
puts :foo
end
define_method(:foo) do |_bar|
puts :baz
end
Prefer Object#is_a?
over Object#kind_of?
. Open
if eval_value.kind_of?(TrueClass) || eval_value.kind_of?(FalseClass)
- Read upRead up
- Exclude checks
This cop enforces consistent use of Object#is_a?
or Object#kind_of?
.
Example: EnforcedStyle: is_a? (default)
# bad
var.kind_of?(Date)
var.kind_of?(Integer)
# good
var.is_a?(Date)
var.is_a?(Integer)
Example: EnforcedStyle: kind_of?
# bad
var.is_a?(Time)
var.is_a?(String)
# good
var.kind_of?(Time)
var.kind_of?(String)
Use a guard clause instead of wrapping the code inside a conditional expression. Open
if value.kind_of?(TrueClass) || value.kind_of?(FalseClass)
- 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
Use proc
instead of Proc.new
. Open
Proc.new do
- Read upRead up
- Exclude checks
This cops checks for uses of Proc.new where Kernel#proc would be more appropriate.
Example:
# bad
p = Proc.new { |n| puts n }
# good
p = proc { |n| puts n }
Replace class var @@extensions with a class instance var. Open
@@extensions = extensions
- Read upRead up
- Exclude checks
This cop checks for uses of class variables. Offenses are signaled only on assignment to class variables to reduce the number of offenses that would be reported.
Pass &:call
as an argument to each
instead of a block. Open
procs.each { |proc| proc.call }
- Read upRead up
- Exclude checks
Use symbols as procs when possible.
Example:
# bad
something.map { |s| s.upcase }
# good
something.map(&:upcase)