rubocop-rails 2.14.2 → 2.15.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (108) hide show
  1. checksums.yaml +4 -4
  2. data/config/default.yml +37 -6
  3. data/lib/rubocop/cop/rails/action_filter.rb +1 -1
  4. data/lib/rubocop/cop/rails/active_record_callbacks_order.rb +1 -1
  5. data/lib/rubocop/cop/rails/active_support_aliases.rb +1 -1
  6. data/lib/rubocop/cop/rails/add_column_index.rb +1 -1
  7. data/lib/rubocop/cop/rails/after_commit_override.rb +1 -1
  8. data/lib/rubocop/cop/rails/application_controller.rb +1 -1
  9. data/lib/rubocop/cop/rails/application_job.rb +1 -1
  10. data/lib/rubocop/cop/rails/application_mailer.rb +1 -1
  11. data/lib/rubocop/cop/rails/application_record.rb +1 -1
  12. data/lib/rubocop/cop/rails/arel_star.rb +1 -1
  13. data/lib/rubocop/cop/rails/attribute_default_block_value.rb +1 -1
  14. data/lib/rubocop/cop/rails/belongs_to.rb +1 -1
  15. data/lib/rubocop/cop/rails/blank.rb +4 -4
  16. data/lib/rubocop/cop/rails/bulk_change_table.rb +1 -1
  17. data/lib/rubocop/cop/rails/compact_blank.rb +1 -1
  18. data/lib/rubocop/cop/rails/content_tag.rb +1 -1
  19. data/lib/rubocop/cop/rails/create_table_with_timestamps.rb +1 -1
  20. data/lib/rubocop/cop/rails/date.rb +8 -8
  21. data/lib/rubocop/cop/rails/default_scope.rb +1 -1
  22. data/lib/rubocop/cop/rails/delegate.rb +1 -1
  23. data/lib/rubocop/cop/rails/delegate_allow_blank.rb +1 -1
  24. data/lib/rubocop/cop/rails/deprecated_active_model_errors_methods.rb +56 -2
  25. data/lib/rubocop/cop/rails/dot_separated_keys.rb +71 -0
  26. data/lib/rubocop/cop/rails/duplicate_association.rb +2 -2
  27. data/lib/rubocop/cop/rails/duplicate_scope.rb +1 -1
  28. data/lib/rubocop/cop/rails/duration_arithmetic.rb +1 -1
  29. data/lib/rubocop/cop/rails/dynamic_find_by.rb +1 -1
  30. data/lib/rubocop/cop/rails/eager_evaluation_log_message.rb +1 -1
  31. data/lib/rubocop/cop/rails/enum_hash.rb +2 -3
  32. data/lib/rubocop/cop/rails/enum_uniqueness.rb +1 -1
  33. data/lib/rubocop/cop/rails/environment_comparison.rb +1 -1
  34. data/lib/rubocop/cop/rails/environment_variable_access.rb +1 -1
  35. data/lib/rubocop/cop/rails/exit.rb +1 -1
  36. data/lib/rubocop/cop/rails/expanded_date_range.rb +1 -1
  37. data/lib/rubocop/cop/rails/file_path.rb +12 -9
  38. data/lib/rubocop/cop/rails/find_by.rb +1 -1
  39. data/lib/rubocop/cop/rails/find_by_id.rb +1 -1
  40. data/lib/rubocop/cop/rails/find_each.rb +1 -1
  41. data/lib/rubocop/cop/rails/has_and_belongs_to_many.rb +1 -1
  42. data/lib/rubocop/cop/rails/has_many_or_has_one_dependent.rb +10 -2
  43. data/lib/rubocop/cop/rails/helper_instance_variable.rb +2 -2
  44. data/lib/rubocop/cop/rails/http_positional_arguments.rb +1 -1
  45. data/lib/rubocop/cop/rails/i18n_lazy_lookup.rb +1 -1
  46. data/lib/rubocop/cop/rails/i18n_locale_assignment.rb +1 -1
  47. data/lib/rubocop/cop/rails/ignored_skip_action_filter_option.rb +2 -2
  48. data/lib/rubocop/cop/rails/index_by.rb +1 -1
  49. data/lib/rubocop/cop/rails/index_with.rb +1 -1
  50. data/lib/rubocop/cop/rails/inquiry.rb +1 -1
  51. data/lib/rubocop/cop/rails/inverse_of.rb +1 -1
  52. data/lib/rubocop/cop/rails/lexically_scoped_action_filter.rb +3 -3
  53. data/lib/rubocop/cop/rails/link_to_blank.rb +1 -1
  54. data/lib/rubocop/cop/rails/mailer_name.rb +1 -1
  55. data/lib/rubocop/cop/rails/match_route.rb +1 -1
  56. data/lib/rubocop/cop/rails/migration_class_name.rb +1 -1
  57. data/lib/rubocop/cop/rails/negate_include.rb +1 -1
  58. data/lib/rubocop/cop/rails/not_null_column.rb +1 -1
  59. data/lib/rubocop/cop/rails/order_by_id.rb +2 -3
  60. data/lib/rubocop/cop/rails/output.rb +1 -1
  61. data/lib/rubocop/cop/rails/output_safety.rb +1 -1
  62. data/lib/rubocop/cop/rails/pick.rb +1 -1
  63. data/lib/rubocop/cop/rails/pluck.rb +1 -1
  64. data/lib/rubocop/cop/rails/pluck_id.rb +1 -1
  65. data/lib/rubocop/cop/rails/pluck_in_where.rb +1 -1
  66. data/lib/rubocop/cop/rails/pluralization_grammar.rb +1 -1
  67. data/lib/rubocop/cop/rails/presence.rb +1 -1
  68. data/lib/rubocop/cop/rails/present.rb +2 -2
  69. data/lib/rubocop/cop/rails/rake_environment.rb +1 -1
  70. data/lib/rubocop/cop/rails/read_write_attribute.rb +1 -1
  71. data/lib/rubocop/cop/rails/redundant_foreign_key.rb +1 -1
  72. data/lib/rubocop/cop/rails/redundant_receiver_in_with_options.rb +1 -1
  73. data/lib/rubocop/cop/rails/redundant_travel_back.rb +1 -1
  74. data/lib/rubocop/cop/rails/reflection_class_name.rb +1 -1
  75. data/lib/rubocop/cop/rails/relative_date_constant.rb +1 -1
  76. data/lib/rubocop/cop/rails/render_inline.rb +1 -1
  77. data/lib/rubocop/cop/rails/render_plain_text.rb +1 -1
  78. data/lib/rubocop/cop/rails/request_referer.rb +1 -1
  79. data/lib/rubocop/cop/rails/require_dependency.rb +1 -1
  80. data/lib/rubocop/cop/rails/reversible_migration.rb +1 -1
  81. data/lib/rubocop/cop/rails/reversible_migration_method_definition.rb +4 -4
  82. data/lib/rubocop/cop/rails/root_public_path.rb +59 -0
  83. data/lib/rubocop/cop/rails/safe_navigation.rb +7 -12
  84. data/lib/rubocop/cop/rails/safe_navigation_with_blank.rb +1 -1
  85. data/lib/rubocop/cop/rails/save_bang.rb +2 -2
  86. data/lib/rubocop/cop/rails/schema_comment.rb +1 -1
  87. data/lib/rubocop/cop/rails/scope_args.rb +1 -1
  88. data/lib/rubocop/cop/rails/short_i18n.rb +1 -1
  89. data/lib/rubocop/cop/rails/skips_model_validations.rb +1 -1
  90. data/lib/rubocop/cop/rails/squished_sql_heredocs.rb +1 -1
  91. data/lib/rubocop/cop/rails/strip_heredoc.rb +56 -0
  92. data/lib/rubocop/cop/rails/table_name_assignment.rb +1 -1
  93. data/lib/rubocop/cop/rails/time_zone.rb +7 -7
  94. data/lib/rubocop/cop/rails/time_zone_assignment.rb +3 -3
  95. data/lib/rubocop/cop/rails/to_formatted_s.rb +46 -0
  96. data/lib/rubocop/cop/rails/transaction_exit_statement.rb +17 -10
  97. data/lib/rubocop/cop/rails/unique_validation_without_index.rb +2 -2
  98. data/lib/rubocop/cop/rails/unknown_env.rb +1 -1
  99. data/lib/rubocop/cop/rails/unused_ignored_columns.rb +1 -1
  100. data/lib/rubocop/cop/rails/validation.rb +1 -1
  101. data/lib/rubocop/cop/rails/where_equals.rb +1 -1
  102. data/lib/rubocop/cop/rails/where_exists.rb +2 -2
  103. data/lib/rubocop/cop/rails/where_not.rb +1 -1
  104. data/lib/rubocop/cop/rails_cops.rb +4 -0
  105. data/lib/rubocop/rails/schema_loader/schema.rb +8 -5
  106. data/lib/rubocop/rails/version.rb +1 -1
  107. data/lib/rubocop-rails.rb +8 -0
  108. metadata +9 -5
