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.

Space found between receiver name and opening brackets RB-C1013
Anti-pattern
Minor
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
Major

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
Minor

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

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

Incorrect pluralization grammar detected RB-RL1037
Style
Major
Autofix

When using ActiveSupport's number pluralization, proper aliases should be used for readablity. For example, 1.day.ago, while equivalent to 1.days.ago, does not make grammatical sense.

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.

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.

Grouped parentheses found in function calls RB-LI1043
Style
Major
Autofix

Do not put a space between method name and left parenthesis, it makes the code ambiguous to read.

rails version is susceptible to DOS attack via Mime type caching RB-A1008
Security
Critical

Selected versions of Rails till version 4.2.5 do not properly restrict the use of the MIME type caches, which allows remote attackers to cause a denial of service (memory consumption) via a crafted HTTP Accept header. Upgrading to newer versions of Rails can help fix this issue.

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.

Use String#end_with? instead of a regex match anchored to the end of the string RB-PR1009
Performance
Major

Instead of searching for a string pattern at the end of a string using regex, it is more efficient to simply use end_with? instead.

Do not compute the size of statically sized objects RB-PR1010
Performance
Major

Sizes of objects that we know to be static should not be computed. For example, we know the size of array in the snippet below to be 3. We can directly use the value instead of calculating it first.

Use =~ in places where the MatchData returned by #match will not be used RB-PR1016
Performance
Major
Autofix

The return value of =~ is an integral index/nil and is more performant.

Use tr/delete instead of gsub RB-PR1022
Performance
Major
Autofix

tr/delete are more efficient than gsub.

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