Showing 235 of 235 total issues
Add an empty line after magic comments. (https://github.com/bbatsov/ruby-style-guide#separate-magic-comments-from-code) Open
ActiveRecordSchemaScrapper::Attributes.register_type(name: :enum, klass: String)
- 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
Surrounding space missing in default value assignment. (https://github.com/bbatsov/ruby-style-guide#spaces-around-equals) Open
def classes(klass, fail_hard=false)
- Read upRead up
- Exclude checks
Checks that the equals signs in parameter default assignments have or don't have surrounding space depending on configuration.
Example:
# bad
def some_method(arg1=:default, arg2=nil, arg3=[])
# do something...
end
# good
def some_method(arg1 = :default, arg2 = nil, arg3 = [])
# do something...
end
Replace class var @@built_types with a class instance var. (https://github.com/bbatsov/ruby-style-guide#no-class-vars) Open
@@built_types ||= {}
- Read upRead up
- Exclude checks
This cop checks for uses of class variables. Offenses are signaled only on assignment to class variables to reduce the number of offenses that would be reported.
Put empty method definitions on a single line. (https://github.com/bbatsov/ruby-style-guide#no-single-line-methods) Open
def initialize(*)
end
- Read upRead up
- Exclude checks
This cop checks for the formatting of empty method definitions.
By default it enforces empty method definitions to go on a single
line (compact style), but it can be configured to enforce the end
to go on its own line (expanded style).
Note: A method definition is not considered empty if it contains comments.
Example: EnforcedStyle: compact (default)
# bad
def foo(bar)
end
def self.foo(bar)
end
# good
def foo(bar); end
def foo(bar)
# baz
end
def self.foo(bar); end
Example: EnforcedStyle: expanded
# bad
def foo(bar); end
def self.foo(bar); end
# good
def foo(bar)
end
def self.foo(bar)
end
Avoid using touch
because it skips validations. (http://guides.rubyonrails.org/active_record_validations.html#skipping-validations) Open
record.touch(:created_at, :created_on) if ActiveMocker::LoadedMocks.features[:timestamps]
- Read upRead up
- Exclude checks
This cop checks for the use of methods which skip validations which are listed in http://guides.rubyonrails.org/active_record_validations.html#skipping-validations
Example:
# bad
Article.first.decrement!(:view_count)
DiscussionBoard.decrement_counter(:post_count, 5)
Article.first.increment!(:view_count)
DiscussionBoard.increment_counter(:post_count, 5)
person.toggle :active
product.touch
Billing.update_all("category = 'authorized', author = 'David'")
user.update_attribute(website: 'example.com')
user.update_columns(last_request_at: Time.current)
Post.update_counters 5, comment_count: -1, action_count: 1
# good
user.update_attributes(website: 'example.com')
FileUtils.touch('file')
Avoid multi-line chains of blocks. (https://github.com/bbatsov/ruby-style-guide#single-line-blocks) Open
end.any? { |a| a }
- Read upRead up
- Exclude checks
This cop checks for chaining of a block after another block that spans multiple lines.
Example:
Thread.list.find_all do |t|
t.alive?
end.map do |t|
t.object_id
end
Add an empty line after magic comments. (https://github.com/bbatsov/ruby-style-guide#separate-magic-comments-from-code) Open
module ActiveMocker
- 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
Add an empty line after magic comments. (https://github.com/bbatsov/ruby-style-guide#separate-magic-comments-from-code) Open
module ActiveMocker
- 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
Use delegate
to define delegations. Open
def blank?
- Read upRead up
- Exclude checks
This cop looks for delegations that could have been created
automatically with the delegate
method.
Safe navigation &.
is ignored because Rails' allow_nil
option checks not just for nil but also delegates if nil
responds to the delegated method.
The EnforceForPrefixed
option (defaulted to true
) means that
using the target object as a prefix of the method name
without using the delegate
method will be a violation.
When set to false
, this case is legal.
Example:
# bad
def bar
foo.bar
end
# good
delegate :bar, to: :foo
# good
def bar
foo&.bar
end
# good
private
def bar
foo.bar
end
# EnforceForPrefixed: true
# bad
def foo_bar
foo.bar
end
# good
delegate :bar, to: :foo, prefix: true
# EnforceForPrefixed: false
# good
def foo_bar
foo.bar
end
# good
delegate :bar, to: :foo, prefix: true
Line is too long. [123/120] (https://github.com/bbatsov/ruby-style-guide#80-character-limits) Open
# Input ActiveRecord Model Name as String or Symbol and it returns everything but that ActiveMock equivalent class.
- Exclude checks
Add an empty line after magic comments. (https://github.com/bbatsov/ruby-style-guide#separate-magic-comments-from-code) Open
module ActiveMocker
- 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
Use a guard clause instead of wrapping the code inside a conditional expression. (https://github.com/bbatsov/ruby-style-guide#no-nested-conditionals) Open
if respond_to?("#{k}=")
- Read upRead up
- 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
Use %i
or %I
for an array of symbols. (https://github.com/bbatsov/ruby-style-guide#percent-i) Open
attributes = [:updated_at, :update_on]
- Read upRead up
- Exclude checks
This cop can check for array literals made up of symbols that are not using the %i() syntax.
Alternatively, it checks for symbol arrays using the %i() syntax on projects which do not want to use that syntax.
Configuration option: MinSize
If set, arrays with fewer elements than this value will not trigger the
cop. For example, a MinSize of
3` will not enforce a style on an array
of 2 or fewer elements.
Example: EnforcedStyle: percent (default)
# good
%i[foo bar baz]
# bad
[:foo, :bar, :baz]
Example: EnforcedStyle: brackets
# good
[:foo, :bar, :baz]
# bad
%i[foo bar baz]
Put empty method definitions on a single line. (https://github.com/bbatsov/ruby-style-guide#no-single-line-methods) Open
def increment
end
- Read upRead up
- Exclude checks
This cop checks for the formatting of empty method definitions.
By default it enforces empty method definitions to go on a single
line (compact style), but it can be configured to enforce the end
to go on its own line (expanded style).
Note: A method definition is not considered empty if it contains comments.
Example: EnforcedStyle: compact (default)
# bad
def foo(bar)
end
def self.foo(bar)
end
# good
def foo(bar); end
def foo(bar)
# baz
end
def self.foo(bar); end
Example: EnforcedStyle: expanded
# bad
def foo(bar); end
def self.foo(bar); end
# good
def foo(bar)
end
def self.foo(bar)
end
Add an empty line after magic comments. (https://github.com/bbatsov/ruby-style-guide#separate-magic-comments-from-code) Open
module ActiveMocker
- 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
Add an empty line after magic comments. (https://github.com/bbatsov/ruby-style-guide#separate-magic-comments-from-code) Open
module ActiveMocker
- 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
Provide an exception class and message as arguments to raise
. (https://github.com/bbatsov/ruby-style-guide#exception-class-messages) Open
raise RecordNotFound.new("Couldn't find #{name} without an ID") if ids.nil?
- Read upRead up
- Exclude checks
This cop checks the args passed to fail
and raise
. For exploded
style (default), it recommends passing the exception class and message
to raise
, rather than construct an instance of the error. It will
still allow passing just a message, or the construction of an error
with more than one argument.
The exploded style works identically, but with the addition that it will also suggest constructing error objects when the exception is passed multiple arguments.
Example: EnforcedStyle: exploded (default)
# bad
raise StandardError.new("message")
# good
raise StandardError, "message"
fail "message"
raise MyCustomError.new(arg1, arg2, arg3)
raise MyKwArgError.new(key1: val1, key2: val2)
Example: EnforcedStyle: compact
# bad
raise StandardError, "message"
raise RuntimeError, arg1, arg2, arg3
# good
raise StandardError.new("message")
raise MyCustomError.new(arg1, arg2, arg3)
fail "message"
Provide an exception class and message as arguments to raise
. (https://github.com/bbatsov/ruby-style-guide#exception-class-messages) Open
raise RecordNotFound.new("Couldn't find #{name} with '#{conditions.keys.first}'=#{conditions.values.first}")
- Read upRead up
- Exclude checks
This cop checks the args passed to fail
and raise
. For exploded
style (default), it recommends passing the exception class and message
to raise
, rather than construct an instance of the error. It will
still allow passing just a message, or the construction of an error
with more than one argument.
The exploded style works identically, but with the addition that it will also suggest constructing error objects when the exception is passed multiple arguments.
Example: EnforcedStyle: exploded (default)
# bad
raise StandardError.new("message")
# good
raise StandardError, "message"
fail "message"
raise MyCustomError.new(arg1, arg2, arg3)
raise MyKwArgError.new(key1: val1, key2: val2)
Example: EnforcedStyle: compact
# bad
raise StandardError, "message"
raise RuntimeError, arg1, arg2, arg3
# good
raise StandardError.new("message")
raise MyCustomError.new(arg1, arg2, arg3)
fail "message"
Add an empty line after magic comments. (https://github.com/bbatsov/ruby-style-guide#separate-magic-comments-from-code) Open
module ActiveMocker
- 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
Missing magic comment # frozen_string_literal: true
. Open
module ActiveMocker
- Read upRead up
- Exclude checks
This cop is designed to help upgrade to Ruby 3.0. 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 Ruby 3.0. The comment will be added below a shebang and encoding
comment. The frozen string literal comment is only valid in Ruby 2.3+.
Example: EnforcedStyle: when_needed (default)
# The `when_needed` style will add the frozen string literal comment
# to files only when the `TargetRubyVersion` is set to 2.3+.
# bad
module Foo
# ...
end
# good
# frozen_string_literal: true
module Foo
# ...
end
Example: EnforcedStyle: always
# 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
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