@@ -3,7 +3,7 @@
3
3
  module RuboCop
4
4
  module Cop
5
5
  module Rails
6
- # This cop checks that Rails.env is compared using `.production?`-like
6
+ # Checks that Rails.env is compared using `.production?`-like
7
7
  # methods instead of equality against a string or symbol.
8
8
  #
9
9
  # @example
@@ -3,7 +3,7 @@
3
3
  module RuboCop
4
4
  module Cop
5
5
  module Rails
6
- # This cop looks for direct access to environment variables through the
6
+ # Looks for direct access to environment variables through the
7
7
  # `ENV` variable within the application code. This can lead to runtime
8
8
  # errors due to misconfiguration that could have been discovered at boot
9
9
  # time if the environment variables were loaded as part of initialization
@@ -3,7 +3,7 @@
3
3
  module RuboCop
4
4
  module Cop
5
5
  module Rails
6
- # This cop enforces that `exit` calls are not used within a rails app.
6
+ # Enforces that `exit` calls are not used within a rails app.
7
7
  # Valid options are instead to raise an error, break, return, or some
8
8
  # other form of stopping execution of current request.
9
9
  #
@@ -3,7 +3,7 @@
3
3
  module RuboCop
4
4
  module Cop
5
5
  module Rails
6
- # This cop checks for expanded date range. It only compatible `..` range is targeted.
6
+ # Checks for expanded date range. It only compatible `..` range is targeted.
7
7
  # Incompatible `...` range is ignored.
