rubocop-rails 2.36.0 → 2.38.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (36) hide show
  1. checksums.yaml +4 -4
  2. data/lib/rubocop/cop/mixin/target_rails_version.rb +52 -0
  3. data/lib/rubocop/cop/mixin.rb +17 -0
  4. data/lib/rubocop/cop/rails/active_support_on_load.rb +1 -0
  5. data/lib/rubocop/cop/rails/application_controller.rb +1 -2
  6. data/lib/rubocop/cop/rails/application_job.rb +1 -2
  7. data/lib/rubocop/cop/rails/application_mailer.rb +1 -2
  8. data/lib/rubocop/cop/rails/application_record.rb +1 -2
  9. data/lib/rubocop/cop/rails/attribute_default_block_value.rb +9 -0
  10. data/lib/rubocop/cop/rails/bulk_change_table.rb +1 -0
  11. data/lib/rubocop/cop/rails/dangerous_column_names.rb +1 -2
  12. data/lib/rubocop/cop/rails/deprecated_active_model_errors_methods.rb +1 -0
  13. data/lib/rubocop/cop/rails/enum_hash.rb +1 -0
  14. data/lib/rubocop/cop/rails/http_positional_arguments.rb +9 -3
  15. data/lib/rubocop/cop/rails/inverse_of.rb +3 -2
  16. data/lib/rubocop/cop/rails/output.rb +1 -2
  17. data/lib/rubocop/cop/rails/pluck.rb +1 -2
  18. data/lib/rubocop/cop/rails/rake_environment.rb +50 -18
  19. data/lib/rubocop/cop/rails/read_write_attribute.rb +8 -0
  20. data/lib/rubocop/cop/rails/redirect_back_or_to.rb +1 -2
  21. data/lib/rubocop/cop/rails/redundant_receiver_in_with_options.rb +1 -2
  22. data/lib/rubocop/cop/rails/reversible_migration.rb +1 -0
  23. data/lib/rubocop/cop/rails/save_bang.rb +2 -4
  24. data/lib/rubocop/cop/rails/select_map.rb +1 -2
  25. data/lib/rubocop/cop/rails/strong_parameters_expect.rb +2 -4
  26. data/lib/rubocop/cop/rails/transaction_exit_statement.rb +2 -0
  27. data/lib/rubocop/cop/rails/unknown_env.rb +2 -0
  28. data/lib/rubocop/cop/rails/where_equals.rb +1 -2
  29. data/lib/rubocop/cop/rails/where_missing.rb +1 -2
  30. data/lib/rubocop/cop/rails/where_not.rb +1 -2
  31. data/lib/rubocop/cop/rails/where_range.rb +1 -2
  32. data/lib/rubocop/cop/rails.rb +152 -0
  33. data/lib/rubocop/cop/rails_cops.rb +4 -148
  34. data/lib/rubocop/rails/version.rb +1 -1
  35. data/lib/rubocop-rails.rb +1 -1
  36. metadata +6 -4
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 5fcf30164d8e9727b16702ab937a902890c342d02c1865e4588295a355380f7a
4
- data.tar.gz: 8c88a959e8b7b07e6751c6a385302deabc39f8bf328278b979d62c46becaccc7
3
+ metadata.gz: 934845fbf3f9e2a700b98f36bcd02c55bf2ec0ed4955931830e36463f3dc2793
4
+ data.tar.gz: a4623739f29604fa7869bc431442feea890337223628839e500672f2f74f1783
5
5
  SHA512:
6
- metadata.gz: bc070f9148d8b3b8d87c06cf95ae2b604eb81758548cfab082a38300760ac714ac0d1741e19c8c7d604563868be6b03b4c1b1bdc87af6d7999a4386aa37701d4
7
- data.tar.gz: 14e8a2fa9886a93625e49678688e7b00e2075bfcfa00a04adc23c3de5d3b8e9fd3c5be88b19e532d4cd30b1dc746320b273f0a2c7f7b984625e1a6874f16d649
6
+ metadata.gz: bf70f7da40827b323bf43d3ee9718177a11aeed5417f6a332d31a2a8edbd63733472819fd6bc658bcf1c47451b3f38125f2b84e1ac9de1aa6e8eb35593d52c32
7
+ data.tar.gz: 3db22831cd73b6c83abcba17c13fdf1b239fd94197644f311bc259433fdf78430f7e0051bdc9e27dbbb490e1e5c6887aa1e573a9d85512267fbfb78f09cfb871
@@ -11,6 +11,29 @@ module RuboCop
11
11
  # See https://github.com/rubocop/rubocop/pull/11289
12
12
  TARGET_GEM_NAME = 'railties' # :nodoc:
13
13
 
14
+ # Used when the target Rails version cannot be detected from `AllCops: TargetRailsVersion`
15
+ # or from the `railties` version in the target's lockfile.
16
+ DEFAULT_RAILS_VERSION = 5.0
17
+
18
+ # Resolves the target Rails version as a `major.minor` Float, using only stable RuboCop core APIs.
19
+ # Precedence: `AllCops: TargetRailsVersion`, then the `railties` version from the target's lockfile,
20
+ # then `DEFAULT_RAILS_VERSION`.
21
+ def self.resolve(config)
22
+ target_rails_version = config.for_all_cops['TargetRailsVersion']
23
+ return target_rails_version.to_f if target_rails_version
24
+
25
+ gem_versions_in_target = config.gem_versions_in_target
26
+ railties_version = gem_versions_in_target && gem_versions_in_target[TARGET_GEM_NAME]
27
+ return DEFAULT_RAILS_VERSION unless railties_version
28
+
29
+ segments = railties_version.segments
30
+ Float("#{segments[0]}.#{segments[1]}")
31
+ end
32
+
33
+ def self.extended(base)
34
+ base.include(InstanceMethods)
35
+ end
36
+
14
37
  def minimum_target_rails_version(version)
15
38
  case version
16
39
  when Integer, Float then requires_gem(TARGET_GEM_NAME, ">= #{version}")
@@ -26,6 +49,35 @@ module RuboCop
26
49
 
27
50
  gem_requirement.satisfied_by?(Gem::Version.new(version))
28
51
  end
52
+
53
+ # Instance methods for cops that use the resolved target Rails version at runtime,
54
+ # included automatically when a cop extends `TargetRailsVersion`.
55
+ # On RuboCop < 2.0, `#target_rails_version` shadows `RuboCop::Cop::Base#target_rails_version`,
56
+ # so the resolution is owned by rubocop-rails on all supported RuboCop versions.
57
+ module InstanceMethods
58
+ def target_rails_version
59
+ @target_rails_version ||= TargetRailsVersion.resolve(config)
60
+ end
61
+
62
+ private
63
+
64
+ # Overrides `RuboCop::Cop::Base` so that `railties` requirements declared via
65
+ # `minimum_target_rails_version` are checked against the resolved target Rails version
66
+ # instead of the lockfile alone. This keeps `AllCops: TargetRailsVersion` effective for
67
+ # version-gated cops, including in projects without a lockfile.
68
+ def target_satisfies_all_gem_version_requirements?
69
+ self.class.gem_requirements.all? do |gem_name, version_requirement|
70
+ if gem_name == TARGET_GEM_NAME
71
+ version_requirement.satisfied_by?(Gem::Version.new(target_rails_version.to_s))
72
+ else
73
+ gem_versions_in_target = config.gem_versions_in_target
74
+ gem_version_in_target = gem_versions_in_target && gem_versions_in_target[gem_name]
75
+
76
+ gem_version_in_target && version_requirement.satisfied_by?(gem_version_in_target)
77
+ end
78
+ end
79
+ end
80
+ end
29
81
  end
