Models should subclass ApplicationRecord
. Open
class Authorization < ActiveRecord::Base
- Read upRead up
- Create a ticketCreate a ticket
- Exclude checks
This cop checks that models subclass ApplicationRecord with Rails 5.0.
Example:
# good class Rails5Model < ApplicationRecord # ... end
# bad class Rails4Model < ActiveRecord::Base # ... end
Duplicate value 'wechat'
found in provider
enum declaration. Open
wechatservice: 'wechat',
- Read upRead up
- Create a ticketCreate a ticket
- Exclude checks
This cop looks for duplicate values in enum declarations.
Example:
# bad
enum status: { active: 0, archived: 0 }
# good
enum status: { active: 0, archived: 1 }
# bad
enum status: [:active, :archived, :active]
# good
enum status: [:active, :archived]
Unnecessary spacing detected. Open
belongs_to :user, touch: true
- Read upRead up
- Create a ticketCreate a ticket
- Exclude checks
This cop checks for extra/unnecessary whitespace.
Example:
# good if AllowForAlignment is true
name = "RuboCop"
# Some comment and an empty line
website += "/bbatsov/rubocop" unless cond
puts "rubocop" if debug
# bad for any configuration
set_app("RuboCop")
website = "https://github.com/bbatsov/rubocop"
Redundant return
detected. (https://github.com/bbatsov/ruby-style-guide#no-explicit-return) Open
return false
- Read upRead up
- Create a ticketCreate a ticket
- Exclude checks
This cop checks for redundant return
expressions.
Example:
def test
return something
end
def test
one
two
three
return something
end
It should be extended to handle methods whose body is if/else or a case expression with a default branch.
Put one space between the method name and the first argument. Open
belongs_to :user, touch: true
- Read upRead up
- Create a ticketCreate a ticket
- Exclude checks
Checks that exactly one space is used between a method name and the first argument for method calls without parentheses.
Alternatively, extra spaces can be added to align the argument with something on a preceding or following line, if the AllowForAlignment config parameter is true.
Example:
# bad
something x
something y, z
something'hello'
# good
something x
something y, z
something 'hello'
Use a guard clause instead of wrapping the code inside a conditional expression. (https://github.com/bbatsov/ruby-style-guide#no-nested-conditionals) Open
unless user.authorizations.count > 1 || user.mobile.present? || user.email.present?
- Read upRead up
- Create a ticketCreate a ticket
- Exclude checks
Use a guard clause instead of wrapping the code inside a conditional expression
Example:
# bad
def test
if something
work
end
end
# good
def test
return unless something
work
end
# also good
def test
work if something
end
# bad
if something
raise 'exception'
else
ok
end
# good
raise 'exception' if something
ok