8
8
  #
9
9
  # @example
@@ -3,27 +3,27 @@
3
3
  module RuboCop
4
4
  module Cop
5
5
  module Rails
6
- # This cop is used to identify usages of file path joining process
6
+ # Identifies usages of file path joining process
7
7
  # to use `Rails.root.join` clause. It is used to add uniformity when
8
8
  # joining paths.
9
9
  #
10
- # @example EnforcedStyle: arguments
10
+ # @example EnforcedStyle: slashes (default)
11
11
  # # bad
12
- # Rails.root.join('app/models/goober')
12
+ # Rails.root.join('app', 'models', 'goober')
13
13
  # File.join(Rails.root, 'app/models/goober')
14
14
  # "#{Rails.root}/app/models/goober"
15
15
  #
16
16
  # # good
17
- # Rails.root.join('app', 'models', 'goober')
17
+ # Rails.root.join('app/models/goober')
18
18
  #
19
- # @example EnforcedStyle: slashes (default)
19
+ # @example EnforcedStyle: arguments
20
20
  # # bad
21
- # Rails.root.join('app', 'models', 'goober')
21
+ # Rails.root.join('app/models/goober')
22
22
  # File.join(Rails.root, 'app/models/goober')
23
23
  # "#{Rails.root}/app/models/goober"
24
24
  #
25
25
  # # good
26
- # Rails.root.join('app/models/goober')
26
+ # Rails.root.join('app', 'models', 'goober')
27
27
  #
28
28
  class FilePath < Base
29
29
  include ConfigurableEnforcedStyle
@@ -48,8 +48,11 @@ module RuboCop
48
48
  def on_dstr(node)
49
49
  return unless rails_root_nodes?(node)
50
50
  return unless node.children.last.str_type?
51
- return unless node.children.last.source.start_with?('.') ||
52
- node.children.last.source.include?(File::SEPARATOR)
51
+
52
+ last_child_source = node.children.last.source
53
+ return unless last_child_source.start_with?('.') ||
54
+ last_child_source.include?(File::SEPARATOR)
55
+ return if last_child_source.start_with?(':')
53
56
 
