Ruby

Ruby

Made by DeepSource
Ignored column accessed from ActiveRecord model RB-E1010
Bug risk
Major

The ignored_columns attribute allows the exclusion of certain columns when working with ActiveRecord models in Rails. However, accessing an ignored column from an ActiveRecord model wail raise a NoMethodError.

IO.select with single argument detected RB-DS1003
Bug risk
Major

IO.select statements can get very hard to make them compatible with Ruby 3 scheduler. It is recommended to use wait_readable or wait_writable on an IO object with a given timeout instead of rescuing an IO::WaitReadable or IO::WaitWritable error and using IO.select in the block.

Unused method arguments detected RB-LI1074
Bug risk
Major

If an unused method argument is intended, it should be prefixed with an underscore.

Renamed column accessed from ActiveRecord model RB-E1012
Bug risk
Major

The rename_column/t.rename migration method in Rails is used to rename a column in a database table. However, if an ActiveRecord model is still accessing the renamed column using its old name, it can lead to errors during runtime.

Duplicate value detected in enum declarations RB-RL1019
Bug risk
Major

Safe navigation used with blank? RB-RL1050
Bug risk
Major

While the safe navigation operator is generally a good idea, when checking foo&.blank? in a conditional, foo being nil will actually do the opposite of what was intended.

Bad ordering of magic comments RB-LI1042
Bug risk
Major

Duplicate require/require_relative blocks were found RB-LI1096
Bug risk
Major

Requiring, or relatively requiring same file/module twice is unnecessary and either of the blocks can be removed as they both serve the same purpose.

Division by zero RB-E1009
Bug risk
Major

The division by zero error in Ruby occurs when an attempt is made to divide a number by zero. This issue arises due to the fundamental mathematical rule that division by zero is undefined. When the division operation encounters a denominator of zero, it leads to an error condition.

Unexpected override of built-in Struct method RB-W1007
Bug risk
Major

When creating a custom value object using Struct.new, be careful as to not have attributes whose names match the built-in methods provided by the Struct class.

Arguments to range literal are ambiguous RB-W1006
Bug risk
Major

Range literal should be enclosed in parentheses when the end of the range is at a line break, otherwise the intention of the code becomes ambigous.

return detected inside ensure RB-LI1021
Bug risk
Major

Do not return from an ensure block. If you explicitly return from a method inside an ensure block, the return will take precedence over any exception being raised, and the method will return as if no exception had been raised

Exception class overwritten by its result RB-E1001
Bug risk
Major
Autofix

You intended to write as rescue StandardError. However, you have written rescue => StandardError. In that case, the result of rescue will overwrite StandardError.

Lambda without a literal block is deprecated RB-W1004
Bug risk
Major
Autofix

Lambda without a literal block is deprecated since Ruby 3.0, use the proc without lambda instead.

Risk of race condition in non-atomic file operation RB-E1002
Bug risk
Minor

Non-atomic file operations can cause problems that are difficult to reproduce, especially in cases of frequent file operations in parallel, such as test runs with parallel_rspec.

uniqueness: true used on a field that is not an index RB-W1022
Bug risk
Major

Defining uniqueness: true on an ActiveRecord model can be error prone if the column hasn't been declared unique at the database level.

Deprecated method used inside refine block RB-W1005
Bug risk
Major

Starting from Ruby 3.1, include or prepend must not be used within a refine block. These methods are deprecated and should be replaced with Refinement#import_methods.

Duplicate magic comment found RB-W1008
Bug risk
Major
Autofix

Having duplicate magic comments can lead to potential bug-risks, as a duplicate magic comment can have a different argument passed to it which can change the behavior of the program or even cause it to crash.

Usage of "*" on Arel::Table column reference RB-W1018
Bug risk
Major

Avoid using "*" on an Arel::Table column reference.

Usage of Time.zone= method RB-W1019
Bug risk
Major

Setting the timezone using Time.zone= should be avoided.