30
82
  end
31
83
  end
@@ -0,0 +1,17 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RuboCop
4
+ module Cop
5
+ # Autoloads mixin modules included by cops. Mixins are autoloaded to reduce the number of requires
6
+ # because they're used only when the relevant cop class is loaded.
7
+ autoload :ActiveRecordHelper, "#{__dir__}/mixin/active_record_helper"
8
+ autoload :ActiveRecordMigrationsHelper, "#{__dir__}/mixin/active_record_migrations_helper"
9
+ autoload :ClassSendNodeHelper, "#{__dir__}/mixin/class_send_node_helper"
10
+ autoload :DatabaseTypeResolvable, "#{__dir__}/mixin/database_type_resolvable"
11
+ autoload :EnforceSuperclass, "#{__dir__}/mixin/enforce_superclass"
12
+ autoload :IndexMethod, "#{__dir__}/mixin/index_method"
13
+ autoload :MigrationsHelper, "#{__dir__}/mixin/migrations_helper"
14
+ autoload :RoutesHelper, "#{__dir__}/mixin/routes_helper"
15
+ autoload :TargetRailsVersion, "#{__dir__}/mixin/target_rails_version"
16
+ end
17
+ end
@@ -19,6 +19,7 @@ module RuboCop
19
19
  # ActiveSupport.on_load(:active_record) { include MyClass }
20
20
  class ActiveSupportOnLoad < Base
21
21
  extend AutoCorrector
22
+ extend TargetRailsVersion
22
23
 
23
24
  MSG = 'Use `%<prefer>s` instead of `%<current>s`.'
24
25
  RESTRICT_ON_SEND = %i[prepend include extend].freeze
@@ -27,9 +27,8 @@ module RuboCop
27
27
  SUPERCLASS = 'ApplicationController'
28
28
  BASE_PATTERN = '(const (const {nil? cbase} :ActionController) :Base)'
29
29
 
30
- # rubocop:disable Layout/ClassStructure
30
+ # rubocop:disable-next Layout/ClassStructure
31
31
  include RuboCop::Cop::EnforceSuperclass
32
- # rubocop:enable Layout/ClassStructure
33
32
  end
34
33
  end
35
34
  end
@@ -30,9 +30,8 @@ module RuboCop
30
30
  SUPERCLASS = 'ApplicationJob'
31
31
  BASE_PATTERN = '(const (const {nil? cbase} :ActiveJob) :Base)'
32
32
 
33
- # rubocop:disable Layout/ClassStructure
33
+ # rubocop:disable-next Layout/ClassStructure
34
34
  include RuboCop::Cop::EnforceSuperclass
35
- # rubocop:enable Layout/ClassStructure
36
35
 
37
36
  def autocorrect(node)
38
37
  lambda do |corrector|
@@ -30,9 +30,8 @@ module RuboCop
30
30
  SUPERCLASS = 'ApplicationMailer'
31
31
  BASE_PATTERN = '(const (const {nil? cbase} :ActionMailer) :Base)'
32
32
 
33
- # rubocop:disable Layout/ClassStructure
33
+ # rubocop:disable-next Layout/ClassStructure
34
34
  include RuboCop::Cop::EnforceSuperclass
35
- # rubocop:enable Layout/ClassStructure
36
35
  end
37
36
  end
38
37
  end
@@ -35,9 +35,8 @@ module RuboCop
35
35
  SUPERCLASS = 'ApplicationRecord'
36
36
  BASE_PATTERN = '(const (const {nil? cbase} :ActiveRecord) :Base)'
37
37
 
38
- # rubocop:disable Layout/ClassStructure
38
+ # rubocop:disable-next Layout/ClassStructure
39
39
  include RuboCop::Cop::EnforceSuperclass
40
- # rubocop:enable Layout/ClassStructure
41
40
  end
42
41
  end
43
42
  end
@@ -29,6 +29,11 @@ module RuboCop
29
29
  # attribute :roles, :string, array: true, default: -> { [] }
30
30
  # end
31
31
  #
32
+ # # good
33
+ # class User < ApplicationRecord
34
+ # attribute :roles, :string, array: true, default: [].freeze
35
+ # end
36
+ #
32
37
  # # bad
33
38
  # class User < ApplicationRecord
34
39
  # attribute :configuration, default: {}
@@ -71,10 +76,14 @@ module RuboCop
71
76
  PATTERN
72
77
 
73
78
  def_node_matcher :attribute, '(pair (sym :default) $_)'
79
+ def_node_matcher :frozen_literal_default?, <<~PATTERN
80
+ (send {(array) (hash)} :freeze)
81
+ PATTERN
74
82
 
75
83
  def on_send(node)
76
84
  default_attribute(node) do |attribute|
77
85
  value = attribute.children.last
86
+ return if frozen_literal_default?(value)
78
87
  return unless TYPE_OFFENDERS.any?(value.type)
79
88
 
80
89
  add_offense(value) do |corrector|
@@ -66,6 +66,7 @@ module RuboCop
66
66
  class BulkChangeTable < Base
67
67
  include DatabaseTypeResolvable
68
68
  include MigrationsHelper
69
+ extend TargetRailsVersion
69
70
 
70
71
  MSG_FOR_CHANGE_TABLE = <<~MSG.chomp
71
72
  You can combine alter queries using `bulk: true` options.
@@ -34,7 +34,7 @@ module RuboCop
34
34
  ].to_set.freeze
35
35
 
36
36
  # Generated from `ActiveRecord::AttributeMethods.dangerous_attribute_methods` on activerecord 7.1.3.
37
- # rubocop:disable Metrics/CollectionLiteralLength
37
+ # rubocop:disable-next Metrics/CollectionLiteralLength
38
38
  DANGEROUS_COLUMN_NAMES = %w[
39
39
  __callbacks
40
40
  __id__
@@ -406,7 +406,6 @@ module RuboCop
406
406
  write_attribute
407
407
  write_store_attribute
408
408
  ].freeze
409
- # rubocop:enable Metrics/CollectionLiteralLength
410
409
 
411
410
  MSG = 'Avoid dangerous column names.'
412
411
 
@@ -35,6 +35,7 @@ module RuboCop
35
35
  class DeprecatedActiveModelErrorsMethods < Base
36
36
  include RangeHelp
37
37
  extend AutoCorrector
38
+ extend TargetRailsVersion
38
39
 
39
40
  MSG = 'Avoid manipulating ActiveModel errors as hash directly.'