54
57
  register_offense(node)
55
58
  end
@@ -3,7 +3,7 @@
3
3
  module RuboCop
4
4
  module Cop
5
5
  module Rails
6
- # This cop is used to identify usages of `where.take` and change them to use `find_by` instead.
6
+ # Identifies usages of `where.take` and change them to use `find_by` instead.
7
7
  #
8
8
  # And `where(...).first` can return different results from `find_by`.
9
9
  # (They order records differently, so the "first" record can be different.)
@@ -3,7 +3,7 @@
3
3
  module RuboCop
4
4
  module Cop
5
5
  module Rails
6
- # This cop enforces that `ActiveRecord#find` is used instead of
6
+ # Enforces that `ActiveRecord#find` is used instead of
7
7
  # `where.take!`, `find_by!`, and `find_by_id!` to retrieve a single record
8
8
  # by primary key when you expect it to be found.
9
9
  #
@@ -3,7 +3,7 @@
3
3
  module RuboCop
4
4
  module Cop
5
5
  module Rails
6
- # This cop is used to identify usages of `all.each` and
6
+ # Identifies usages of `all.each` and
7
7
  # change them to use `all.find_each` instead.
8
8
  #
9
9
  # @example
@@ -3,7 +3,7 @@
3
3
  module RuboCop
4
4
  module Cop
5
5
  module Rails
6
- # This cop checks for the use of the has_and_belongs_to_many macro.
6
+ # Checks for the use of the has_and_belongs_to_many macro.
7
7
  #
8
8
  # @example
9
9
  # # bad
@@ -3,7 +3,7 @@
3
3
  module RuboCop
4
4
  module Cop
5
5
  module Rails
6
- # This cop looks for `has_many` or `has_one` associations that don't
6
+ # Looks for `has_many` or `has_one` associations that don't
7
7
  # specify a `:dependent` option.
8
8
  #
9
9
  # It doesn't register an offense if `:through` or `dependent: nil`
@@ -116,7 +116,7 @@ module RuboCop
116
116
  def valid_options?(options)
117
117
  return false if options.nil?
118
118
 
119
- options = options.first.children.first.pairs if options.first.kwsplat_type?
119
+ options = extract_option_if_kwsplat(options)
120
120
 
121
121
  return true unless options
122
122
  return true if options.any? do |o|
@@ -126,6 +126,14 @@ module RuboCop
126
126
  false
127
127
  end
128
128
 
129
+ def extract_option_if_kwsplat(options)
130
+ if options.first.kwsplat_type? && options.first.children.first.hash_type?
131
+ return options.first.children.first.pairs
132
+ end
133
+
134
+ options
135
+ end
136
+
129
137
  def active_resource?(node)
130
138
  return false if node.nil?
131
139
 
@@ -3,14 +3,14 @@
3
3
  module RuboCop
4
4
  module Cop
5
5
  module Rails
6
- # This cop checks for use of the helper methods which reference
6
+ # Checks for use of the helper methods which reference
7
7
  # instance variables.
8
8
  #
9
9
  # Relying on instance variables makes it difficult to re-use helper
10
10
  # methods.
11
11
  #
12
12
  # If it seems awkward to explicitly pass in each dependent
13
- # variable, consider moving the behaviour elsewhere, for
13
+ # variable, consider moving the behavior elsewhere, for
14
14
  # example to a model, decorator or presenter.
15
15
  #
16
16
  # Provided that a class inherits `ActionView::Helpers::FormBuilder`,
@@ -3,7 +3,7 @@
3
3
  module RuboCop
4
4
  module Cop
5
5
  module Rails
6
- # This cop is used to identify usages of http methods like `get`, `post`,
6
+ # Identifies usages of http methods like `get`, `post`,
7
7
  # `put`, `patch` without the usage of keyword arguments in your tests and
8
8
  # change them to use keyword args. This cop only applies to Rails >= 5.
9
9
  # If you are running Rails < 5 you should disable the
@@ -3,7 +3,7 @@
3
3
  module RuboCop
4
4
  module Cop
5
5
  module Rails
