Showing 439 of 439 total issues
Specify a :dependent
option. Open
has_one :design_illustration
- 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
Do not use instance variables in helpers. Open
@header_links ||= collect_header_links
- Exclude checks
Use nested module/class definitions instead of compact style. Open
class Profiles::AccountsController < ApplicationController
- Read upRead up
- Exclude checks
This cop checks the style of children definitions at classes and modules. Basically there are two different styles:
Example: EnforcedStyle: nested (default)
# good
# have each child on its own line
class Foo
class Bar
end
end
Example: EnforcedStyle: compact
# good
# combine definitions as much as possible
class Foo::Bar
end
The compact style is only forced for classes/modules with one child.
Use (process['busy']).zero?
instead of process['busy'] == 0
. Open
ps.empty? || ps.detect { |process| process['busy'] == 0 }
- Read upRead up
- Exclude checks
This cop checks for usage of comparison operators (==
,
>
, <
) to test numbers as zero, positive, or negative.
These can be replaced by their respective predicate methods.
The cop can also be configured to do the reverse.
The cop disregards #nonzero?
as it its value is truthy or falsey,
but not true
and false
, and thus not always interchangeable with
!= 0
.
The cop ignores comparisons to global variables, since they are often
populated with objects which can be compared with integers, but are
not themselves Integer
polymorphic.
Example: EnforcedStyle: predicate (default)
# bad
foo == 0
0 > foo
bar.baz > 0
# good
foo.zero?
foo.negative?
bar.baz.positive?
Example: EnforcedStyle: comparison
# bad
foo.zero?
foo.negative?
bar.baz.positive?
# good
foo == 0
0 > foo
bar.baz > 0
Specify a :dependent
option. Open
has_many :designs
- 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 if params[:user_email].present?
instead of unless params[:user_email].blank?
. Open
return params[:user_email] unless params[:user_email].blank?
- Read upRead up
- Exclude checks
This cop checks for code that can be written with simpler conditionals
using Object#present?
defined by Active Support.
Interaction with Style/UnlessElse
:
The configuration of NotBlank
will not produce an offense in the
context of unless else
if Style/UnlessElse
is inabled. This is
to prevent interference between the auto-correction of the two cops.
Example: NotNilAndNotEmpty: true (default)
# Converts usages of `!nil? && !empty?` to `present?`
# bad
!foo.nil? && !foo.empty?
# bad
foo != nil && !foo.empty?
# good
foo.present?
Example: NotBlank: true (default)
# Converts usages of `!blank?` to `present?`
# bad
!foo.blank?
# bad
not foo.blank?
# good
foo.present?
Example: UnlessBlank: true (default)
# Converts usages of `unless blank?` to `if present?`
# bad
something unless foo.blank?
# good
something if foo.present?
Line is too long. [171/100] Open
# Ahoy uses 'request' object for accessing 'traffic source', 'technology', 'UTM parameters' etc. (https://api.rubyonrails.org/v6.0.0/classes/ActionDispatch/Request.html)
- Exclude checks
create
is not explicitly defined on the class. Open
before_action :throttle_reset, only: [:create]
- Read upRead up
- Exclude checks
This cop checks that methods specified in the filter's only
or
except
options are defined within the same class or module.
You can technically specify methods of superclass or methods added by mixins on the filter, but these can confuse developers. If you specify methods that are defined in other classes or modules, you should define the filter in that class or module.
If you rely on behaviour defined in the superclass actions, you must
remember to invoke super
in the subclass actions.
Example:
# bad
class LoginController < ApplicationController
before_action :require_login, only: %i[index settings logout]
def index
end
end
# good
class LoginController < ApplicationController
before_action :require_login, only: %i[index settings logout]
def index
end
def settings
end
def logout
end
end
Example:
# bad
module FooMixin
extend ActiveSupport::Concern
included do
before_action proc { authenticate }, only: :foo
end
end
# good
module FooMixin
extend ActiveSupport::Concern
included do
before_action proc { authenticate }, only: :foo
end
def foo
# something
end
end
Example:
class ContentController < ApplicationController
def update
@content.update(content_attributes)
end
end
class ArticlesController < ContentController
before_action :load_article, only: [:update]
# the cop requires this method, but it relies on behaviour defined
# in the superclass, so needs to invoke `super`
def update
super
end
private
def load_article
@content = Article.find(params[:article_id])
end
end
Line is too long. [115/100] Open
format.html { redirect_back_or_default(default: { action: 'show' }, options: { alert: result[:message] }) }
- Exclude checks
Use module_function
instead of extend self
. Open
extend self
- Read upRead up
- Exclude checks
This cop checks for use of extend self
or module_function
in a
module.
Supported styles are: modulefunction, extendself.
Example: EnforcedStyle: module_function (default)
# bad
module Test
extend self
# ...
end
# good
module Test
module_function
# ...
end
In case there are private methods, the cop won't be activated. Otherwise, it forces to change the flow of the default code.
Example: EnforcedStyle: module_function (default)
# good
module Test
extend self
# ...
private
# ...
end
Example: EnforcedStyle: extend_self
# bad
module Test
module_function
# ...
end
# good
module Test
extend self
# ...
end
These offenses are not safe to auto-correct since there are different implications to each approach.
Assignment Branch Condition size for presigned_post_options is too high. [<0, 17, 0> 17/15] Open
def presigned_post_options
# https://docs.aws.amazon.com/sdk-for-ruby/v3/api/Aws/S3/Bucket.html#presigned_post-instance_method
# TODO: consider moving Boyutluseyler.config policies into related policy class
{
key: generate_key(policy.key_prefix),
- Read upRead up
- Exclude checks
This cop checks that the ABC size of methods is not higher than the configured maximum. The ABC size is based on assignments, branches (method calls), and conditions. See http://c2.com/cgi/wiki?AbcMetric and https://en.wikipedia.org/wiki/ABC_Software_Metric.
Use ==
if you meant to do a comparison or wrap the expression in parentheses to indicate you meant to assign in a condition. Open
if path = options.delete(:path)
- Read upRead up
- Exclude checks
This cop checks for assignments in the conditions of if/while/until.
AllowSafeAssignment
option for safe assignment.
By safe assignment we mean putting parentheses around
an assignment to indicate "I know I'm using an assignment
as a condition. It's not a mistake."
Example:
# bad
if some_var = true
do_something
end
# good
if some_var == true
do_something
end
Example: AllowSafeAssignment: true (default)
# good
if (some_var = true)
do_something
end
Example: AllowSafeAssignment: false
# bad
if (some_var = true)
do_something
end
Use ==
if you meant to do a comparison or wrap the expression in parentheses to indicate you meant to assign in a condition. Open
elsif page = options.delete(:page)
- Read upRead up
- Exclude checks
This cop checks for assignments in the conditions of if/while/until.
AllowSafeAssignment
option for safe assignment.
By safe assignment we mean putting parentheses around
an assignment to indicate "I know I'm using an assignment
as a condition. It's not a mistake."
Example:
# bad
if some_var = true
do_something
end
# good
if some_var == true
do_something
end
Example: AllowSafeAssignment: true (default)
# good
if (some_var = true)
do_something
end
Example: AllowSafeAssignment: false
# bad
if (some_var = true)
do_something
end
Assignment Branch Condition size for show is too high. [<3, 18, 0> 18.25/15] Open
def show
@illustrations = BuildSerializer.new(design.preview_illustrations,
fields: { illustration: file_preview_fields })
.serialize
- Read upRead up
- Exclude checks
This cop checks that the ABC size of methods is not higher than the configured maximum. The ABC size is based on assignments, branches (method calls), and conditions. See http://c2.com/cgi/wiki?AbcMetric and https://en.wikipedia.org/wiki/ABC_Software_Metric.
Method Boyutluseyler::Auth::OAuth::User#auth_hash=
is defined at both lib/boyutluseyler/auth/o_auth/user.rb:9 and lib/boyutluseyler/auth/o_auth/user.rb:72. Open
def auth_hash=(auth_hash)
- Read upRead up
- Exclude checks
This cop checks for duplicated instance (or singleton) method definitions.
Example:
# bad
def foo
1
end
def foo
2
end
Example:
# bad
def foo
1
end
alias foo bar
Example:
# good
def foo
1
end
def bar
2
end
Example:
# good
def foo
1
end
alias bar foo
Please use Rails.root.join('path', 'to')
instead. Open
format.html { render file: Rails.root.join('public/404'), layout: false, status: 404 }
- Read upRead up
- Exclude checks
This cop is used to identify usages of file path joining process
to use Rails.root.join
clause. It is used to add uniformity when
joining paths.
Example: EnforcedStyle: arguments (default)
# bad
Rails.root.join('app/models/goober')
File.join(Rails.root, 'app/models/goober')
"#{Rails.root}/app/models/goober"
# good
Rails.root.join('app', 'models', 'goober')
Example: EnforcedStyle: slashes
# bad
Rails.root.join('app', 'models', 'goober')
File.join(Rails.root, 'app/models/goober')
"#{Rails.root}/app/models/goober"
# good
Rails.root.join('app/models/goober')
Don't extend an instance initialized by Struct.new
. Use a block to customize the struct. Open
class DirectUploadPolicy < Struct.new(:user, :direct_upload)
- Read upRead up
- Exclude checks
This cop checks for inheritance from Struct.new.
Example:
# bad
class Person < Struct.new(:first_name, :last_name)
def age
42
end
end
# good
Person = Struct.new(:first_name, :last_name) do
def age
42
end
end
Missing magic comment # frozen_string_literal: true
. Open
# == Schema Information
- Read upRead up
- Exclude checks
This cop is designed to help you transition from mutable string literals
to frozen string literals.
It will add the comment # frozen_string_literal: true
to the top of
files to enable frozen string literals. Frozen string literals may be
default in future Ruby. The comment will be added below a shebang and
encoding comment. The frozen string literal comment is only valid in
Ruby 2.3+.
Note that the cop will ignore files where the comment exists but is set
to false
instead of true
.
Example: EnforcedStyle: always (default)
# The `always` style will always add the frozen string literal comment
# to a file, regardless of the Ruby version or if `freeze` or `<<` are
# called on a string literal.
# bad
module Bar
# ...
end
# good
# frozen_string_literal: true
module Bar
# ...
end
# good
# frozen_string_literal: false
module Bar
# ...
end
Example: EnforcedStyle: never
# The `never` will enforce that the frozen string literal comment does
# not exist in a file.
# bad
# frozen_string_literal: true
module Baz
# ...
end
# good
module Baz
# ...
end
Don't extend an instance initialized by Struct.new
. Use a block to customize the struct. Open
class IdentityProviderPolicy < Struct.new(:user, :identity_provider)
- Read upRead up
- Exclude checks
This cop checks for inheritance from Struct.new.
Example:
# bad
class Person < Struct.new(:first_name, :last_name)
def age
42
end
end
# good
Person = Struct.new(:first_name, :last_name) do
def age
42
end
end
Assignment Branch Condition size for add_or_update_user_identities is too high. [<5, 16, 2> 16.88/15] Open
def add_or_update_user_identities
return unless bs_user
# find_or_initialize_by doesn't update `bs_user.identities`, and isn't autosaved.
identity = bs_user.identities.find { |identity| identity.provider == auth_hash.provider }
- Read upRead up
- Exclude checks
This cop checks that the ABC size of methods is not higher than the configured maximum. The ABC size is based on assignments, branches (method calls), and conditions. See http://c2.com/cgi/wiki?AbcMetric and https://en.wikipedia.org/wiki/ABC_Software_Metric.