40
41
  AUTOCORRECTABLE_METHODS = %i[<< clear keys].freeze
@@ -25,6 +25,7 @@ module RuboCop
25
25
  #
26
26
  class EnumHash < Base
27
27
  extend AutoCorrector
28
+ extend TargetRailsVersion
28
29
 
29
30
  MSG = 'Enum defined as an array found in `%<enum>s` enum declaration. Use hash syntax instead.'
30
31
  RESTRICT_ON_SEND = %i[enum].freeze
@@ -51,6 +51,10 @@ module RuboCop
51
51
  (const {nil? cbase} :Rack) :Test) :Methods))
52
52
  PATTERN
53
53
 
54
+ def on_new_investigation
55
+ @use_rack_test_methods = nil
56
+ end
57
+
54
58
  def on_send(node)
55
59
  return if in_routing_block?(node) || use_rack_test_methods?
56
60
 
@@ -81,13 +85,16 @@ module RuboCop
81
85
  !!node.each_ancestor(:block).detect { |block| ROUTING_METHODS.include?(block.method_name) }
82
86
  end
83
87
 
88
+ # The result is the same for every node in a file, so scan the AST only once.
84
89
  def use_rack_test_methods?
85
- processed_source.ast.each_descendant(:send).any? do |node|
90
+ return @use_rack_test_methods unless @use_rack_test_methods.nil?
91
+
92
+ @use_rack_test_methods = processed_source.ast.each_descendant(:send).any? do |node|
86
93
  include_rack_test_methods?(node)
87
94
  end
88
95
  end
89
96
 
90
- # rubocop:disable Metrics/CyclomaticComplexity
97
+ # rubocop:disable-next Metrics/CyclomaticComplexity
91
98
  def needs_conversion?(data)
92
99
  return false if data.forwarded_args_type? || forwarded_kwrestarg?(data)
93
100
  return true unless data.hash_type?
@@ -97,7 +104,6 @@ module RuboCop
97
104
  special_keyword_arg?(pair.key) || (format_arg?(pair.key) && data.pairs.one?)
98
105
  end
99
106
  end
100
- # rubocop:enable Metrics/CyclomaticComplexity
101
107
 
102
108
  def special_keyword_arg?(node)
103
109
  node.sym_type? && KEYWORD_ARGS.include?(node.value)
@@ -138,6 +138,8 @@ module RuboCop
138
138
  # has_many :posts, -> { order(published_at: :desc) }
139
139
  # end
140
140
  class InverseOf < Base
141
+ extend TargetRailsVersion
142
+
141
143
  SPECIFY_MSG = 'Specify an `:inverse_of` option.'
142
144
  NIL_MSG = 'You specified `inverse_of: nil`, you probably meant to use `inverse_of: false`.'
143
145
  RESTRICT_ON_SEND = %i[has_many has_one belongs_to].freeze
@@ -178,7 +180,7 @@ module RuboCop
178
180
  (pair (sym :inverse_of) nil)
179
181
  PATTERN
180
182
 
181
- # rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
183
+ # rubocop:disable-next Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
182
184
  def on_send(node)
183
185
  recv, arguments = association_recv_arguments(node)
184
186
  return unless arguments
@@ -197,7 +199,6 @@ module RuboCop
197
199
 
198
200
  add_offense(node.loc.selector, message: message(options))
199
201
  end
200
- # rubocop:enable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
201
202
 
202
203
  def scope?(arguments)
203
204
  !ignore_scopes? && arguments.any?(&:block_type?)
@@ -38,7 +38,7 @@ module RuboCop
38
38
  ...)
39
39
  PATTERN
40
40
 
41
- # rubocop:disable Metrics/CyclomaticComplexity
41
+ # rubocop:disable-next Metrics/CyclomaticComplexity
42
42
  def on_send(node)
43
43
  return if node.parent&.call_type? || node.block_node
44
44
  return if !output?(node) && !io_output?(node)
@@ -50,7 +50,6 @@ module RuboCop
50
50
  corrector.replace(range, 'Rails.logger.debug')
51
51
  end
52
52
  end
53
- # rubocop:enable Metrics/CyclomaticComplexity
54
53
 
55
54
  private
56
55
 
@@ -62,7 +62,7 @@ module RuboCop
62
62
  (any_block (call _ {:map :collect}) $_argument (send lvar :[] $_key))
63
63
  PATTERN
64
64
 
65
- # rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
65
+ # rubocop:disable-next Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
66
66
  def on_block(node)
67
67
  return if node.each_ancestor(:any_block).first&.receiver
68
68
 
@@ -82,7 +82,6 @@ module RuboCop
82
82
  register_offense(node, key)
83
83
  end
84
84
  end
85
- # rubocop:enable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
86
85
  alias on_numblock on_block
87
86
  alias on_itblock on_block
88
87
 
@@ -45,22 +45,62 @@ module RuboCop
45
45
  return if with_dependencies?(task_method)
46
46
 
47
47
  add_offense(task_method) do |corrector|
48
- if with_arguments?(task_method)
49
- new_task_dependency = correct_task_arguments_dependency(task_method)
50
- corrector.replace(task_arguments(task_method), new_task_dependency)
51
- else
52
- task_name = task_method.first_argument
53
- new_task_dependency = correct_task_dependency(task_name)
54
- corrector.replace(task_name, new_task_dependency)
55
- end
48
+ autocorrect(corrector, task_method)
56
49
  end
57
50
  end
58
51
  end
59
52
 
60
53
  private
61
54
 
62
- def correct_task_arguments_dependency(task_method)
63
- "#{task_arguments(task_method).source} => :environment"
55
+ def autocorrect(corrector, task_method)
56
+ task_name, *task_arguments = task_method.arguments
57
+
58
+ if task_arguments.empty?
59
+ correct_task_name(corrector, task_name)
60
+ else
61
+ correct_task_arguments(corrector, task_arguments)
62
+ end
63
+ end
64
+
65
+ def correct_task_name(corrector, task_name)
66
+ if task_name.hash_type?
67
+ correct_empty_dependencies(corrector, task_name)
68
+ else
69
+ corrector.replace(task_name, correct_task_dependency(task_name))
70
+ end
71
+ end
72
+
73
+ def correct_task_arguments(corrector, task_arguments)
74
+ if task_arguments.one?
75
+ correct_single_task_argument(corrector, task_arguments.first)
76
+ elsif task_arguments.all? { |argument| argument.type?(:sym, :str) }
77
+ corrector.replace(task_arguments_range(task_arguments), task_arguments_dependency(task_arguments))
78
+ end
79
+ end
80
+
81
+ def correct_single_task_argument(corrector, argument)
82
+ if argument.hash_type?
83
+ correct_empty_dependencies(corrector, argument)
84
+ elsif argument.array_type?
85
+ corrector.replace(argument, "#{argument.source} => :environment")
86
+ elsif argument.type?(:sym, :str)
87
+ corrector.replace(argument, task_arguments_dependency([argument]))
88
+ end
89
+ end
90
+
91
+ def task_arguments_dependency(task_arguments)
92
+ "[#{task_arguments.map(&:source).join(', ')}] => :environment"
93
+ end
94
+
95
+ def correct_empty_dependencies(corrector, hash_node)
96
+ dependencies = hash_node.pairs.first&.value
97
+ return unless dependencies&.array_type? && dependencies.values.empty?
98
+
99
+ corrector.replace(dependencies, '[:environment]')
100
+ end
101
+
102
+ def task_arguments_range(task_arguments)
103
+ task_arguments.first.source_range.join(task_arguments.last.source_range)
64
104
  end