6
- # This cop checks for places where I18n "lazy" lookup can be used.
6
+ # Checks for places where I18n "lazy" lookup can be used.
7
7
  #
8
8
  # @example
9
9
  # # en.yml
@@ -3,7 +3,7 @@
3
3
  module RuboCop
4
4
  module Cop
5
5
  module Rails
6
- # This cop checks for the use of `I18n.locale=` method.
6
+ # Checks for the use of `I18n.locale=` method.
7
7
  #
8
8
  # The `locale` attribute persists for the rest of the Ruby runtime, potentially causing
9
9
  # unexpected behavior at a later time.
@@ -3,7 +3,7 @@
3
3
  module RuboCop
4
4
  module Cop
5
5
  module Rails
6
- # This cop checks that `if` and `only` (or `except`) are not used together
6
+ # Checks that `if` and `only` (or `except`) are not used together
7
7
  # as options of `skip_*` action filter.
8
8
  #
9
9
  # The `if` option will be ignored when `if` and `only` are used together.
@@ -80,7 +80,7 @@ module RuboCop
80
80
  def options_hash(options)
81
81
  options.pairs
82
82
  .select { |pair| pair.key.sym_type? }
83
- .map { |pair| [pair.key.value, pair] }.to_h
83
+ .to_h { |pair| [pair.key.value, pair] }
84
84
  end
85
85
 
86
86
  def if_and_only?(options)
@@ -3,7 +3,7 @@
3
3
  module RuboCop
4
4
  module Cop
5
5
  module Rails
6
- # This cop looks for uses of `each_with_object({}) { ... }`,
6
+ # Looks for uses of `each_with_object({}) { ... }`,
7
7
  # `map { ... }.to_h`, and `Hash[map { ... }]` that are transforming
8
8
  # an enumerable into a hash where the values are the original elements.
9
9
  # Rails provides the `index_by` method for this purpose.
@@ -3,7 +3,7 @@
3
3
  module RuboCop
4
4
  module Cop
5
5
  module Rails
6
- # This cop looks for uses of `each_with_object({}) { ... }`,
6
+ # Looks for uses of `each_with_object({}) { ... }`,
7
7
  # `map { ... }.to_h`, and `Hash[map { ... }]` that are transforming
8
8
  # an enumerable into a hash where the keys are the original elements.
9
9
  # Rails provides the `index_with` method for this purpose.
@@ -3,7 +3,7 @@
3
3
  module RuboCop
4
4
  module Cop
5
5
  module Rails
6
- # This cop checks that Active Support's `inquiry` method is not used.
6
+ # Checks that Active Support's `inquiry` method is not used.
7
7
  #
8
8
  # @example
9
9
  # # bad - String#inquiry
@@ -3,7 +3,7 @@
3
3
  module RuboCop
4
4
  module Cop
5
5
  module Rails
6
- # This cop looks for has_(one|many) and belongs_to associations where
6
+ # Looks for has_(one|many) and belongs_to associations where
7
7
  # Active Record can't automatically determine the inverse association
8
8
  # because of a scope or the options used. Using the blog with order scope
9
9
  # example below, traversing the a Blog's association in both directions
@@ -3,7 +3,7 @@
3
3
  module RuboCop
4
4
  module Cop
5
5
  module Rails
6
- # This cop checks that methods specified in the filter's `only` or
6
+ # Checks that methods specified in the filter's `only` or
7
7
  # `except` options are defined within the same class or module.
8
8
  #
9
9
  # @safety
@@ -12,7 +12,7 @@ module RuboCop
12
12
  # methods that are defined in other classes or modules, you should
13
13
  # define the filter in that class or module.
14
14
  #
15
- # If you rely on behaviour defined in the superclass actions, you must
15
+ # If you rely on behavior defined in the superclass actions, you must
16
16
  # remember to invoke `super` in the subclass actions.
17
17
  #
18
18
  # @example
@@ -71,7 +71,7 @@ module RuboCop
71
71
  # class ArticlesController < ContentController
72
72
  # before_action :load_article, only: [:update]
73
73
  #
74
- # # the cop requires this method, but it relies on behaviour defined
74
+ # # the cop requires this method, but it relies on behavior defined
75
75
  # # in the superclass, so needs to invoke `super`
