Showing 70 of 70 total issues
Use include MoreCoreExtensions::ObjectDeepSend
instead of send(:include, MoreCoreExtensions::ObjectDeepSend)
. Open
Object.send(:include, MoreCoreExtensions::ObjectDeepSend)
- Read upRead up
- Exclude checks
Checks for send
, public_send
, and __send__
methods
when using mix-in.
include
and prepend
methods were private methods until Ruby 2.0,
they were mixed-in via send
method. This cop uses Ruby 2.1 or
higher style that can be called by public methods.
And extend
method that was originally a public method is also targeted
for style unification.
Example:
# bad
Foo.send(:include, Bar)
Foo.send(:prepend, Bar)
Foo.send(:extend, Bar)
# bad
Foo.public_send(:include, Bar)
Foo.public_send(:prepend, Bar)
Foo.public_send(:extend, Bar)
# bad
Foo.__send__(:include, Bar)
Foo.__send__(:prepend, Bar)
Foo.__send__(:extend, Bar)
# good
Foo.include Bar
Foo.prepend Bar
Foo.extend Bar
Use prepend MoreCoreExtensions::DecimalSI
instead of send(:prepend, MoreCoreExtensions::DecimalSI)
. Open
String.send(:prepend, MoreCoreExtensions::DecimalSI)
- Read upRead up
- Exclude checks
Checks for send
, public_send
, and __send__
methods
when using mix-in.
include
and prepend
methods were private methods until Ruby 2.0,
they were mixed-in via send
method. This cop uses Ruby 2.1 or
higher style that can be called by public methods.
And extend
method that was originally a public method is also targeted
for style unification.
Example:
# bad
Foo.send(:include, Bar)
Foo.send(:prepend, Bar)
Foo.send(:extend, Bar)
# bad
Foo.public_send(:include, Bar)
Foo.public_send(:prepend, Bar)
Foo.public_send(:extend, Bar)
# bad
Foo.__send__(:include, Bar)
Foo.__send__(:prepend, Bar)
Foo.__send__(:extend, Bar)
# good
Foo.include Bar
Foo.prepend Bar
Foo.extend Bar
Use include MoreCoreExtensions::SymbolToI
instead of send(:include, MoreCoreExtensions::SymbolToI)
. Open
Symbol.send(:include, MoreCoreExtensions::SymbolToI) unless Symbol.method_defined?(:to_i)
- Read upRead up
- Exclude checks
Checks for send
, public_send
, and __send__
methods
when using mix-in.
include
and prepend
methods were private methods until Ruby 2.0,
they were mixed-in via send
method. This cop uses Ruby 2.1 or
higher style that can be called by public methods.
And extend
method that was originally a public method is also targeted
for style unification.
Example:
# bad
Foo.send(:include, Bar)
Foo.send(:prepend, Bar)
Foo.send(:extend, Bar)
# bad
Foo.public_send(:include, Bar)
Foo.public_send(:prepend, Bar)
Foo.public_send(:extend, Bar)
# bad
Foo.__send__(:include, Bar)
Foo.__send__(:prepend, Bar)
Foo.__send__(:extend, Bar)
# good
Foo.include Bar
Foo.prepend Bar
Foo.extend Bar
Use yield
instead of block.call
. Open
new_value = block.call
- Read upRead up
- Exclude checks
This cop identifies the use of a &block
parameter and block.call
where yield
would do just as well.
Example:
# bad
def method(&block)
block.call
end
def another(&func)
func.call 1, 2, 3
end
# good
def method
yield
end
def another
yield 1, 2, 3
end
Unused block argument - k
. If it's necessary, use _
or _k
as an argument name to indicate that it won't be used. Open
delete_if { |k, v| v.blank? }
- Read upRead up
- Exclude checks
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
# good
do_something do |used, _unused|
puts used
end
do_something do
puts :foo
end
define_method(:foo) do |_bar|
puts :baz
end
Example: IgnoreEmptyBlocks: true (default)
# good
do_something { |unused| }
Example: IgnoreEmptyBlocks: false
# bad
do_something { |unused| }
Example: AllowUnusedKeywordArguments: false (default)
# bad
do_something do |unused: 42|
foo
end
Example: AllowUnusedKeywordArguments: true
# good
do_something do |unused: 42|
foo
end
Use include MoreCoreExtensions::HashNested
instead of send(:include, MoreCoreExtensions::HashNested)
. Open
Hash.send(:include, MoreCoreExtensions::HashNested)
- Read upRead up
- Exclude checks
Checks for send
, public_send
, and __send__
methods
when using mix-in.
include
and prepend
methods were private methods until Ruby 2.0,
they were mixed-in via send
method. This cop uses Ruby 2.1 or
higher style that can be called by public methods.
And extend
method that was originally a public method is also targeted
for style unification.
Example:
# bad
Foo.send(:include, Bar)
Foo.send(:prepend, Bar)
Foo.send(:extend, Bar)
# bad
Foo.public_send(:include, Bar)
Foo.public_send(:prepend, Bar)
Foo.public_send(:extend, Bar)
# bad
Foo.__send__(:include, Bar)
Foo.__send__(:prepend, Bar)
Foo.__send__(:extend, Bar)
# good
Foo.include Bar
Foo.prepend Bar
Foo.extend Bar
Wrap expressions with varying precedence with parentheses to avoid ambiguity. Open
r_squared = (n * sum_xy - sum_x * sum_y) / Math.sqrt((n * sum_x2 - sum_x.square) * (n * sum_y2 - sum_y.square)) rescue nil
- Read upRead up
- Exclude checks
Looks for expressions containing multiple binary operators
where precedence is ambiguous due to lack of parentheses. For example,
in 1 + 2 * 3
, the multiplication will happen before the addition, but
lexically it appears that the addition will happen first.
The cop does not consider unary operators (ie. !a
or -b
) or comparison
operators (ie. a =~ b
) because those are not ambiguous.
NOTE: Ranges are handled by Lint/AmbiguousRange
.
Example:
# bad
a + b * c
a || b && c
a ** b + c
# good (different precedence)
a + (b * c)
a || (b && c)
(a ** b) + c
# good (same precedence)
a + b + c
a * b / c % d
Use include MoreCoreExtensions::HashSortByBang
instead of send(:include, MoreCoreExtensions::HashSortByBang)
. Open
Hash.send(:include, MoreCoreExtensions::HashSortByBang) unless Hash.method_defined?(:sort_by!)
- Read upRead up
- Exclude checks
Checks for send
, public_send
, and __send__
methods
when using mix-in.
include
and prepend
methods were private methods until Ruby 2.0,
they were mixed-in via send
method. This cop uses Ruby 2.1 or
higher style that can be called by public methods.
And extend
method that was originally a public method is also targeted
for style unification.
Example:
# bad
Foo.send(:include, Bar)
Foo.send(:prepend, Bar)
Foo.send(:extend, Bar)
# bad
Foo.public_send(:include, Bar)
Foo.public_send(:prepend, Bar)
Foo.public_send(:extend, Bar)
# bad
Foo.__send__(:include, Bar)
Foo.__send__(:prepend, Bar)
Foo.__send__(:extend, Bar)
# good
Foo.include Bar
Foo.prepend Bar
Foo.extend Bar
Wrap expressions with varying precedence with parentheses to avoid ambiguity. Open
r_squared = (n * sum_xy - sum_x * sum_y) / Math.sqrt((n * sum_x2 - sum_x.square) * (n * sum_y2 - sum_y.square)) rescue nil
- Read upRead up
- Exclude checks
Looks for expressions containing multiple binary operators
where precedence is ambiguous due to lack of parentheses. For example,
in 1 + 2 * 3
, the multiplication will happen before the addition, but
lexically it appears that the addition will happen first.
The cop does not consider unary operators (ie. !a
or -b
) or comparison
operators (ie. a =~ b
) because those are not ambiguous.
NOTE: Ranges are handled by Lint/AmbiguousRange
.
Example:
# bad
a + b * c
a || b && c
a ** b + c
# good (different precedence)
a + (b * c)
a || (b && c)
(a ** b) + c
# good (same precedence)
a + b + c
a * b / c % d
Use prepend MoreCoreExtensions::NumericMath
instead of send(:prepend, MoreCoreExtensions::NumericMath)
. Open
Numeric.send(:prepend, MoreCoreExtensions::NumericMath)
- Read upRead up
- Exclude checks
Checks for send
, public_send
, and __send__
methods
when using mix-in.
include
and prepend
methods were private methods until Ruby 2.0,
they were mixed-in via send
method. This cop uses Ruby 2.1 or
higher style that can be called by public methods.
And extend
method that was originally a public method is also targeted
for style unification.
Example:
# bad
Foo.send(:include, Bar)
Foo.send(:prepend, Bar)
Foo.send(:extend, Bar)
# bad
Foo.public_send(:include, Bar)
Foo.public_send(:prepend, Bar)
Foo.public_send(:extend, Bar)
# bad
Foo.__send__(:include, Bar)
Foo.__send__(:prepend, Bar)
Foo.__send__(:extend, Bar)
# good
Foo.include Bar
Foo.prepend Bar
Foo.extend Bar