Showing 83 of 83 total issues
Use a guard clause instead of wrapping the code inside a conditional expression. Open
if (association_foreign_key = find_association_fk).present?
- 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
Line is too long. [125/100] Open
%i[execute do_execute rename_column change_column column_for tables indexes select_all] & self.class.connection.methods
- Exclude checks
Avoid rescuing the Exception
class. Perhaps you meant to rescue StandardError
? Open
rescue Exception => exception
if @options[:debug]
warn "Failed: #{exception.class}: #{exception.message}"
warn exception.backtrace.map { |trace| " from #{trace}" }
end
- Read upRead up
- Exclude checks
This cop checks for rescue blocks targeting the Exception class.
Example:
# bad
begin
do_something
rescue Exception
handle_exception
end
Example:
# good
begin
do_something
rescue ArgumentError
handle_exception
end
Missing top-level class documentation comment. Open
class MigrationMocker
- Read upRead up
- Exclude checks
This cop checks for missing top-level documentation of classes and modules. Classes with no body are exempt from the check and so are namespace modules - modules that have nothing in their bodies except classes, other modules, or constant definitions.
The documentation requirement is annulled if the class or module has a "#:nodoc:" comment next to it. Likewise, "#:nodoc: all" does the same for all its children.
Example:
# bad
class Person
# ...
end
# good
# Description/Explanation of Person class
class Person
# ...
end
required_ruby_version
(2.0, declared in lol_dba.gemspec) and TargetRubyVersion
(2.1, declared in .rubocop.yml) should be equal. Open
s.required_ruby_version = '>= 2.0.0'
- Read upRead up
- Exclude checks
Checks that required_ruby_version
of gemspec and TargetRubyVersion
of .rubocop.yml are equal.
Thereby, RuboCop to perform static analysis working on the version
required by gemspec.
Example:
# When `TargetRubyVersion` of .rubocop.yml is `2.3`.
# bad
Gem::Specification.new do |spec|
spec.required_ruby_version = '>= 2.2.0'
end
# bad
Gem::Specification.new do |spec|
spec.required_ruby_version = '>= 2.4.0'
end
# good
Gem::Specification.new do |spec|
spec.required_ruby_version = '>= 2.3.0'
end
# good
Gem::Specification.new do |spec|
spec.required_ruby_version = '>= 2.3'
end
# good
Gem::Specification.new do |spec|
spec.required_ruby_version = ['>= 2.3.0', '< 2.5.0']
end
Missing top-level class documentation comment. Open
class RelationInspectorFactory
- Read upRead up
- Exclude checks
This cop checks for missing top-level documentation of classes and modules. Classes with no body are exempt from the check and so are namespace modules - modules that have nothing in their bodies except classes, other modules, or constant definitions.
The documentation requirement is annulled if the class or module has a "#:nodoc:" comment next to it. Likewise, "#:nodoc: all" does the same for all its children.
Example:
# bad
class Person
# ...
end
# good
# Description/Explanation of Person class
class Person
# ...
end
Missing top-level class documentation comment. Open
class SqlGenerator
- Read upRead up
- Exclude checks
This cop checks for missing top-level documentation of classes and modules. Classes with no body are exempt from the check and so are namespace modules - modules that have nothing in their bodies except classes, other modules, or constant definitions.
The documentation requirement is annulled if the class or module has a "#:nodoc:" comment next to it. Likewise, "#:nodoc: all" does the same for all its children.
Example:
# bad
class Person
# ...
end
# good
# Description/Explanation of Person class
class Person
# ...
end
Parenthesize the param exception.backtrace.map { |trace| " from #{trace}" }
to make sure that the block will be associated with the exception.backtrace.map
method call. Open
warn exception.backtrace.map { |trace| " from #{trace}" }
- Read upRead up
- Exclude checks
This cop checks for ambiguous block association with method when param passed without parentheses.
Example:
# bad
some_method a { |val| puts val }
Example:
# good
# With parentheses, there's no ambiguity.
some_method(a) { |val| puts val }
# good
# Operator methods require no disambiguation
foo == bar { |b| b.baz }
# good
# Lambda arguments require no disambiguation
foo = ->(bar) { bar.baz }
Missing top-level class documentation comment. Open
class CLI
- Read upRead up
- Exclude checks
This cop checks for missing top-level documentation of classes and modules. Classes with no body are exempt from the check and so are namespace modules - modules that have nothing in their bodies except classes, other modules, or constant definitions.
The documentation requirement is annulled if the class or module has a "#:nodoc:" comment next to it. Likewise, "#:nodoc: all" does the same for all its children.
Example:
# bad
class Person
# ...
end
# good
# Description/Explanation of Person class
class Person
# ...
end
Prefer $ERROR_INFO
from the stdlib 'English' module (don't forget to require it) over $!
. Open
raise $!
- Exclude checks
Missing top-level class documentation comment. Open
class RailsCompatibility
- Read upRead up
- Exclude checks
This cop checks for missing top-level documentation of classes and modules. Classes with no body are exempt from the check and so are namespace modules - modules that have nothing in their bodies except classes, other modules, or constant definitions.
The documentation requirement is annulled if the class or module has a "#:nodoc:" comment next to it. Likewise, "#:nodoc: all" does the same for all its children.
Example:
# bad
class Person
# ...
end
# good
# Description/Explanation of Person class
class Person
# ...
end
Freeze mutable objects assigned to constants. Open
VERSION = '2.4.0' unless defined? LolDba::VERSION
- Read upRead up
- Exclude checks
This cop checks whether some constant value isn't a mutable literal (e.g. array or hash).
Example:
# bad
CONST = [1, 2, 3]
# good
CONST = [1, 2, 3].freeze
Missing top-level class documentation comment. Open
class HasMany < RelationInspector
- Read upRead up
- Exclude checks
This cop checks for missing top-level documentation of classes and modules. Classes with no body are exempt from the check and so are namespace modules - modules that have nothing in their bodies except classes, other modules, or constant definitions.
The documentation requirement is annulled if the class or module has a "#:nodoc:" comment next to it. Likewise, "#:nodoc: all" does the same for all its children.
Example:
# bad
class Person
# ...
end
# good
# Description/Explanation of Person class
class Person
# ...
end
Missing top-level class documentation comment. Open
class HasAndBelongsToMany < RelationInspector
- Read upRead up
- Exclude checks
This cop checks for missing top-level documentation of classes and modules. Classes with no body are exempt from the check and so are namespace modules - modules that have nothing in their bodies except classes, other modules, or constant definitions.
The documentation requirement is annulled if the class or module has a "#:nodoc:" comment next to it. Likewise, "#:nodoc: all" does the same for all its children.
Example:
# bad
class Person
# ...
end
# good
# Description/Explanation of Person class
class Person
# ...
end
Missing top-level class documentation comment. Open
class Railtie < Rails::Railtie
- Read upRead up
- Exclude checks
This cop checks for missing top-level documentation of classes and modules. Classes with no body are exempt from the check and so are namespace modules - modules that have nothing in their bodies except classes, other modules, or constant definitions.
The documentation requirement is annulled if the class or module has a "#:nodoc:" comment next to it. Likewise, "#:nodoc: all" does the same for all its children.
Example:
# bad
class Person
# ...
end
# good
# Description/Explanation of Person class
class Person
# ...
end
Missing top-level class documentation comment. Open
class Writer
- Read upRead up
- Exclude checks
This cop checks for missing top-level documentation of classes and modules. Classes with no body are exempt from the check and so are namespace modules - modules that have nothing in their bodies except classes, other modules, or constant definitions.
The documentation requirement is annulled if the class or module has a "#:nodoc:" comment next to it. Likewise, "#:nodoc: all" does the same for all its children.
Example:
# bad
class Person
# ...
end
# good
# Description/Explanation of Person class
class Person
# ...
end
Missing top-level class documentation comment. Open
class RelationInspector
- Read upRead up
- Exclude checks
This cop checks for missing top-level documentation of classes and modules. Classes with no body are exempt from the check and so are namespace modules - modules that have nothing in their bodies except classes, other modules, or constant definitions.
The documentation requirement is annulled if the class or module has a "#:nodoc:" comment next to it. Likewise, "#:nodoc: all" does the same for all its children.
Example:
# bad
class Person
# ...
end
# good
# Description/Explanation of Person class
class Person
# ...
end
Useless assignment to variable - foreign_key
. Use ||
instead of ||=
. Open
foreign_key ||= if reflection_options.respond_to?(:primary_key_name)
- 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
Use 2 spaces for indentation in a heredoc by using some library(e.g. ActiveSupport's String#strip_heredoc
). Open
* TIP: if you have a problem with the index name('index name too long'), you can
solve with the :name option. Something like :name => 'my_index'.
* run `rails g migration AddMissingIndexes` and add the following content:
class AddMissingIndexes < ActiveRecord::Migration
- Read upRead up
- Exclude checks
This cops checks the indentation of the here document bodies. The bodies
are indented one step.
In Ruby 2.3 or newer, squiggly heredocs (<<~
) should be used. If you
use the older rubies, you should introduce some library to your project
(e.g. ActiveSupport, Powerpack or Unindent).
Note: When Metrics/LineLength
's AllowHeredoc
is false(not default),
this cop does not add any offenses for long here documents to
avoid Metrics/LineLength
's offenses.
Example:
# bad
<<-RUBY
something
RUBY
# good
# When EnforcedStyle is squiggly, bad code is auto-corrected to the
# following code.
<<~RUBY
something
RUBY
# good
# When EnforcedStyle is active_support, bad code is auto-corrected to
# the following code.
<<-RUBY.strip_heredoc
something
RUBY
Missing top-level class documentation comment. Open
class Migration
- Read upRead up
- Exclude checks
This cop checks for missing top-level documentation of classes and modules. Classes with no body are exempt from the check and so are namespace modules - modules that have nothing in their bodies except classes, other modules, or constant definitions.
The documentation requirement is annulled if the class or module has a "#:nodoc:" comment next to it. Likewise, "#:nodoc: all" does the same for all its children.
Example:
# bad
class Person
# ...
end
# good
# Description/Explanation of Person class
class Person
# ...
end