76
76
  # def update
77
77
  # super
@@ -3,7 +3,7 @@
3
3
  module RuboCop
4
4
  module Cop
5
5
  module Rails
6
- # This cop checks for calls to `link_to` that contain a
6
+ # Checks for calls to `link_to` that contain a
7
7
  # `target: '_blank'` but no `rel: 'noopener'`. This can be a security
8
8
  # risk as the loaded page will have control over the previous page
9
9
  # and could change its location for phishing purposes.
@@ -3,7 +3,7 @@
3
3
  module RuboCop
4
4
  module Cop
5
5
  module Rails
6
- # This cop enforces that mailer names end with `Mailer` suffix.
6
+ # Enforces that mailer names end with `Mailer` suffix.
7
7
  #
8
8
  # Without the `Mailer` suffix it isn't immediately apparent what's a mailer
9
9
  # and which views are related to the mailer.
@@ -3,7 +3,7 @@
3
3
  module RuboCop
4
4
  module Cop
5
5
  module Rails
6
- # This cop identifies places where defining routes with `match`
6
+ # Identifies places where defining routes with `match`
7
7
  # can be replaced with a specific HTTP method.
8
8
  #
9
9
  # Don't use `match` to define any routes unless there is a need to map multiple request types
@@ -3,7 +3,7 @@
3
3
  module RuboCop
4
4
  module Cop
5
5
  module Rails
6
- # This cop makes sure that each migration file defines a migration class
6
+ # Makes sure that each migration file defines a migration class
7
7
  # whose name matches the file name.
8
8
  # (e.g. `20220224111111_create_users.rb` should define `CreateUsers` class.)
9
9
  #
@@ -3,7 +3,7 @@
3
3
  module RuboCop
4
4
  module Cop
5
5
  module Rails
6
- # This cop enforces the use of `collection.exclude?(obj)`
6
+ # Enforces the use of `collection.exclude?(obj)`
7
7
  # over `!collection.include?(obj)`.
8
8
  #
9
9
  # @safety
@@ -3,7 +3,7 @@
3
3
  module RuboCop
4
4
  module Cop
5
5
  module Rails
6
- # This cop checks for add_column call with NOT NULL constraint
6
+ # Checks for add_column call with NOT NULL constraint
7
7
  # in migration file.
8
8
  #
9
9
  # @example
@@ -3,7 +3,7 @@
3
3
  module RuboCop
4
4
  module Cop
5
5
  module Rails
6
- # This cop checks for places where ordering by `id` column is used.
6
+ # Checks for places where ordering by `id` column is used.
7
7
  #
8
8
  # Don't use the `id` column for ordering. The sequence of ids is not guaranteed
9
9
  # to be in any particular order, despite often (incidentally) being chronological.
@@ -23,8 +23,7 @@ module RuboCop
23
23
  class OrderById < Base
24
24
  include RangeHelp
25
25
 
26
- MSG = 'Do not use the `id` column for ordering. '\
27
- 'Use a timestamp column to order chronologically.'
26
+ MSG = 'Do not use the `id` column for ordering. Use a timestamp column to order chronologically.'
28
27
  RESTRICT_ON_SEND = %i[order].freeze
29
28
 
30
29
  def_node_matcher :order_by_id?, <<~PATTERN
@@ -3,7 +3,7 @@
3
3
  module RuboCop
4
4
  module Cop
5
5
  module Rails
6
- # This cop checks for the use of output calls like puts and print
6
+ # Checks for the use of output calls like puts and print
7
7
  #
8
8
  # @safety
9
9
  # This cop's autocorrection is unsafe because depending on the Rails log level configuration,
@@ -3,7 +3,7 @@
3
3
  module RuboCop
4
4
  module Cop
5
5
  module Rails
6
- # This cop checks for the use of output safety calls like `html_safe`,
6
+ # Checks for the use of output safety calls like `html_safe`,
7
7
  # `raw`, and `safe_concat`. These methods do not escape content. They
8
8
  # simply return a SafeBuffer containing the content as is. Instead,
9
9
  # use `safe_join` to join content and escape it and concat to
@@ -3,7 +3,7 @@
3
3
  module RuboCop
4
4
  module Cop
