Showing 2,521 of 2,521 total issues
Use create!
instead of create
if the return value is not checked. (https://rails.rubystyle.guide#save-bang) Open
RelatedContentScore.create(user: user, related_content: opposite_related_content, value: value)
- Read upRead up
- Exclude checks
This cop identifies possible cases where Active Record save! or related should be used instead of save because the model might have failed to save and an exception is better than unhandled failure.
This will allow:
- update or save calls, assigned to a variable,
or used as a condition in an if/unless/case statement.
- create calls, assigned to a variable that then has a
call to persisted?
.
- calls if the result is explicitly returned from methods and blocks,
or provided as arguments.
- calls whose signature doesn't look like an ActiveRecord
persistence method.
By default it will also allow implicit returns from methods and blocks.
that behavior can be turned off with AllowImplicitReturn: false
.
You can permit receivers that are giving false positives with
AllowedReceivers: []
Example:
# bad
user.save
user.update(name: 'Joe')
user.find_or_create_by(name: 'Joe')
user.destroy
# good
unless user.save
# ...
end
user.save!
user.update!(name: 'Joe')
user.find_or_create_by!(name: 'Joe')
user.destroy!
user = User.find_or_create_by(name: 'Joe')
unless user.persisted?
# ...
end
def save_user
return user.save
end
Example: AllowImplicitReturn: true (default)
# good
users.each { |u| u.save }
def save_user
user.save
end
Example: AllowImplicitReturn: false
# bad
users.each { |u| u.save }
def save_user
user.save
end
# good
users.each { |u| u.save! }
def save_user
user.save!
end
def save_user
return user.save
end
Example: AllowedReceivers: ['merchant.customers', 'Service::Mailer']
# bad
merchant.create
customers.builder.save
Mailer.create
module Service::Mailer
self.create
end
# good
merchant.customers.create
MerchantService.merchant.customers.destroy
Service::Mailer.update(message: 'Message')
::Service::Mailer.update
Services::Service::Mailer.update(message: 'Message')
Service::Mailer::update
Specify a :dependent
option. (https://rails.rubystyle.guide#has_many-has_one-dependent-option) Open
has_many :poll_questions,
- 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
Use save!
instead of save
if the return value is not checked. (https://rails.rubystyle.guide#save-bang) Open
residence.save
- Read upRead up
- Exclude checks
This cop identifies possible cases where Active Record save! or related should be used instead of save because the model might have failed to save and an exception is better than unhandled failure.
This will allow:
- update or save calls, assigned to a variable,
or used as a condition in an if/unless/case statement.
- create calls, assigned to a variable that then has a
call to persisted?
.
- calls if the result is explicitly returned from methods and blocks,
or provided as arguments.
- calls whose signature doesn't look like an ActiveRecord
persistence method.
By default it will also allow implicit returns from methods and blocks.
that behavior can be turned off with AllowImplicitReturn: false
.
You can permit receivers that are giving false positives with
AllowedReceivers: []
Example:
# bad
user.save
user.update(name: 'Joe')
user.find_or_create_by(name: 'Joe')
user.destroy
# good
unless user.save
# ...
end
user.save!
user.update!(name: 'Joe')
user.find_or_create_by!(name: 'Joe')
user.destroy!
user = User.find_or_create_by(name: 'Joe')
unless user.persisted?
# ...
end
def save_user
return user.save
end
Example: AllowImplicitReturn: true (default)
# good
users.each { |u| u.save }
def save_user
user.save
end
Example: AllowImplicitReturn: false
# bad
users.each { |u| u.save }
def save_user
user.save
end
# good
users.each { |u| u.save! }
def save_user
user.save!
end
def save_user
return user.save
end
Example: AllowedReceivers: ['merchant.customers', 'Service::Mailer']
# bad
merchant.create
customers.builder.save
Mailer.create
module Service::Mailer
self.create
end
# good
merchant.customers.create
MerchantService.merchant.customers.destroy
Service::Mailer.update(message: 'Message')
::Service::Mailer.update
Services::Service::Mailer.update(message: 'Message')
Service::Mailer::update
0.5
should be written without a leading zero as .5
Open
$body-margin: calc(50vw - #{$global-width * 0.5}) !default;
- Exclude checks
0.25
should be written without a leading zero as .25
Open
$button-opacity-disabled: 0.25 !default;
- Exclude checks
0.25
should be written without a leading zero as .25
Open
$menu-icon-spacing: 0.25rem !default;
- Exclude checks
0.1
should be written without a leading zero as .1
Open
$orbit-bullet-margin: 0.1rem !default;
- Exclude checks
0.25
should be written without a leading zero as .25
Open
$switch-paddle-offset: 0.25rem !default;
- Exclude checks
0.25
should be written without a leading zero as .25
Open
$switch-paddle-transition: all 0.25s ease-out !default;
- Exclude checks
0.5
should be written without a leading zero as .5
Open
$thumbnail-shadow-hover: 0 0 6px 1px rgba($primary-color, 0.5) !default;
- Exclude checks
Nesting should be no greater than 3, but was 4 Open
> header {
- Exclude checks
Nesting should be no greater than 3, but was 4 Open
a {
- Exclude checks
Selector should have depth of applicability no greater than 3, but was 4 Open
.new-link {
- Exclude checks
Selector should have depth of applicability no greater than 3, but was 4 Open
* + dt::before {
- Exclude checks
Selector should have depth of applicability no greater than 3, but was 4 Open
> * {
- Exclude checks
Selector should have depth of applicability no greater than 3, but was 4 Open
&.polls-link {
- Exclude checks
Selector should have depth of applicability no greater than 3, but was 4 Open
&.ml-link {
- Exclude checks
Unknown property container-type Open
container-type: inline-size;
- Exclude checks
Color literals like hsla(52, 100%, 85%, 0.5)
should only be used in variable declarations; they should be referred to via variable everywhere else. Open
background: hsla(52, 100%, 85%, 0.5);
- Exclude checks
Prefer single quoted strings Open
@import "datepicker_overrides";
- Exclude checks