65
105
 
66
106
  def correct_task_dependency(task_name)
@@ -88,14 +128,6 @@ module RuboCop
88
128
  end
89
129
  end
90
130
 
91
- def task_arguments(node)
92
- node.arguments[1]
93
- end
94
-
95
- def with_arguments?(node)
96
- node.arguments.size > 1 && node.arguments[1].array_type?
97
- end
98
-
99
131
  def with_dependencies?(node)
100
132
  first_arg = node.first_argument
101
133
  return false unless first_arg
@@ -52,6 +52,8 @@ module RuboCop
52
52
  return if within_shadowing_method?(node)
53
53
 
54
54
  add_offense(node, message: build_message(node)) do |corrector|
55
+ next if nested_read_write_attribute?(node)
56
+
55
57
  corrector.replace(node, node_replacement(node))
56
58
  end
57
59
  end
@@ -106,6 +108,12 @@ module RuboCop
106
108
  def write_attribute_replacement(node)
107
109
  "self[#{node.first_argument.source}] = #{node.last_argument.source}"
108
110
  end
111
+
112
+ def nested_read_write_attribute?(node)
113
+ node.each_descendant(:send).any? do |descendant|
114
+ read_write_attribute?(descendant) && !within_shadowing_method?(descendant)
115
+ end
116
+ end
109
117
  end
110
118
  end
111
119
  end
@@ -47,7 +47,7 @@ module RuboCop
47
47
 
48
48
  private
49
49
 
50
- # rubocop:disable Metrics/AbcSize
50
+ # rubocop:disable-next Metrics/AbcSize
51
51
  def correct_redirect_back(corrector, node, fallback_pair, fallback_value, options)
52
52
  corrector.replace(node.loc.selector, 'redirect_back_or_to')
53
53
 
@@ -64,7 +64,6 @@ module RuboCop
64
64
 
65
65
  wrap_with_parentheses(node, corrector) unless node.parenthesized?
66
66
  end
67
- # rubocop:enable Metrics/AbcSize
68
67
 
69
68
  def remove_fallback_location_pair(corrector, hash_node, fallback_pair)
70
69
  pairs = hash_node.pairs
@@ -95,7 +95,7 @@ module RuboCop
95
95
  corrector.remove(block_argument_range(send_node)) if node.block_type?
96
96
  end
97
97
 
98
- # rubocop:disable Metrics/AbcSize
98
+ # rubocop:disable-next Metrics/AbcSize
99
99
  def redundant_receiver?(send_nodes, node)
100
100
  proc = if node.numblock_type?
101
101
  ->(n) { n.receiver.lvar_type? && n.receiver.source == '_1' }
@@ -110,7 +110,6 @@ module RuboCop
110
110
 
111
111
  send_nodes.all?(&proc)
112
112
  end
113
- # rubocop:enable Metrics/AbcSize
114
113
 
115
114
  def block_argument_range(node)
116
115
  block_node = node.each_ancestor(:block).first
@@ -152,6 +152,7 @@ module RuboCop
152
152
  # end
153
153
  class ReversibleMigration < Base
154
154
  include MigrationsHelper
155
+ extend TargetRailsVersion
155
156
 
156
157
  MSG = '%<action>s is not reversible.'
157
158
 
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- # rubocop:disable Metrics/ClassLength
3
+ # rubocop:disable-next Metrics/ClassLength
4
4
  module RuboCop
5
5
  module Cop
6
6
  module Rails
@@ -152,7 +152,7 @@ module RuboCop
152
152
  register_offense(node, CREATE_MSG)
153
153
  end
154
154
 
155
- # rubocop:disable Metrics/CyclomaticComplexity
155
+ # rubocop:disable-next Metrics/CyclomaticComplexity
156
156
  def on_send(node)
157
157
  return unless persist_method?(node)
158
158
  return if return_value_assigned?(node)
@@ -164,7 +164,6 @@ module RuboCop
164
164
 
165
165
  register_offense(node, MSG)
166
166
  end
167
- # rubocop:enable Metrics/CyclomaticComplexity
168
167
  alias on_csend on_send
169
168
 
170
169
  private
@@ -356,4 +355,3 @@ module RuboCop
356
355
  end
357
356
  end
358
357
  end
359
- # rubocop:enable Metrics/ClassLength
@@ -58,7 +58,7 @@ module RuboCop
58
58
  receiver_chain?(node, select_node) ? select_node : nil
59
59
  end
60
60
 
61
- # rubocop:disable Metrics/AbcSize
61
+ # rubocop:disable-next Metrics/AbcSize
62
62
  def autocorrect(corrector, select_node, node, preferred_method)
63
63
  if (parent = select_node.parent).loc?(:dot)
64
64
  corrector.remove(parent.loc.dot)
@@ -68,7 +68,6 @@ module RuboCop
68
68
  corrector.replace(node, "#{select_node.receiver.source}.#{preferred_method}")
69
69
  end
70
70
  end
71
- # rubocop:enable Metrics/AbcSize
72
71
 
73
72
  def match_column_name?(select_candidate, column_name)
74
73
  return false unless select_candidate.arguments.one?
@@ -109,7 +109,7 @@ module RuboCop
109
109
  :require _require_param_name)
110
110
  PATTERN
111
111
 
112
- # rubocop:disable Metrics/AbcSize, Metrics/MethodLength
112
+ # rubocop:disable-next Metrics/AbcSize, Metrics/MethodLength
113
113
  def on_send(node)
114
114
  return if part_of_ignored_node?(node)
115
115
 
@@ -141,7 +141,6 @@ module RuboCop
141
141
 
142
142
  ignore_node(node)
143
143
  end
144
- # rubocop:enable Metrics/AbcSize, Metrics/MethodLength
145
144
  alias on_csend on_send
146
145
 
147
146
  private
@@ -157,7 +156,7 @@ module RuboCop
157
156
  end
158
157
  end
159
158
 
160
- # rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
159
+ # rubocop:disable-next Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
161
160
  def offensive_bracket_access?(node)
162
161
  return false unless (parent = node.parent)
163
162
  return false if parent.or_type?
@@ -174,7 +173,6 @@ module RuboCop
174
173
  raising_finder_method?(parent)
175
174
  end
176
175
  end
177
- # rubocop:enable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
178
176
 
179
177
  def raising_finder_method?(node)
180
178
  RAISING_FINDER_METHODS.include?(node.method_name)
@@ -64,6 +64,8 @@ module RuboCop
64
64
  # end
65
65
  #
66
66
  class TransactionExitStatement < Base