5
5
  module Rails
6
- # This cop enforces the use of `pick` over `pluck(...).first`.
6
+ # Enforces the use of `pick` over `pluck(...).first`.
7
7
  #
8
8
  # Using `pluck` followed by `first` creates an intermediate array, which
9
9
  # `pick` avoids. When called on an Active Record relation, `pick` adds a
@@ -3,7 +3,7 @@
3
3
  module RuboCop
4
4
  module Cop
5
5
  module Rails
6
- # This cop enforces the use of `pluck` over `map`.
6
+ # Enforces the use of `pluck` over `map`.
7
7
  #
8
8
  # `pluck` can be used instead of `map` to extract a single key from each
9
9
  # element in an enumerable. When called on an Active Record relation, it
@@ -3,7 +3,7 @@
3
3
  module RuboCop
4
4
  module Cop
5
5
  module Rails
6
- # This cop enforces the use of `ids` over `pluck(:id)` and `pluck(primary_key)`.
6
+ # Enforces the use of `ids` over `pluck(:id)` and `pluck(primary_key)`.
7
7
  #
8
8
  # @safety
9
9
  # This cop is unsafe if the receiver object is not an Active Record object.
@@ -3,7 +3,7 @@
3
3
  module RuboCop
4
4
  module Cop
5
5
  module Rails
6
- # This cop identifies places where `pluck` is used in `where` query methods
6
+ # Identifies places where `pluck` is used in `where` query methods
7
7
  # and can be replaced with `select`.
8
8
  #
9
9
  # Since `pluck` is an eager method and hits the database immediately,
@@ -3,7 +3,7 @@
3
3
  module RuboCop
4
4
  module Cop
5
5
  module Rails
6
- # This cop checks for correct grammar when using ActiveSupport's
6
+ # Checks for correct grammar when using ActiveSupport's
7
7
  # core extensions to the numeric classes.
8
8
  #
9
9
  # @example
@@ -3,7 +3,7 @@
3
3
  module RuboCop
4
4
  module Cop
5
5
  module Rails
6
- # This cop checks code that can be written more easily using
6
+ # Checks code that can be written more easily using
7
7
  # `Object#presence` defined by Active Support.
8
8
  #
9
9
  # @example
@@ -3,13 +3,13 @@
3
3
  module RuboCop
4
4
  module Cop
5
5
  module Rails
6
- # This cop checks for code that can be written with simpler conditionals
6
+ # Checks for code that can be written with simpler conditionals
7
7
  # using `Object#present?` defined by Active Support.
8
8
  #
9
9
  # Interaction with `Style/UnlessElse`:
10
10
  # The configuration of `NotBlank` will not produce an offense in the
11
11
  # context of `unless else` if `Style/UnlessElse` is inabled. This is
12
- # to prevent interference between the auto-correction of the two cops.
12
+ # to prevent interference between the autocorrection of the two cops.
13
13
  #
14
14
  # @example NotNilAndNotEmpty: true (default)
15
15
  # # Converts usages of `!nil? && !empty?` to `present?`
@@ -3,7 +3,7 @@
3
3
  module RuboCop
4
4
  module Cop
5
5
  module Rails
6
- # This cop checks for Rake tasks without the `:environment` task
6
+ # Checks for Rake tasks without the `:environment` task
7
7
  # dependency. The `:environment` task loads application code for other
8
8
  # Rake tasks. Without it, tasks cannot make use of application code like
9
9
  # models.
@@ -3,7 +3,7 @@
3
3
  module RuboCop
4
4
  module Cop
5
5
  module Rails
6
- # This cop checks for the use of the `read_attribute` or `write_attribute`
6
+ # Checks for the use of the `read_attribute` or `write_attribute`
7
7
  # methods and recommends square brackets instead.
8
8
  #
9
9
  # If an attribute is missing from the instance (for example, when
@@ -3,7 +3,7 @@
3
3
  module RuboCop
4
4
  module Cop
5
5
  module Rails
6
- # This cop detects cases where the `:foreign_key` option on associations
6
+ # Detects cases where the `:foreign_key` option on associations
7
7
  # is redundant.
8
8
  #
9
9
  # @example
@@ -3,7 +3,7 @@
3
3
  module RuboCop
