Showing 439 of 439 total issues
create
is not explicitly defined on the class. Open
before_action :resource_from_email, 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
Add an empty line after magic comments. Open
# == Schema Information
- Read upRead up
- Exclude checks
Checks for a newline after the final magic comment.
Example:
# good
# frozen_string_literal: true
# Some documentation for Person
class Person
# Some code
end
# bad
# frozen_string_literal: true
# Some documentation for Person
class Person
# Some code
end
Line is too long. [141/100] Open
url: "#{illustration_source}/id/#{illustration_id}/#{illustration_large_size}/#{illustration_large_size}.#{illustration_format}",
- Exclude checks
Line is too long. [147/100] Open
large_url: "#{illustration_source}/id/#{illustration_id}/#{illustration_large_size}/#{illustration_large_size}.#{illustration_format}",
- Exclude checks
Gems should be sorted in an alphabetical order within their section of the Gemfile. Gem oj
should appear before omniauth-rails_csrf_protection
. Open
gem 'oj', '~> 3.9', '>= 3.9.2' # Speed up JSON processes
- Read upRead up
- Exclude checks
Gems should be alphabetically sorted within groups.
Example:
# bad
gem 'rubocop'
gem 'rspec'
# good
gem 'rspec'
gem 'rubocop'
# good
gem 'rubocop'
gem 'rspec'
# good only if TreatCommentsAsGroupSeparators is true
# For code quality
gem 'rubocop'
# For tests
gem 'rspec'
Line is too long. [108/100] Open
gem 'pry-rails', '~> 0.3.9', require: false # call `rails r pry-rails` instead `rails console r pry-rails`
- Exclude checks
Assignment Branch Condition size for simple_sorts is too high. [<0, 18, 0> 18/15] Open
def simple_sorts
{
'created_asc' => -> { order_created_asc },
'created_date' => -> { order_created_desc },
'created_desc' => -> { order_created_desc },
- 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.
.pryrc should define a class or module called ``. Open
# frozen_string_literal: true
- Read upRead up
- Exclude checks
This cop makes sure that Ruby source files have snake_case names. Ruby scripts (i.e. source files with a shebang in the first line) are ignored.
The cop also ignores .gemspec
files, because Bundler
recommends using dashes to separate namespaces in nested gems
(i.e. bundler-console
becomes Bundler::Console
). As such, the
gemspec is supposed to be named bundler-console.gemspec
.
Example:
# bad
lib/layoutManager.rb
anything/usingCamelCase
# good
lib/layout_manager.rb
anything/using_snake_case.rake
Do not write to stdout. Use Rails's logger if you want to log. Open
puts "(#{provider}) Error saving user #{auth_hash.uid} (#{auth_hash.email}): #{bs_user.errors.full_messages}"
- Read upRead up
- Exclude checks
This cop checks for the use of output calls like puts and print
Example:
# bad
puts 'A debug message'
pp 'A debug message'
print 'A debug message'
# good
Rails.logger.debug 'A debug message'
Line is too long. [109/100] Open
description: Faker::Hipster.unique.paragraphs(number: rand(1..5)).map { |pr| "<p>#{pr}</p>" }.join,
- Exclude checks
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
Assignment Branch Condition size for create is too high. [<3, 18, 4> 18.68/15] Open
def create
authorize Blueprint
result = create_service.new(ObjectStorage::DirectUpload::Bucket.new,
current_user,
- 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.
Line is too long. [111/100] Open
Ahoy::Event.where(name: event_name, properties: event_properties, user_id: current_user.id).destroy_all
- Exclude checks
Use user.roles.where(name: 'admin').count.positive?
instead of user.roles.where(name: 'admin').count > 0
. Open
user && user.roles.where(name: 'admin').count > 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
Method Boyutluseyler::Auth::OAuth::User#bs_user
is defined at both lib/boyutluseyler/auth/o_auth/user.rb:9 and lib/boyutluseyler/auth/o_auth/user.rb:37. Open
def bs_user
- 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
Line is too long. [408/100] Open
# Users may visit the design very close to the end of the 'visit_duration', after that visit 'visit_duration' time may be expired. Clicking the download button creates a new visit record because 'visit_duration' time expired. This new visit record will contain missing data about 'traffic source', 'technology', 'UTM parameters' etc. because Ahoy will be unable to access 'request' object in the async job.
- Exclude checks
Line is too long. [128/100] Open
gem 'web-console', '>= 3.3.0' # Access an interactive console on exception pages or by calling 'console' anywhere in the code.
- Exclude checks
Assignment Branch Condition size for create is too high. [<3, 18, 4> 18.68/15] Open
def create
authorize Illustration
result = create_service.new(ObjectStorage::DirectUpload::Bucket.new,
current_user,
- 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.
Useless assignment to variable - success
. Open
success = design.update(params)
- Read upRead up
- Exclude checks
This cop checks for every useless assignment to local variable in every
scope.
The basic idea for this cop was from the warning of ruby -cw
:
assigned but unused variable - foo
Currently this cop has advanced logic that detects unreferenced reassignments and properly handles varied cases such as branch, loop, rescue, ensure, etc.
Example:
# bad
def some_method
some_var = 1
do_something
end
Example:
# good
def some_method
some_var = 1
do_something(some_var)
end
Line is too long. [119/100] Open
puts "(#{provider}) Error saving user #{auth_hash.uid} (#{auth_hash.email}): #{bs_user.errors.full_messages}"
- Exclude checks