lambda
/proc
instead of a plain method call RB-RL1052Scope calls should not pass a method (usually a scope) instead of a lambda/proc.
BEGIN
block detected RB-ST1009BEGIN
blocks should not be used.
When using array syntax, adding an element in a position other than the last causes all previous definitions to shift. Explicitly specifying the value for each key prevents this from happening.
private
or protected
access modifiers which are applied to a singleton method do not make them private/protected. private_class_method
can be used for that.
Literals used in interpolations are pointless, and can be replaced by the literal directly.
Self assignments can be removed.
Integer#odd?
/Integer#even?
RB-ST1046is_a
is preferred RB-ST1016is_a?
method should be used to check the type.
In case you want to return nil
from a case body, it is better to return it explicitly. Otherwise the intent of the code may seem ambiguous.
Care is needed when setting a value for a class variable; if a class has been inherited, changing the value of a class variable also affects the inheriting classes. This means that it's almost always better to use
Integer#times
for a simple loop which iterates a fixed number of times RB-ST1035for
loops which iterate a constant number of times, using a Range
literal and #each
, can be done more readably using Integer#times
.
It covers arithmetic operators: +, -, , /, %, *; comparison operators: ==, ===, =~, >, >=, <, ⇐; bitwise operators: |, ^, &, <<, >>; boolean operators: &&, || and "spaceship" operator - <⇒.
enumerator
, rational
, complex
and thread
need not be require
d, since they can be directly used in the program.
enable
statement found after disable
RB-LI1034No # rubocop: enable
was found in the source code after the # rubocop: disable
comment. Since DeepSource respects issue silencing rules laid out by Rubocop, all issues in this file after the disable
statement will be silenced, and issues will
Literals used in conditions are pointless, as the programmer already knows if the condition will evaluate to true or false.
has_and_belongs_to_many
detected RB-RL1025Prefer has_many :through
to has_and_belongs_to_many
. Using has_many :through
allows additional attributes and validations on the join model.
index_with
can be used to create a hash from an enumerable RB-RL1059For transforming an enumerable into a hash where the values are the original elements, Rails provides the index_with
method.
Exception
RB-LI1029Error classes must inherit from RuntimeError
instead.
ActiveRecord
alias detected RB-RL1002The direct attribute names are clearer and easier to read.
Namespaced classes and modules should be defined (and reopened) in a consistent way throughout the project. Using the scope resolution operator can lead to surprising constant lookups due to Ruby’s lexical scoping, which depends on the module nesting at the point of definition.