4
4
  module Cop
5
5
  module Rails
6
- # This cop checks for redundant receiver in `with_options`.
6
+ # Checks for redundant receiver in `with_options`.
7
7
  # Receiver is implicit from Rails 4.2 or higher.
8
8
  #
9
9
  # @example
@@ -3,7 +3,7 @@
3
3
  module RuboCop
4
4
  module Cop
5
5
  module Rails
6
- # This cop checks for redundant `travel_back` calls.
6
+ # Checks for redundant `travel_back` calls.
7
7
  # Since Rails 5.2, `travel_back` is automatically called at the end of the test.
8
8
  #
9
9
  # @example
@@ -3,7 +3,7 @@
3
3
  module RuboCop
4
4
  module Cop
5
5
  module Rails
6
- # This cop checks if the value of the option `class_name`, in
6
+ # Checks if the value of the option `class_name`, in
7
7
  # the definition of a reflection is a string.
8
8
  #
9
9
  # @safety
@@ -3,7 +3,7 @@
3
3
  module RuboCop
4
4
  module Cop
5
5
  module Rails
6
- # This cop checks whether constant value isn't relative date.
6
+ # Checks whether constant value isn't relative date.
7
7
  # Because the relative date will be evaluated only once.
8
8
  #
9
9
  # @safety
@@ -3,7 +3,7 @@
3
3
  module RuboCop
4
4
  module Cop
5
5
  module Rails
6
- # This cop looks for inline rendering within controller actions.
6
+ # Looks for inline rendering within controller actions.
7
7
  #
8
8
  # @example
9
9
  # # bad
@@ -3,7 +3,7 @@
3
3
  module RuboCop
4
4
  module Cop
5
5
  module Rails
6
- # This cop identifies places where `render text:` can be
6
+ # Identifies places where `render text:` can be
7
7
  # replaced with `render plain:`.
8
8
  #
9
9
  # @example
@@ -3,7 +3,7 @@
3
3
  module RuboCop
4
4
  module Cop
5
5
  module Rails
6
- # This cop checks for consistent uses of `request.referer` or
6
+ # Checks for consistent uses of `request.referer` or
7
7
  # `request.referrer`, depending on the cop's configuration.
8
8
  #
9
9
  # @example EnforcedStyle: referer (default)
@@ -3,7 +3,7 @@
3
3
  module RuboCop
4
4
  module Cop
5
5
  module Rails
6
- # This cop checks for the usage of `require_dependency`.
6
+ # Checks for the usage of `require_dependency`.
7
7
  #
8
8
  # `require_dependency` is an obsolete method for Rails applications running in Zeitwerk mode.
9
9
  # In Zeitwerk mode, the semantics should match Ruby's and no need to be defensive with load order,
@@ -3,7 +3,7 @@
3
3
  module RuboCop
4
4
  module Cop
5
5
  module Rails
6
- # This cop checks whether the change method of the migration file is
6
+ # Checks whether the change method of the migration file is
7
7
  # reversible.
8
8
  #
9
9
  # @example
@@ -3,7 +3,7 @@
3
3
  module RuboCop
4
4
  module Cop
5
5
  module Rails
6
- # This cop checks whether the migration implements
6
+ # Checks whether the migration implements
7
7
  # either a `change` method or both an `up` and a `down`
8
8
  # method.
9
9
  #
@@ -49,15 +49,15 @@ module RuboCop
49
49
  'both an `up` and a `down` method.'
50
50
 
51
51
  def_node_matcher :change_method?, <<~PATTERN
52
- [ #migration_class? `(def :change (args) _) ]
52
+ `(def :change (args) _)
53
53
  PATTERN
54
54
 
55
55
  def_node_matcher :up_and_down_methods?, <<~PATTERN
56
- [ #migration_class? `(def :up (args) _) `(def :down (args) _) ]
56
+ [`(def :up (args) _) `(def :down (args) _)]
57
57
  PATTERN
58
58
 
59
59
  def on_class(node)
60
- return if change_method?(node) || up_and_down_methods?(node)
60
+ return if !migration_class?(node) || change_method?(node) || up_and_down_methods?(node)
61
61
 
62
62
  add_offense(node)
63
63
  end