67
+ extend TargetRailsVersion
68
+
67
69
  MSG = 'Exit statement `%<statement>s` is not allowed. Use `raise` (rollback) or `next` (commit).'
68
70
  BUILT_IN_TRANSACTION_METHODS = %i[transaction with_lock].freeze
69
71
 
@@ -34,6 +34,8 @@ module RuboCop
34
34
  # end
35
35
  #
36
36
  class UnknownEnv < Base
37
+ extend TargetRailsVersion
38
+
37
39
  MSG = 'Unknown environment `%<name>s`.'
38
40
  MSG_SIMILAR = 'Unknown environment `%<name>s`. Did you mean `%<similar>s`?'
39
41
 
@@ -74,7 +74,7 @@ module RuboCop
74
74
  range_between(node.loc.selector.begin_pos, node.source_range.end_pos)
75
75
  end
76
76
 
77
- # rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/MethodLength
77
+ # rubocop:disable-next Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/MethodLength
78
78
  def extract_column_and_value(template_node, value_node)
79
79
  value =
80
80
  case template_node.value
@@ -96,7 +96,6 @@ module RuboCop
96
96
 
97
97
  [column_qualifier, value]
98
98
  end
99
- # rubocop:enable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/MethodLength
100
99
 
101
100
  def build_good_method(method_name, column, value)
102
101
  if column.include?('.')
@@ -89,7 +89,7 @@ module RuboCop
89
89
  end
90
90
  end
91
91
 
92
- # rubocop:disable Metrics/AbcSize
92
+ # rubocop:disable-next Metrics/AbcSize
93
93
  def remove_where_method(corrector, node, where_node)
94
94
  range = range_between(where_node.loc.selector.begin_pos, where_node.loc.end.end_pos)
95
95
  if node.multiline? && !same_line?(node, where_node)
@@ -102,7 +102,6 @@ module RuboCop
102
102
 
103
103
  corrector.remove(range)
104
104
  end
105
- # rubocop:enable Metrics/AbcSize
106
105
 
107
106
  def same_line?(left_joins_node, where_node)
108
107
  left_joins_node.loc.selector.line == where_node.loc.selector.line
@@ -68,7 +68,7 @@ module RuboCop
68
68
  range_between(node.loc.selector.begin_pos, node.source_range.end_pos)
69
69
  end
70
70
 
71
- # rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/MethodLength
71
+ # rubocop:disable-next Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/MethodLength
72
72
  def extract_column_and_value(template_node, value_node)
73
73
  value =
74
74
  case template_node.value
@@ -90,7 +90,6 @@ module RuboCop
90
90
 
91
91
  [column_qualifier, value]
92
92
  end
93
- # rubocop:enable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/MethodLength
94
93
 
95
94
  def build_good_method(dot, column, value)
96
95
  dot ||= '.'
@@ -92,7 +92,7 @@ module RuboCop
92
92
  receiver&.send_type? && receiver.method?(:where)
93
93
  end
94
94
 
95
- # rubocop:disable Metrics
95
+ # rubocop:disable-next Metrics
96
96
  def extract_column_and_value(template_node, values_node)
97
97
  case template_node.value
98
98
  when GTEQ_ANONYMOUS_RE
@@ -157,7 +157,6 @@ module RuboCop
157
157
 
158
158
  [column_qualifier, "#{lhs_source}#{operator}#{rhs_source}"] if operator
159
159
  end
160
- # rubocop:enable Metrics
161
160
 
162
161
  def range_operator(comparison_operator)
163
162
  comparison_operator == '<' ? '...' : '..'
