Showing 12,628 of 12,628 total issues
Prefer single-quoted strings when you don't need string interpolation or special symbols. Open
attribute :status, :string, default: "Uploaded"
- Read upRead up
- Exclude checks
Checks if uses of quotes match the configured preference.
Example: EnforcedStyle: single_quotes (default)
# bad
"No special symbols"
"No string interpolation"
"Just text"
# good
'No special symbols'
'No string interpolation'
'Just text'
"Wait! What's #{this}!"
Example: EnforcedStyle: double_quotes
# bad
'Just some text'
'No special chars or interpolation'
# good
"Just some text"
"No special chars or interpolation"
"Every string in #{project} uses double_quotes"
unexpected token tRPAREN
(Using Ruby 2.4 parser; configure using TargetRubyVersion
parameter, under AllCops
) Open
if id.nil? || (@event_id_identifier_namespace ||= Namespace.find_by(id:)).nil?
- Read upRead up
- Exclude checks
This is not actually a cop. It does not inspect anything. It just provides methods to repack Parser's diagnostics/errors into RuboCop's offenses.
Specify a :dependent
option. Open
has_many :common_names, inverse_of: :language
- Read upRead up
- Exclude checks
This cop looks for has_many
or has_one
associations that don't
specify a :dependent
option.
It doesn't register an offense if :through
option was specified.
Example:
# bad
class User < ActiveRecord::Base
has_many :comments
has_one :avatar
end
# good
class User < ActiveRecord::Base
has_many :comments, dependent: :restrict_with_exception
has_one :avatar, dependent: :destroy
has_many :patients, through: :appointments
end
unexpected token tRCURLY
(Using Ruby 2.4 parser; configure using TargetRubyVersion
parameter, under AllCops
) Open
klass.constantize.joins(:tags).where(tags: {keyword_id:}).each do |o|
- Read upRead up
- Exclude checks
This is not actually a cop. It does not inspect anything. It just provides methods to repack Parser's diagnostics/errors into RuboCop's offenses.
unexpected token tRPAREN
(Using Ruby 2.4 parser; configure using TargetRubyVersion
parameter, under AllCops
) Open
created.push LoanItem.create!(loan_item_object: o, loan_id:)
- Read upRead up
- Exclude checks
This is not actually a cop. It does not inspect anything. It just provides methods to repack Parser's diagnostics/errors into RuboCop's offenses.
Specify an :inverse_of
option. Open
has_many :hybrid_relationships, -> {
- Read upRead up
- Exclude checks
This cop looks for has(one|many) and belongsto associations where
Active Record can't automatically determine the inverse association
because of a scope or the options used. Using the blog with order scope
example below, traversing the a Blog's association in both directions
with blog.posts.first.blog
would cause the blog
to be loaded from
the database twice.
:inverse_of
must be manually specified for Active Record to use the
associated object in memory, or set to false
to opt-out. Note that
setting nil
does not stop Active Record from trying to determine the
inverse automatically, and is not considered a valid value for this.
Example:
# good
class Blog < ApplicationRecord
has_many :posts
end
class Post < ApplicationRecord
belongs_to :blog
end
Example:
# bad
class Blog < ApplicationRecord
has_many :posts, -> { order(published_at: :desc) }
end
class Post < ApplicationRecord
belongs_to :blog
end
# good
class Blog < ApplicationRecord
has_many(:posts,
-> { order(published_at: :desc) },
inverse_of: :blog)
end
class Post < ApplicationRecord
belongs_to :blog
end
# good
class Blog < ApplicationRecord
with_options inverse_of: :blog do
has_many :posts, -> { order(published_at: :desc) }
end
end
class Post < ApplicationRecord
belongs_to :blog
end
# good
# When you don't want to use the inverse association.
class Blog < ApplicationRecord
has_many(:posts,
-> { order(published_at: :desc) },
inverse_of: false)
end
Example:
# bad
class Picture < ApplicationRecord
belongs_to :imageable, polymorphic: true
end
class Employee < ApplicationRecord
has_many :pictures, as: :imageable
end
class Product < ApplicationRecord
has_many :pictures, as: :imageable
end
# good
class Picture < ApplicationRecord
belongs_to :imageable, polymorphic: true
end
class Employee < ApplicationRecord
has_many :pictures, as: :imageable, inverse_of: :imageable
end
class Product < ApplicationRecord
has_many :pictures, as: :imageable, inverse_of: :imageable
end
Example:
# bad
# However, RuboCop can not detect this pattern...
class Physician < ApplicationRecord
has_many :appointments
has_many :patients, through: :appointments
end
class Appointment < ApplicationRecord
belongs_to :physician
belongs_to :patient
end
class Patient < ApplicationRecord
has_many :appointments
has_many :physicians, through: :appointments
end
# good
class Physician < ApplicationRecord
has_many :appointments
has_many :patients, through: :appointments
end
class Appointment < ApplicationRecord
belongs_to :physician, inverse_of: :appointments
belongs_to :patient, inverse_of: :appointments
end
class Patient < ApplicationRecord
has_many :appointments
has_many :physicians, through: :appointments
end
@see https://guides.rubyonrails.org/association_basics.html#bi-directional-associations @see https://api.rubyonrails.org/classes/ActiveRecord/Associations/ClassMethods.html#module-ActiveRecord::Associations::ClassMethods-label-Setting+Inverses
Use 2 (not 4) spaces for indentation. Open
NAMESPACES = %w{WOS ZOOREC}.freeze
- Read upRead up
- Exclude checks
This cop checks for indentation that doesn't use the specified number of spaces.
See also the IndentationConsistency cop which is the companion to this one.
Example:
# bad
class A
def test
puts 'hello'
end
end
# good
class A
def test
puts 'hello'
end
end
Example: IgnoredPatterns: ['^\s*module']
# bad
module A
class B
def test
puts 'hello'
end
end
end
# good
module A
class B
def test
puts 'hello'
end
end
end
Use 2 (not 4) spaces for indentation. Open
def uri
- Read upRead up
- Exclude checks
This cop checks for indentation that doesn't use the specified number of spaces.
See also the IndentationConsistency cop which is the companion to this one.
Example:
# bad
class A
def test
puts 'hello'
end
end
# good
class A
def test
puts 'hello'
end
end
Example: IgnoredPatterns: ['^\s*module']
# bad
module A
class B
def test
puts 'hello'
end
end
end
# good
module A
class B
def test
puts 'hello'
end
end
end
Use 2 (not 4) spaces for indentation. Open
def source_use_only
- Read upRead up
- Exclude checks
This cop checks for indentation that doesn't use the specified number of spaces.
See also the IndentationConsistency cop which is the companion to this one.
Example:
# bad
class A
def test
puts 'hello'
end
end
# good
class A
def test
puts 'hello'
end
end
Example: IgnoredPatterns: ['^\s*module']
# bad
module A
class B
def test
puts 'hello'
end
end
end
# good
module A
class B
def test
puts 'hello'
end
end
end
class definition in method body
(Using Ruby 2.4 parser; configure using TargetRubyVersion
parameter, under AllCops
) Open
class ImportDataset::DarwinCore < ImportDataset
- Read upRead up
- Exclude checks
This is not actually a cop. It does not inspect anything. It just provides methods to repack Parser's diagnostics/errors into RuboCop's offenses.
unexpected token tRPAREN
(Using Ruby 2.4 parser; configure using TargetRubyVersion
parameter, under AllCops
) Open
h[:quick] = Loan.pinned_by(user_id).pinboard_inserted.where(project_id:).to_a
- Read upRead up
- Exclude checks
This is not actually a cop. It does not inspect anything. It just provides methods to repack Parser's diagnostics/errors into RuboCop's offenses.
unexpected token kDO_BLOCK
(Using Ruby 2.4 parser; configure using TargetRubyVersion
parameter, under AllCops
) Open
Tag.where(keyword_id:).where(tag_object_type: ['Container', 'Otu', 'CollectionObject']).distinct.all.each do |o|
- Read upRead up
- Exclude checks
This is not actually a cop. It does not inspect anything. It just provides methods to repack Parser's diagnostics/errors into RuboCop's offenses.
Avoid more than 3 levels of block nesting. Open
if check_byte == 11
check_byte = 0
end
- Read upRead up
- Exclude checks
This cop checks for excessive nesting of conditional and looping constructs.
You can configure if blocks are considered using the CountBlocks
option. When set to false
(the default) blocks are not counted
towards the nesting level. Set to true
to count blocks as well.
The maximum level of nesting allowed is configurable.
Do not use Time.now
without zone. Use one of Time.zone.now
, Time.current
, Time.now.in_time_zone
, Time.now.utc
, Time.now.getlocal
, Time.now.xmlschema
, Time.now.iso8601
, Time.now.jisx0301
, Time.now.rfc3339
, Time.now.httpdate
, Time.now.to_i
, Time.now.to_f
instead. Open
if (year > Time.now.year) or (year < 2001)
- Read upRead up
- Exclude checks
This cop checks for the use of Time methods without zone.
Built on top of Ruby on Rails style guide (https://github.com/rubocop-hq/rails-style-guide#time) and the article http://danilenko.org/2012/7/6/rails_timezones/
Two styles are supported for this cop. When EnforcedStyle is 'strict' then only use of Time.zone is allowed.
When EnforcedStyle is 'flexible' then it's also allowed to use Time.intimezone.
Example: EnforcedStyle: strict
# `strict` means that `Time` should be used with `zone`.
# bad
Time.now
Time.parse('2015-03-02 19:05:37')
# bad
Time.current
Time.at(timestamp).in_time_zone
# good
Time.zone.now
Time.zone.parse('2015-03-02 19:05:37')
Example: EnforcedStyle: flexible (default)
# `flexible` allows usage of `in_time_zone` instead of `zone`.
# bad
Time.now
Time.parse('2015-03-02 19:05:37')
# good
Time.zone.now
Time.zone.parse('2015-03-02 19:05:37')
# good
Time.current
Time.at(timestamp).in_time_zone
Prefer the new style validations validates :column, uniqueness: value
over validates_uniqueness_of
. Open
validates_uniqueness_of :value, scope: [
- Read upRead up
- Exclude checks
This cop checks for the use of old-style attribute validation macros.
Example:
# bad
validates_acceptance_of :foo
validates_confirmation_of :foo
validates_exclusion_of :foo
validates_format_of :foo
validates_inclusion_of :foo
validates_length_of :foo
validates_numericality_of :foo
validates_presence_of :foo
validates_absence_of :foo
validates_size_of :foo
validates_uniqueness_of :foo
# good
validates :foo, acceptance: true
validates :foo, confirmation: true
validates :foo, exclusion: true
validates :foo, format: true
validates :foo, inclusion: true
validates :foo, length: true
validates :foo, numericality: true
validates :foo, presence: true
validates :foo, absence: true
validates :foo, size: true
validates :foo, uniqueness: true
unexpected token tRPAREN
(Using Ruby 2.4 parser; configure using TargetRubyVersion
parameter, under AllCops
) Open
records = records.where(id: start_id..) if start_id
- Read upRead up
- Exclude checks
This is not actually a cop. It does not inspect anything. It just provides methods to repack Parser's diagnostics/errors into RuboCop's offenses.
unexpected token tCOMMA
(Using Ruby 2.4 parser; configure using TargetRubyVersion
parameter, under AllCops
) Open
update!(date_returned:, disposition:)
- Read upRead up
- Exclude checks
This is not actually a cop. It does not inspect anything. It just provides methods to repack Parser's diagnostics/errors into RuboCop's offenses.
Do not use Time.now
without zone. Use one of Time.zone.now
, Time.current
, Time.now.in_time_zone
, Time.now.utc
, Time.now.getlocal
, Time.now.xmlschema
, Time.now.iso8601
, Time.now.jisx0301
, Time.now.rfc3339
, Time.now.httpdate
, Time.now.to_i
, Time.now.to_f
instead. Open
scope :used_recently, -> { joins(:identifiers).includes(:identifiers).where(identifiers: { updated_at: 10.weeks.ago..Time.now } ).order('"identifiers"."created_at" DESC') }
- Read upRead up
- Exclude checks
This cop checks for the use of Time methods without zone.
Built on top of Ruby on Rails style guide (https://github.com/rubocop-hq/rails-style-guide#time) and the article http://danilenko.org/2012/7/6/rails_timezones/
Two styles are supported for this cop. When EnforcedStyle is 'strict' then only use of Time.zone is allowed.
When EnforcedStyle is 'flexible' then it's also allowed to use Time.intimezone.
Example: EnforcedStyle: strict
# `strict` means that `Time` should be used with `zone`.
# bad
Time.now
Time.parse('2015-03-02 19:05:37')
# bad
Time.current
Time.at(timestamp).in_time_zone
# good
Time.zone.now
Time.zone.parse('2015-03-02 19:05:37')
Example: EnforcedStyle: flexible (default)
# `flexible` allows usage of `in_time_zone` instead of `zone`.
# bad
Time.now
Time.parse('2015-03-02 19:05:37')
# good
Time.zone.now
Time.zone.parse('2015-03-02 19:05:37')
# good
Time.current
Time.at(timestamp).in_time_zone
Prefer single-quoted strings when you don't need string interpolation or special symbols. Open
georeferenceSources: "Georeferenced image.",
- Read upRead up
- Exclude checks
Checks if uses of quotes match the configured preference.
Example: EnforcedStyle: single_quotes (default)
# bad
"No special symbols"
"No string interpolation"
"Just text"
# good
'No special symbols'
'No string interpolation'
'Just text'
"Wait! What's #{this}!"
Example: EnforcedStyle: double_quotes
# bad
'Just some text'
'No special chars or interpolation'
# good
"Just some text"
"No special chars or interpolation"
"Every string in #{project} uses double_quotes"
class definition in method body
(Using Ruby 2.4 parser; configure using TargetRubyVersion
parameter, under AllCops
) Open
class RequestUI
- Read upRead up
- Exclude checks
This is not actually a cop. It does not inspect anything. It just provides methods to repack Parser's diagnostics/errors into RuboCop's offenses.