Ruby

Ruby

Made by DeepSource
Use lambda/proc instead of a plain method call RB-RL1052
Anti-pattern
Major

Scope calls should not pass a method (usually a scope) instead of a lambda/proc.

Use of BEGIN block detected RB-ST1009
Anti-pattern
Minor

BEGIN blocks should not be used.

Enum detected with array syntax RB-RL1018
Anti-pattern
Major
Autofix

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.

Ineffective access modifier detected RB-LI1028
Anti-pattern
Major

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.

Literal used in interpolation RB-LI1032
Anti-pattern
Major
Autofix

Literals used in interpolations are pointless, and can be replaced by the literal directly.

Self assignment detected RB-LI1092
Anti-pattern
Major

Self assignments can be removed.

Replace with Integer#odd?/Integer#even? RB-ST1046
Anti-pattern
Minor
Autofix

Use of is_a is preferred RB-ST1016
Anti-pattern
Minor
Autofix

is_a? method should be used to check the type.

Found pattern branch without a body RB-W1003
Anti-pattern
Minor

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.

Use of class variables detected RB-ST1018
Anti-pattern
Minor

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

Use Integer#times for a simple loop which iterates a fixed number of times RB-ST1035
Anti-pattern
Minor
Autofix

for loops which iterate a constant number of times, using a Range literal and #each, can be done more readably using Integer#times.

Binary operator with identical operands detected RB-LI1093
Anti-pattern
Major

It covers arithmetic operators: +, -, , /, %, *; comparison operators: ==, ===, =~, >, >=, <, ⇐; bitwise operators: |, ^, &, <<, >>; boolean operators: &&, || and "spaceship" operator - <⇒.

Unnecessary require statement RB-LI1049
Anti-pattern
Major
Autofix

enumerator, rational, complex and thread need not be required, since they can be directly used in the program.

No enable statement found after disable RB-LI1034
Anti-pattern
Major

No # 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

Literal is used as condition RB-LI1031
Anti-pattern
Major

Literals used in conditions are pointless, as the programmer already knows if the condition will evaluate to true or false.

Use of has_and_belongs_to_many detected RB-RL1025
Anti-pattern
Major

Prefer 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-RL1059
Anti-pattern
Major
Autofix

For transforming an enumerable into a hash where the values are the original elements, Rails provides the index_with method.

Error class inheriting from Exception RB-LI1029
Anti-pattern
Major

Error classes must inherit from RuntimeError instead.

Use of ActiveRecord alias detected RB-RL1002
Anti-pattern
Major

The direct attribute names are clearer and easier to read.

Inconsistent class/module namespace nesting RB-ST1015
Anti-pattern
Minor

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.