@@ -0,0 +1,152 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'mixin'
4
+
5
+ module RuboCop
6
+ module Cop
7
+ # Cops for the `Rails` department. The department's cops are registered for lazy loading
8
+ # and their files are loaded on demand.
9
+ module Rails
10
+ extend LazyLoader
11
+
12
+ register_cop :ActionControllerFlashBeforeRender, "#{__dir__}/rails/action_controller_flash_before_render"
13
+ register_cop :StrongParametersExpect, "#{__dir__}/rails/strong_parameters_expect"
14
+ register_cop :ActionControllerTestCase, "#{__dir__}/rails/action_controller_test_case"
15
+ register_cop :ActionFilter, "#{__dir__}/rails/action_filter"
16
+ register_cop :ActionOrder, "#{__dir__}/rails/action_order"
17
+ register_cop :ActiveRecordAliases, "#{__dir__}/rails/active_record_aliases"
18
+ register_cop :ActiveRecordCallbacksOrder, "#{__dir__}/rails/active_record_callbacks_order"
19
+ register_cop :ActiveRecordOverride, "#{__dir__}/rails/active_record_override"
20
+ register_cop :ActiveSupportAliases, "#{__dir__}/rails/active_support_aliases"
21
+ register_cop :ActiveSupportOnLoad, "#{__dir__}/rails/active_support_on_load"
22
+ register_cop :AddColumnIndex, "#{__dir__}/rails/add_column_index"
23
+ register_cop :AfterCommitOverride, "#{__dir__}/rails/after_commit_override"
24
+ register_cop :ApplicationController, "#{__dir__}/rails/application_controller"
25
+ register_cop :ApplicationJob, "#{__dir__}/rails/application_job"
26
+ register_cop :ApplicationMailer, "#{__dir__}/rails/application_mailer"
27
+ register_cop :ApplicationRecord, "#{__dir__}/rails/application_record"
28
+ register_cop :ArelStar, "#{__dir__}/rails/arel_star"
29
+ register_cop :AssertNot, "#{__dir__}/rails/assert_not"
30
+ register_cop :AttributeDefaultBlockValue, "#{__dir__}/rails/attribute_default_block_value"
31
+ register_cop :BelongsTo, "#{__dir__}/rails/belongs_to"
32
+ register_cop :Blank, "#{__dir__}/rails/blank"
33
+ register_cop :BulkChangeTable, "#{__dir__}/rails/bulk_change_table"
34
+ register_cop :CompactBlank, "#{__dir__}/rails/compact_blank"
35
+ register_cop :ContentTag, "#{__dir__}/rails/content_tag"
36
+ register_cop :CreateTableWithTimestamps, "#{__dir__}/rails/create_table_with_timestamps"
37
+ register_cop :DangerousColumnNames, "#{__dir__}/rails/dangerous_column_names"
38
+ register_cop :Date, "#{__dir__}/rails/date"
39
+ register_cop :DefaultScope, "#{__dir__}/rails/default_scope"
40
+ register_cop :Delegate, "#{__dir__}/rails/delegate"
41
+ register_cop :DelegateAllowBlank, "#{__dir__}/rails/delegate_allow_blank"
42
+ register_cop :DeprecatedActiveModelErrorsMethods, "#{__dir__}/rails/deprecated_active_model_errors_methods"
43
+ register_cop :DotSeparatedKeys, "#{__dir__}/rails/dot_separated_keys"
44
+ register_cop :DuplicateAssociation, "#{__dir__}/rails/duplicate_association"
45
+ register_cop :DuplicateScope, "#{__dir__}/rails/duplicate_scope"
46
+ register_cop :DurationArithmetic, "#{__dir__}/rails/duration_arithmetic"
47
+ register_cop :DynamicFindBy, "#{__dir__}/rails/dynamic_find_by"
48
+ register_cop :EagerEvaluationLogMessage, "#{__dir__}/rails/eager_evaluation_log_message"
49
+ register_cop :EnumHash, "#{__dir__}/rails/enum_hash"
50
+ register_cop :EnumSyntax, "#{__dir__}/rails/enum_syntax"
51
+ register_cop :EnumUniqueness, "#{__dir__}/rails/enum_uniqueness"
52
+ register_cop :Env, "#{__dir__}/rails/env"
53
+ register_cop :EnvLocal, "#{__dir__}/rails/env_local"
54
+ register_cop :EnvironmentComparison, "#{__dir__}/rails/environment_comparison"
55
+ register_cop :EnvironmentVariableAccess, "#{__dir__}/rails/environment_variable_access"
56
+ register_cop :Exit, "#{__dir__}/rails/exit"
57
+ register_cop :ExpandedDateRange, "#{__dir__}/rails/expanded_date_range"
58
+ register_cop :FilePath, "#{__dir__}/rails/file_path"
59
+ register_cop :FindBy, "#{__dir__}/rails/find_by"
60
+ register_cop :FindById, "#{__dir__}/rails/find_by_id"
61
+ register_cop :FindByOrAssignmentMemoization, "#{__dir__}/rails/find_by_or_assignment_memoization"
62
+ register_cop :FindEach, "#{__dir__}/rails/find_each"
63
+ register_cop :FreezeTime, "#{__dir__}/rails/freeze_time"
64
+ register_cop :HasAndBelongsToMany, "#{__dir__}/rails/has_and_belongs_to_many"
65
+ register_cop :HasManyOrHasOneDependent, "#{__dir__}/rails/has_many_or_has_one_dependent"
66
+ register_cop :HelperInstanceVariable, "#{__dir__}/rails/helper_instance_variable"
67
+ register_cop :HttpPositionalArguments, "#{__dir__}/rails/http_positional_arguments"
68
+ register_cop :HttpStatus, "#{__dir__}/rails/http_status"
69
+ register_cop :HttpStatusNameConsistency, "#{__dir__}/rails/http_status_name_consistency"
70
+ register_cop :I18nLazyLookup, "#{__dir__}/rails/i18n_lazy_lookup"
71
+ register_cop :I18nLocaleAssignment, "#{__dir__}/rails/i18n_locale_assignment"
72
+ register_cop :I18nLocaleTexts, "#{__dir__}/rails/i18n_locale_texts"
73
+ register_cop :IgnoredColumnsAssignment, "#{__dir__}/rails/ignored_columns_assignment"
74
+ register_cop :IgnoredSkipActionFilterOption, "#{__dir__}/rails/ignored_skip_action_filter_option"
75
+ register_cop :IndexBy, "#{__dir__}/rails/index_by"
76
+ register_cop :IndexWith, "#{__dir__}/rails/index_with"
77
+ register_cop :Inquiry, "#{__dir__}/rails/inquiry"
78
+ register_cop :InverseOf, "#{__dir__}/rails/inverse_of"
79
+ register_cop :LexicallyScopedActionFilter, "#{__dir__}/rails/lexically_scoped_action_filter"
80
+ register_cop :LinkToBlank, "#{__dir__}/rails/link_to_blank"
81
+ register_cop :MailerName, "#{__dir__}/rails/mailer_name"
82
+ register_cop :MatchRoute, "#{__dir__}/rails/match_route"
83
+ register_cop :MigrationClassName, "#{__dir__}/rails/migration_class_name"
84
+ register_cop :MultipleRoutePaths, "#{__dir__}/rails/multiple_route_paths"
85
+ register_cop :NegateInclude, "#{__dir__}/rails/negate_include"
86
+ register_cop :NotNullColumn, "#{__dir__}/rails/not_null_column"
87
+ register_cop :OrderArguments, "#{__dir__}/rails/order_arguments"
88
+ register_cop :OrderById, "#{__dir__}/rails/order_by_id"
89
+ register_cop :Output, "#{__dir__}/rails/output"
90
+ register_cop :OutputSafety, "#{__dir__}/rails/output_safety"
91
+ register_cop :Pick, "#{__dir__}/rails/pick"
92
+ register_cop :Pluck, "#{__dir__}/rails/pluck"
93
+ register_cop :PluckId, "#{__dir__}/rails/pluck_id"
94
+ register_cop :PluckInWhere, "#{__dir__}/rails/pluck_in_where"
95
+ register_cop :PluralizationGrammar, "#{__dir__}/rails/pluralization_grammar"
96
+ register_cop :Presence, "#{__dir__}/rails/presence"
97
+ register_cop :Present, "#{__dir__}/rails/present"
98
+ register_cop :RakeEnvironment, "#{__dir__}/rails/rake_environment"
99
+ register_cop :ReadWriteAttribute, "#{__dir__}/rails/read_write_attribute"
100
+ register_cop :RedundantActiveRecordAllMethod, "#{__dir__}/rails/redundant_active_record_all_method"
101
+ register_cop :RedundantAllowNil, "#{__dir__}/rails/redundant_allow_nil"
102
+ register_cop :RedundantForeignKey, "#{__dir__}/rails/redundant_foreign_key"
103
+ register_cop :RedundantPresenceValidationOnBelongsTo, "#{__dir__}/rails/redundant_presence_validation_on_belongs_to"
104
+ register_cop :RedundantReceiverInWithOptions, "#{__dir__}/rails/redundant_receiver_in_with_options"
105
+ register_cop :RedundantTravelBack, "#{__dir__}/rails/redundant_travel_back"
106
+ register_cop :RedirectBackOrTo, "#{__dir__}/rails/redirect_back_or_to"
107
+ register_cop :ReflectionClassName, "#{__dir__}/rails/reflection_class_name"
108
+ register_cop :RefuteMethods, "#{__dir__}/rails/refute_methods"
109
+ register_cop :RelativeDateConstant, "#{__dir__}/rails/relative_date_constant"
110
+ register_cop :RenderInline, "#{__dir__}/rails/render_inline"
111
+ register_cop :RenderPlainText, "#{__dir__}/rails/render_plain_text"
112
+ register_cop :RequestReferer, "#{__dir__}/rails/request_referer"
113
+ register_cop :RequireDependency, "#{__dir__}/rails/require_dependency"
114
+ register_cop :ResponseParsedBody, "#{__dir__}/rails/response_parsed_body"
115
+ register_cop :ReversibleMigration, "#{__dir__}/rails/reversible_migration"
116
+ register_cop :ReversibleMigrationMethodDefinition, "#{__dir__}/rails/reversible_migration_method_definition"
117
+ register_cop :RootJoinChain, "#{__dir__}/rails/root_join_chain"
118
+ register_cop :RootPathnameMethods, "#{__dir__}/rails/root_pathname_methods"
119
+ register_cop :RootPublicPath, "#{__dir__}/rails/root_public_path"
120
+ register_cop :SafeNavigation, "#{__dir__}/rails/safe_navigation"
121
+ register_cop :SafeNavigationWithBlank, "#{__dir__}/rails/safe_navigation_with_blank"
122
+ register_cop :SaveBang, "#{__dir__}/rails/save_bang"
123
+ register_cop :SchemaComment, "#{__dir__}/rails/schema_comment"
124
+ register_cop :ScopeArgs, "#{__dir__}/rails/scope_args"
125
+ register_cop :SelectMap, "#{__dir__}/rails/select_map"
126
+ register_cop :ShortI18n, "#{__dir__}/rails/short_i18n"
127
+ register_cop :SkipsModelValidations, "#{__dir__}/rails/skips_model_validations"
128
+ register_cop :SquishedSQLHeredocs, "#{__dir__}/rails/squished_sql_heredocs"
129
+ register_cop :StripHeredoc, "#{__dir__}/rails/strip_heredoc"
130
+ register_cop :TableNameAssignment, "#{__dir__}/rails/table_name_assignment"
131
+ register_cop :ThreeStateBooleanColumn, "#{__dir__}/rails/three_state_boolean_column"
132
+ register_cop :TimeZone, "#{__dir__}/rails/time_zone"
133
+ register_cop :TimeZoneAssignment, "#{__dir__}/rails/time_zone_assignment"
134
+ register_cop :ToFormattedS, "#{__dir__}/rails/to_formatted_s"
135
+ register_cop :ToSWithArgument, "#{__dir__}/rails/to_s_with_argument"
136
+ register_cop :TopLevelHashWithIndifferentAccess, "#{__dir__}/rails/top_level_hash_with_indifferent_access"
137
+ register_cop :TransactionExitStatement, "#{__dir__}/rails/transaction_exit_statement"
138
+ register_cop :UniqBeforePluck, "#{__dir__}/rails/uniq_before_pluck"
139
+ register_cop :UniqueValidationWithoutIndex, "#{__dir__}/rails/unique_validation_without_index"
140
+ register_cop :UnknownEnv, "#{__dir__}/rails/unknown_env"
141
+ register_cop :UnusedIgnoredColumns, "#{__dir__}/rails/unused_ignored_columns"
142
+ register_cop :UnusedRenderContent, "#{__dir__}/rails/unused_render_content"
143
+ register_cop :Validation, "#{__dir__}/rails/validation"
144
+ register_cop :WhereEquals, "#{__dir__}/rails/where_equals"
145
+ register_cop :WhereExists, "#{__dir__}/rails/where_exists"
146
+ register_cop :WhereMissing, "#{__dir__}/rails/where_missing"
147
+ register_cop :WhereNot, "#{__dir__}/rails/where_not"
148
+ register_cop :WhereNotWithMultipleConditions, "#{__dir__}/rails/where_not_with_multiple_conditions"
149
+ register_cop :WhereRange, "#{__dir__}/rails/where_range"
150
+ end
151
+ end
152
+ end
@@ -1,150 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require_relative 'mixin/active_record_helper'
4
- require_relative 'mixin/active_record_migrations_helper'
5
- require_relative 'mixin/class_send_node_helper'
6
- require_relative 'mixin/database_type_resolvable'
7
- require_relative 'mixin/enforce_superclass'
8
- require_relative 'mixin/index_method'
9
- require_relative 'mixin/migrations_helper'
10
- require_relative 'mixin/routes_helper'
11
- require_relative 'mixin/target_rails_version'
12
-
13
- require_relative 'rails/action_controller_flash_before_render'
14
- require_relative 'rails/strong_parameters_expect'
15
- require_relative 'rails/action_controller_test_case'
16
- require_relative 'rails/action_filter'
17
- require_relative 'rails/action_order'
18
- require_relative 'rails/active_record_aliases'
19
- require_relative 'rails/active_record_callbacks_order'
20
- require_relative 'rails/active_record_override'
21
- require_relative 'rails/active_support_aliases'
22
- require_relative 'rails/active_support_on_load'
23
- require_relative 'rails/add_column_index'
24
- require_relative 'rails/after_commit_override'
25
- require_relative 'rails/application_controller'
26
- require_relative 'rails/application_job'
27
- require_relative 'rails/application_mailer'
28
- require_relative 'rails/application_record'
29
- require_relative 'rails/arel_star'
30
- require_relative 'rails/assert_not'
31
- require_relative 'rails/attribute_default_block_value'
32
- require_relative 'rails/belongs_to'
33
- require_relative 'rails/blank'
34
- require_relative 'rails/bulk_change_table'
35
- require_relative 'rails/compact_blank'
36
- require_relative 'rails/content_tag'
37
- require_relative 'rails/create_table_with_timestamps'
38
- require_relative 'rails/dangerous_column_names'
39
- require_relative 'rails/date'
40
- require_relative 'rails/default_scope'
41
- require_relative 'rails/delegate'
42
- require_relative 'rails/delegate_allow_blank'
43
- require_relative 'rails/deprecated_active_model_errors_methods'
44
- require_relative 'rails/dot_separated_keys'
45
- require_relative 'rails/duplicate_association'
46
- require_relative 'rails/duplicate_scope'
47
- require_relative 'rails/duration_arithmetic'
48
- require_relative 'rails/dynamic_find_by'
49
- require_relative 'rails/eager_evaluation_log_message'
50
- require_relative 'rails/enum_hash'
51
- require_relative 'rails/enum_syntax'
52
- require_relative 'rails/enum_uniqueness'
53
- require_relative 'rails/env'
54
- require_relative 'rails/env_local'
55
- require_relative 'rails/environment_comparison'
56
- require_relative 'rails/environment_variable_access'
57
- require_relative 'rails/exit'
58
- require_relative 'rails/expanded_date_range'
59
- require_relative 'rails/file_path'
60
- require_relative 'rails/find_by'
61
- require_relative 'rails/find_by_id'
62
- require_relative 'rails/find_by_or_assignment_memoization'
63
- require_relative 'rails/find_each'
64
- require_relative 'rails/freeze_time'
65
- require_relative 'rails/has_and_belongs_to_many'
66
- require_relative 'rails/has_many_or_has_one_dependent'
67
- require_relative 'rails/helper_instance_variable'
68
- require_relative 'rails/http_positional_arguments'
69
- require_relative 'rails/http_status'
70
- require_relative 'rails/http_status_name_consistency'
71
- require_relative 'rails/i18n_lazy_lookup'
72
- require_relative 'rails/i18n_locale_assignment'
73
- require_relative 'rails/i18n_locale_texts'
74
- require_relative 'rails/ignored_columns_assignment'
75
- require_relative 'rails/ignored_skip_action_filter_option'
76
- require_relative 'rails/index_by'
77
- require_relative 'rails/index_with'
78
- require_relative 'rails/inquiry'
79
- require_relative 'rails/inverse_of'
80
- require_relative 'rails/lexically_scoped_action_filter'
81
- require_relative 'rails/link_to_blank'
82
- require_relative 'rails/mailer_name'
83
- require_relative 'rails/match_route'
84
- require_relative 'rails/migration_class_name'
85
- require_relative 'rails/multiple_route_paths'
86
- require_relative 'rails/negate_include'
87
- require_relative 'rails/not_null_column'
88
- require_relative 'rails/order_arguments'
89
- require_relative 'rails/order_by_id'
90
- require_relative 'rails/output'
91
- require_relative 'rails/output_safety'
92
- require_relative 'rails/pick'
93
- require_relative 'rails/pluck'
94
- require_relative 'rails/pluck_id'
95
- require_relative 'rails/pluck_in_where'
96
- require_relative 'rails/pluralization_grammar'
97
- require_relative 'rails/presence'
98
- require_relative 'rails/present'
99
- require_relative 'rails/rake_environment'
100
- require_relative 'rails/read_write_attribute'
101
- require_relative 'rails/redundant_active_record_all_method'
102
- require_relative 'rails/redundant_allow_nil'
103
- require_relative 'rails/redundant_foreign_key'
104
- require_relative 'rails/redundant_presence_validation_on_belongs_to'
105
- require_relative 'rails/redundant_receiver_in_with_options'
106
- require_relative 'rails/redundant_travel_back'
107
- require_relative 'rails/redirect_back_or_to'
108
- require_relative 'rails/reflection_class_name'
109
- require_relative 'rails/refute_methods'
110
- require_relative 'rails/relative_date_constant'
111
- require_relative 'rails/render_inline'
112
- require_relative 'rails/render_plain_text'
113
- require_relative 'rails/request_referer'
114
- require_relative 'rails/require_dependency'
115
- require_relative 'rails/response_parsed_body'
116
- require_relative 'rails/reversible_migration'
117
- require_relative 'rails/reversible_migration_method_definition'
118
- require_relative 'rails/root_join_chain'
119
- require_relative 'rails/root_pathname_methods'
120
- require_relative 'rails/root_public_path'
121
- require_relative 'rails/safe_navigation'
122
- require_relative 'rails/safe_navigation_with_blank'
123
- require_relative 'rails/save_bang'
124
- require_relative 'rails/schema_comment'
125
- require_relative 'rails/scope_args'
126
- require_relative 'rails/select_map'
127
- require_relative 'rails/short_i18n'
128
- require_relative 'rails/skips_model_validations'
129
- require_relative 'rails/squished_sql_heredocs'
130
- require_relative 'rails/strip_heredoc'
131
- require_relative 'rails/table_name_assignment'
132
- require_relative 'rails/three_state_boolean_column'
133
- require_relative 'rails/time_zone'
134
- require_relative 'rails/time_zone_assignment'
135
- require_relative 'rails/to_formatted_s'
136
- require_relative 'rails/to_s_with_argument'
137
- require_relative 'rails/top_level_hash_with_indifferent_access'
138
- require_relative 'rails/transaction_exit_statement'
139
- require_relative 'rails/uniq_before_pluck'
140
- require_relative 'rails/unique_validation_without_index'
141
- require_relative 'rails/unknown_env'
142
- require_relative 'rails/unused_ignored_columns'
143
- require_relative 'rails/unused_render_content'
144
- require_relative 'rails/validation'
145
- require_relative 'rails/where_equals'
146
- require_relative 'rails/where_exists'
147
- require_relative 'rails/where_missing'
148
- require_relative 'rails/where_not'
149
- require_relative 'rails/where_not_with_multiple_conditions'
150
- require_relative 'rails/where_range'
3
+ # @deprecated This file is deprecated. Cops are registered for lazy loading in
4
+ # `rubocop/cop/rails`; this file is kept for compatibility with code that
5
+ # requires it directly.
6
+ require_relative 'rails'
@@ -4,7 +4,7 @@ module RuboCop
4
4
  module Rails
