Ruby

Ruby

By DeepSource

Space found between receiver name and opening brackets RB-C1013
Anti-pattern
Autofix

When accessing elements from arrays or hashes, do not put spaces between the receiver name and the opeining brackets as it can make the code ambigous to read.

Prefer using templates instead of rendering inline text RB-W1011
Anti-pattern

Using plaintext to render view is error prone and very unmaintanable. Prefer using templates instead of rendering inline text.

Pass conditions to where as a Hash RB-W1012
Anti-pattern

Instead of generating fragments of SQL statements within ActiveRecord#where, use it by passing in conditions as a Hash.

Unnecessary require statement RB-LI1049
Anti-pattern
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

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

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

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

Error classes must inherit from RuntimeError instead.

Blocks should be used for interpolated strings passed to Rails.logger.debug RB-W1009
Anti-pattern
Autofix

By default, Rails production environments use the :info log level. At the :info log level, Rails.logger.debug statements do not result in log output.

However, Ruby must eagerly evaluate interpolated string arguments passed as method arguments. Passing a block to Rails.logger.debug prevents costly evaluation of interpolated strings when no output would be produced anyway.

Found redundant self-assignment branch RB-C1014
Anti-pattern
Autofix

Self-assignment branches should be avoided as they are inefficient, unmaintanable and lack reability. Instead it is recommended to use single line conditionals if you need to make assignments.

Redundant usage of %q RB-ST1123
Anti-pattern
Autofix

The %q syntax is used to define a string literal with single quotes. It is unnecessary when the string does not contain any single quotes or when you want to use double quotes instead.

For example, %q{Hello world} is equivalent to 'Hello world', but %q{Hello's world} is necessary to avoid having to escape the single quote character: 'Hello's world'.

If you don't need to use single quotes or want to use double quotes, you can use other string literal syntaxes such as %{} or "".

For example, %"Hello world" is equivalent to "Hello world", and %{Hello world} is also equivalent to "Hello world".

Useless occurrence of rescue RB-W1023
Anti-pattern

Avoid bubbling up exceptions with useless rescues (which only re-raise the errors) in your code as they are inefficient and can make the control flow difficult to understand.

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

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.

require_relative called with current file path RB-W1002
Anti-pattern
Autofix

Calling require_relative with the path of the file it was called from doesn't perform any meaningful action since the file being executed is already in the LOAD_PATH.

Usage of SQL fragments in where query method RB-C1016
Anti-pattern
Autofix

Prefer passing conditions to where and where.not as a hash over using fragments of SQL.

Usage of inquiry method RB-C1017
Anti-pattern

Prefer Ruby’s comparison operators over ActiveSupport’s Array#inquiry, and String#inquiry.

Mailer class name without Mailer suffix RB-C1018
Anti-pattern

Classes implementing mailing functionality (inheriting from ActionMailer::Base or ApplicationMailer) should be named with a Mailer suffix.

Use Comparable#clamp to limit value to a range RB-C1019
Anti-pattern

When you want to limit a value to a certain range, prefer using Comparable#clamp intead of combinations of min/max and conditionals.

Avoid using git to declare files in gemspec RB-E1004
Anti-pattern

Avoid using git ls-files to produce lists of files. Downstreams often need to build your package in an environment that does not have git (on purpose). Instead, use some pure Ruby alternatives, like Dir or Dir.glob.