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
.
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.
Using plaintext to render view is error prone and very unmaintanable. Prefer using templates instead of rendering inline text.
where
as a Hash RB-W1012Instead of generating fragments of SQL statements within ActiveRecord#where
, use it by passing in conditions
as a Hash.
enumerator
, rational
, complex
and thread
need not be require
d, since they can be directly used in the program.
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.
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.
IO.select
with single argument detected RB-DS1003IO.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.
If an unused method argument is intended, it should be prefixed with an underscore.
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-A1008Selected 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.
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.
String#end_with?
instead of a regex match anchored to the end of the string RB-PR1009Instead of searching for a string pattern at the end of a string using regex, it is more efficient to simply use end_with?
instead.
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.
flat_map
to flatten maps RB-PR1011flat_map
is more efficient than flatten
. Refer here.
=~
in places where the MatchData
returned by #match
will not be used RB-PR1016The return value of =~
is an integral index/nil
and is more performant.
size
instead of count
RB-PR1020size
should be preferred over count
. Read more here.
tr
/delete
instead of gsub
RB-PR1022tr
/delete
are more efficient than gsub
.