5
5
  # This module holds the RuboCop Rails version information.
6
6
  module Version
7
- STRING = '2.36.0'
7
+ STRING = '2.38.0'
8
8
 
9
9
  def self.document_version
10
10
  STRING.match('\d+\.\d+').to_s
data/lib/rubocop-rails.rb CHANGED
@@ -9,7 +9,7 @@ require_relative 'rubocop/rails/version'
9
9
  require_relative 'rubocop/rails/schema_loader'
10
10
  require_relative 'rubocop/rails/schema_loader/schema'
11
11
  require_relative 'rubocop/rails/plugin'
12
- require_relative 'rubocop/cop/rails_cops'
12
+ require_relative 'rubocop/cop/rails'
13
13
 
14
14
  require_relative 'rubocop/rails/migration_file_skippable'
15
15
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rubocop-rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.36.0
4
+ version: 2.38.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Bozhidar Batsov
@@ -59,7 +59,7 @@ dependencies:
59
59
  requirements:
60
60
  - - ">="
61
61
  - !ruby/object:Gem::Version
62
- version: 1.75.0
62
+ version: 1.89.0
63
63
  - - "<"
64
64
  - !ruby/object:Gem::Version
65
65
  version: '2.0'
@@ -69,7 +69,7 @@ dependencies:
69
69
  requirements:
70
70
  - - ">="
71
71
  - !ruby/object:Gem::Version
72
- version: 1.75.0
72
+ version: 1.89.0
73
73
  - - "<"
74
74
  - !ruby/object:Gem::Version
75
75
  version: '2.0'
@@ -108,6 +108,7 @@ files:
108
108
  - config/default.yml
109
109
  - config/obsoletion.yml
110
110
  - lib/rubocop-rails.rb
111
+ - lib/rubocop/cop/mixin.rb
111
112
  - lib/rubocop/cop/mixin/active_record_helper.rb
112
113
  - lib/rubocop/cop/mixin/active_record_migrations_helper.rb
113
114
  - lib/rubocop/cop/mixin/class_send_node_helper.rb
@@ -117,6 +118,7 @@ files:
117
118
  - lib/rubocop/cop/mixin/migrations_helper.rb
118
119
  - lib/rubocop/cop/mixin/routes_helper.rb
119
120
  - lib/rubocop/cop/mixin/target_rails_version.rb
121
+ - lib/rubocop/cop/rails.rb
120
122
  - lib/rubocop/cop/rails/action_controller_flash_before_render.rb
121
123
  - lib/rubocop/cop/rails/action_controller_test_case.rb
122
124
  - lib/rubocop/cop/rails/action_filter.rb
@@ -269,7 +271,7 @@ metadata:
269
271
  homepage_uri: https://docs.rubocop.org/rubocop-rails/
270
272
  changelog_uri: https://github.com/rubocop/rubocop-rails/blob/master/CHANGELOG.md
271
273
  source_code_uri: https://github.com/rubocop/rubocop-rails/
272
- documentation_uri: https://docs.rubocop.org/rubocop-rails/2.36/
274
+ documentation_uri: https://docs.rubocop.org/rubocop-rails/2.38/
273
275
  bug_tracker_uri: https://github.com/rubocop/rubocop-rails/issues
274
276
  rubygems_mfa_required: 'true'
275
277
  default_lint_roller_plugin: RuboCop::Rails::Plugin