rubocop-rails 2.20.2 → 2.24.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (66) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +9 -7
  3. data/config/default.yml +72 -10
  4. data/lib/rubocop/cop/mixin/active_record_helper.rb +15 -3
  5. data/lib/rubocop/cop/mixin/database_type_resolvable.rb +66 -0
  6. data/lib/rubocop/cop/mixin/index_method.rb +2 -2
  7. data/lib/rubocop/cop/rails/action_controller_flash_before_render.rb +3 -1
  8. data/lib/rubocop/cop/rails/action_controller_test_case.rb +2 -2
  9. data/lib/rubocop/cop/rails/action_filter.rb +3 -0
  10. data/lib/rubocop/cop/rails/active_record_aliases.rb +2 -2
  11. data/lib/rubocop/cop/rails/active_support_aliases.rb +6 -5
  12. data/lib/rubocop/cop/rails/active_support_on_load.rb +21 -1
  13. data/lib/rubocop/cop/rails/after_commit_override.rb +1 -1
  14. data/lib/rubocop/cop/rails/bulk_change_table.rb +8 -41
  15. data/lib/rubocop/cop/rails/content_tag.rb +1 -1
  16. data/lib/rubocop/cop/rails/dangerous_column_names.rb +446 -0
  17. data/lib/rubocop/cop/rails/date.rb +1 -1
  18. data/lib/rubocop/cop/rails/duplicate_association.rb +69 -12
  19. data/lib/rubocop/cop/rails/dynamic_find_by.rb +3 -3
  20. data/lib/rubocop/cop/rails/eager_evaluation_log_message.rb +2 -2
  21. data/lib/rubocop/cop/rails/env_local.rb +46 -0
  22. data/lib/rubocop/cop/rails/expanded_date_range.rb +1 -1
  23. data/lib/rubocop/cop/rails/file_path.rb +9 -6
  24. data/lib/rubocop/cop/rails/find_by.rb +3 -3
  25. data/lib/rubocop/cop/rails/find_by_id.rb +9 -23
  26. data/lib/rubocop/cop/rails/freeze_time.rb +1 -1
  27. data/lib/rubocop/cop/rails/has_many_or_has_one_dependent.rb +1 -1
  28. data/lib/rubocop/cop/rails/helper_instance_variable.rb +1 -1
  29. data/lib/rubocop/cop/rails/http_status.rb +4 -3
  30. data/lib/rubocop/cop/rails/i18n_lazy_lookup.rb +63 -13
  31. data/lib/rubocop/cop/rails/inquiry.rb +1 -0
  32. data/lib/rubocop/cop/rails/inverse_of.rb +1 -1
  33. data/lib/rubocop/cop/rails/lexically_scoped_action_filter.rb +7 -8
  34. data/lib/rubocop/cop/rails/not_null_column.rb +13 -3
  35. data/lib/rubocop/cop/rails/output.rb +3 -2
  36. data/lib/rubocop/cop/rails/pick.rb +6 -5
  37. data/lib/rubocop/cop/rails/pluck.rb +1 -1
  38. data/lib/rubocop/cop/rails/pluck_id.rb +2 -1
  39. data/lib/rubocop/cop/rails/pluck_in_where.rb +18 -5
  40. data/lib/rubocop/cop/rails/rake_environment.rb +22 -6
  41. data/lib/rubocop/cop/rails/redundant_active_record_all_method.rb +219 -0
  42. data/lib/rubocop/cop/rails/redundant_presence_validation_on_belongs_to.rb +7 -0
  43. data/lib/rubocop/cop/rails/redundant_receiver_in_with_options.rb +1 -1
  44. data/lib/rubocop/cop/rails/response_parsed_body.rb +52 -10
  45. data/lib/rubocop/cop/rails/reversible_migration.rb +4 -4
  46. data/lib/rubocop/cop/rails/root_pathname_methods.rb +38 -4
  47. data/lib/rubocop/cop/rails/save_bang.rb +15 -8
  48. data/lib/rubocop/cop/rails/schema_comment.rb +16 -10
  49. data/lib/rubocop/cop/rails/select_map.rb +78 -0
  50. data/lib/rubocop/cop/rails/time_zone.rb +13 -5
  51. data/lib/rubocop/cop/rails/transaction_exit_statement.rb +29 -10
  52. data/lib/rubocop/cop/rails/uniq_before_pluck.rb +12 -4
  53. data/lib/rubocop/cop/rails/unique_validation_without_index.rb +2 -2
  54. data/lib/rubocop/cop/rails/unknown_env.rb +5 -1
  55. data/lib/rubocop/cop/rails/unused_render_content.rb +67 -0
  56. data/lib/rubocop/cop/rails/validation.rb +2 -2
  57. data/lib/rubocop/cop/rails/where_equals.rb +3 -2
  58. data/lib/rubocop/cop/rails/where_exists.rb +9 -9
  59. data/lib/rubocop/cop/rails/where_missing.rb +6 -2
  60. data/lib/rubocop/cop/rails/where_not.rb +8 -6
  61. data/lib/rubocop/cop/rails_cops.rb +6 -0
  62. data/lib/rubocop/rails/schema_loader/schema.rb +3 -2
  63. data/lib/rubocop/rails/schema_loader.rb +5 -15
  64. data/lib/rubocop/rails/version.rb +1 -1
  65. data/lib/rubocop-rails.rb +8 -0
  66. metadata +30 -4
@@ -13,6 +13,8 @@ module RuboCop
13
13
  # error when rollback is desired, and to use `next` when commit is
14
14
  # desired.
15
15
  #
16
+ # If you are defining custom transaction methods, you can configure it with `TransactionMethods`.
17
+ #
16
18
  # @example
17
19
  # # bad
18
20
  # ApplicationRecord.transaction do
@@ -50,12 +52,16 @@ module RuboCop
50
52
  # # Commit
51
53
  # next if user.active?
52
54
  # end
55
+ #
56
+ # @example TransactionMethods: ["custom_transaction"]
57
+ # # bad
58
+ # CustomModel.custom_transaction do
59
+ # return if user.active?
60
+ # end
61
+ #
53
62
  class TransactionExitStatement < Base
54
- MSG = <<~MSG.chomp
55
- Exit statement `%<statement>s` is not allowed. Use `raise` (rollback) or `next` (commit).
56
- MSG
57
-
58
- RESTRICT_ON_SEND = %i[transaction with_lock].freeze
63
+ MSG = 'Exit statement `%<statement>s` is not allowed. Use `raise` (rollback) or `next` (commit).'
64
+ BUILT_IN_TRANSACTION_METHODS = %i[transaction with_lock].freeze
59
65
 
60
66
  def_node_search :exit_statements, <<~PATTERN
61
67
  ({return | break | send nil? :throw} ...)
@@ -70,10 +76,9 @@ module RuboCop
70
76
  PATTERN
71
77
 
72
78
  def on_send(node)
73
- return unless (parent = node.parent)
74
- return unless parent.block_type? && parent.body
79
+ return unless in_transaction_block?(node)
75
80
 
76
- exit_statements(parent.body).each do |statement_node|
81
+ exit_statements(node.parent.body).each do |statement_node|
77
82
  next if statement_node.break_type? && nested_block?(statement_node)
78
83
 
79
84
  statement = statement(statement_node)
@@ -85,6 +90,13 @@ module RuboCop
85
90
 
86
91
  private
87
92
 
93
+ def in_transaction_block?(node)
94
+ return false unless transaction_method_name?(node.method_name)
95
+ return false unless (parent = node.parent)
96
+
97
+ parent.block_type? && parent.body
98
+ end
99
+
88
100
  def statement(statement_node)
89
101
  if statement_node.return_type?
90
102
  'return'
@@ -96,9 +108,16 @@ module RuboCop
96
108
  end
97
109
 
98
110
  def nested_block?(statement_node)
99
- block_node = statement_node.ancestors.find(&:block_type?)
111
+ name = statement_node.ancestors.find(&:block_type?).children.first.method_name
112
+ !transaction_method_name?(name)
113
+ end
114
+
115
+ def transaction_method_name?(method_name)
116
+ BUILT_IN_TRANSACTION_METHODS.include?(method_name) || transaction_method?(method_name)
117
+ end
100
118
 
101
- RESTRICT_ON_SEND.none? { |name| block_node.method?(name) }
119
+ def transaction_method?(method_name)
120
+ cop_config.fetch('TransactionMethods', []).include?(method_name.to_s)
102
121
  end
103
122
  end
104
123
  end
@@ -68,15 +68,23 @@ module RuboCop
68
68
  return unless uniq
69
69
 
70
70
  add_offense(node.loc.selector) do |corrector|
71
- method = node.method_name
72
-
73
- corrector.remove(dot_method_with_whitespace(method, node))
74
- corrector.insert_before(node.receiver.loc.dot.begin, '.distinct')
71
+ autocorrect(corrector, node)
75
72
  end
76
73
  end
77
74
 
78
75
  private
79
76
 
77
+ def autocorrect(corrector, node)
78
+ method = node.method_name
79
+
80
+ corrector.remove(dot_method_with_whitespace(method, node))
81
+ if (dot = node.receiver.loc.dot)
82
+ corrector.insert_before(dot.begin, '.distinct')
83
+ else
84
+ corrector.insert_before(node.receiver, 'distinct.')
85
+ end
86
+ end
87
+
80
88
  def dot_method_with_whitespace(method, node)
81
89
  range_between(dot_method_begin_pos(method, node), node.loc.selector.end_pos)
82
90
  end
@@ -124,8 +124,8 @@ module RuboCop
124
124
  end
125
125
 
126
126
  def uniqueness_part(node)
127
- pairs = node.arguments.last
128
- return unless pairs.hash_type?
127
+ pairs = node.last_argument
128
+ return unless pairs&.hash_type?
129
129
 
130
130
  pairs.each_pair.find do |pair|
131
131
  next unless pair.key.sym_type? && pair.key.value == :uniqueness
@@ -86,7 +86,11 @@ module RuboCop
86
86
  end
87
87
 
88
88
  def environments
89
- cop_config['Environments']
89
+ @environments ||= begin
90
+ environments = cop_config['Environments'] || []
91
+ environments << 'local' if target_rails_version >= 7.1
92
+ environments
93
+ end
90
94
  end
91
95
  end
92
96
  end
@@ -0,0 +1,67 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RuboCop
4
+ module Cop
5
+ module Rails
6
+ # If you try to render content along with a non-content status code (100-199, 204, 205, or 304),
7
+ # it will be dropped from the response.
8
+ #
9
+ # This cop checks for uses of `render` which specify both body content and a non-content status.
10
+ #
11
+ # @example
12
+ # # bad
13
+ # render 'foo', status: :continue
14
+ # render status: 100, plain: 'Ruby!'
15
+ #
16
+ # # good
17
+ # head :continue
18
+ # head 100
19
+ class UnusedRenderContent < Base
20
+ include RangeHelp
21
+
22
+ MSG = 'Do not specify body content for a response with a non-content status code'
23
+ RESTRICT_ON_SEND = %i[render].freeze
24
+ NON_CONTENT_STATUS_CODES = Set[*100..199, 204, 205, 304] & ::Rack::Utils::SYMBOL_TO_STATUS_CODE.values
25
+ NON_CONTENT_STATUSES = Set[
26
+ *::Rack::Utils::SYMBOL_TO_STATUS_CODE.invert.fetch_values(*NON_CONTENT_STATUS_CODES)
27
+ ]
28
+ BODY_OPTIONS = Set[
29
+ :action,
30
+ :body,
31
+ :content_type,
32
+ :file,
33
+ :html,
34
+ :inline,
35
+ :json,
36
+ :js,
37
+ :layout,
38
+ :plain,
39
+ :raw,
40
+ :template,
41
+ :text,
42
+ :xml
43
+ ]
44
+
45
+ def_node_matcher :non_content_status?, <<~PATTERN
46
+ (pair
47
+ (sym :status)
48
+ {(sym NON_CONTENT_STATUSES) (int NON_CONTENT_STATUS_CODES)}
49
+ )
50
+ PATTERN
51
+
52
+ def_node_matcher :unused_render_content?, <<~PATTERN
53
+ (send nil? :render {
54
+ (hash <#non_content_status? $(pair (sym BODY_OPTIONS) _) ...>) |
55
+ $({str sym} _) (hash <#non_content_status? ...>)
56
+ })
57
+ PATTERN
58
+
59
+ def on_send(node)
60
+ unused_render_content?(node) do |unused_content_node|
61
+ add_offense(unused_content_node)
62
+ end
63
+ end
64
+ end
65
+ end
66
+ end
67
+ end
@@ -51,7 +51,7 @@ module RuboCop
51
51
  uniqueness
52
52
  ].freeze
53
53
 
54
- RESTRICT_ON_SEND = TYPES.map { |p| "validates_#{p}_of".to_sym }.freeze
54
+ RESTRICT_ON_SEND = TYPES.map { |p| :"validates_#{p}_of" }.freeze
55
55
  ALLOWLIST = TYPES.map { |p| "validates :column, #{p}: value" }.freeze
56
56
 
57
57
  def on_send(node)
@@ -60,7 +60,7 @@ module RuboCop
60
60
  range = node.loc.selector
61
61
 
62
62
  add_offense(range, message: message(node)) do |corrector|
63
- last_argument = node.arguments.last
63
+ last_argument = node.last_argument
64
64
  return if !last_argument.literal? && !last_argument.splat_type? && !frozen_array_argument?(last_argument)
65
65
 
66
66
  corrector.replace(range, 'validates')
@@ -33,8 +33,8 @@ module RuboCop
33
33
 
34
34
  def_node_matcher :where_method_call?, <<~PATTERN
35
35
  {
36
- (send _ :where (array $str_type? $_ ?))
37
- (send _ :where $str_type? $_ ?)
36
+ (call _ :where (array $str_type? $_ ?))
37
+ (call _ :where $str_type? $_ ?)
38
38
  }
39
39
  PATTERN
40
40
 
@@ -55,6 +55,7 @@ module RuboCop
55
55
  end
56
56
  end
57
57
  end
58
+ alias on_csend on_send
58
59
 
59
60
  EQ_ANONYMOUS_RE = /\A([\w.]+)\s+=\s+\?\z/.freeze # column = ?
60
61
  IN_ANONYMOUS_RE = /\A([\w.]+)\s+IN\s+\(\?\)\z/i.freeze # column IN (?)
@@ -39,7 +39,6 @@ module RuboCop
39
39
  # # bad
40
40
  # User.exists?(name: 'john')
41
41
  # User.exists?(['name = ?', 'john'])
42
- # User.exists?('name = ?', 'john')
43
42
  # user.posts.exists?(published: true)
44
43
  #
45
44
  # # good
@@ -56,11 +55,11 @@ module RuboCop
56
55
  RESTRICT_ON_SEND = %i[exists?].freeze
57
56
 
58
57
  def_node_matcher :where_exists_call?, <<~PATTERN
59
- (send (send _ :where $...) :exists?)
58
+ (call (call _ :where $...) :exists?)
60
59
  PATTERN
61
60
 
62
61
  def_node_matcher :exists_with_args?, <<~PATTERN
63
- (send _ :exists? $...)
62
+ (call _ :exists? $...)
64
63
  PATTERN
65
64
 
66
65
  def on_send(node)
@@ -68,7 +67,7 @@ module RuboCop
68
67
  return unless convertable_args?(args)
69
68
 
70
69
  range = correction_range(node)
71
- good_method = build_good_method(args)
70
+ good_method = build_good_method(args, dot: node.loc.dot)
72
71
  message = format(MSG, good_method: good_method, bad_method: range.source)
73
72
 
74
73
  add_offense(range, message: message) do |corrector|
@@ -76,6 +75,7 @@ module RuboCop
76
75
  end
77
76
  end
78
77
  end
78
+ alias on_csend on_send
79
79
 
80
80
  private
81
81
 
@@ -109,11 +109,11 @@ module RuboCop
109
109
  end
110
110
  end
111
111
 
112
- def build_good_method(args)
112
+ def build_good_method(args, dot:)
113
113
  if exists_style?
114
114
  build_good_method_exists(args)
115
115
  elsif where_style?
116
- build_good_method_where(args)
116
+ build_good_method_where(args, dot&.source || '.')
117
117
  end
118
118
  end
119
119
 
@@ -125,11 +125,11 @@ module RuboCop
125
125
  end
126
126
  end
127
127
 
128
- def build_good_method_where(args)
128
+ def build_good_method_where(args, dot_source)
129
129
  if args.size > 1
130
- "where(#{args.map(&:source).join(', ')}).exists?"
130
+ "where(#{args.map(&:source).join(', ')})#{dot_source}exists?"
131
131
  else
132
- "where(#{args[0].source}).exists?"
132
+ "where(#{args[0].source})#{dot_source}exists?"
133
133
  end
134
134
  end
135
135
  end
@@ -36,7 +36,7 @@ module RuboCop
36
36
  PATTERN
37
37
 
38
38
  def on_send(node)
39
- return unless node.first_argument.sym_type?
39
+ return unless node.first_argument&.sym_type?
40
40
 
41
41
  root_receiver = root_receiver(node)
42
42
  where_node_and_argument(root_receiver) do |where_node, where_argument|
@@ -89,16 +89,20 @@ module RuboCop
89
89
  end
90
90
  end
91
91
 
92
+ # rubocop:disable Metrics/AbcSize
92
93
  def remove_where_method(corrector, node, where_node)
93
94
  range = range_between(where_node.loc.selector.begin_pos, where_node.loc.end.end_pos)
94
95
  if node.multiline? && !same_line?(node, where_node)
95
96
  range = range_by_whole_lines(range, include_final_newline: true)
96
- else
97
+ elsif where_node.receiver
97
98
  corrector.remove(where_node.loc.dot)
99
+ else
100
+ corrector.remove(node.loc.dot)
98
101
  end
99
102
 
100
103
  corrector.remove(range)
101
104
  end
105
+ # rubocop:enable Metrics/AbcSize
102
106
 
103
107
  def same_line?(left_joins_node, where_node)
104
108
  left_joins_node.loc.selector.line == where_node.loc.selector.line
@@ -32,8 +32,8 @@ module RuboCop
32
32
 
33
33
  def_node_matcher :where_method_call?, <<~PATTERN
34
34
  {
35
- (send _ :where (array $str_type? $_ ?))
36
- (send _ :where $str_type? $_ ?)
35
+ (call _ :where (array $str_type? $_ ?))
36
+ (call _ :where $str_type? $_ ?)
37
37
  }
38
38
  PATTERN
39
39
 
@@ -46,7 +46,7 @@ module RuboCop
46
46
  column_and_value = extract_column_and_value(template_node, value_node)
47
47
  return unless column_and_value
48
48
 
49
- good_method = build_good_method(*column_and_value)
49
+ good_method = build_good_method(node.loc.dot&.source, *column_and_value)
50
50
  message = format(MSG, good_method: good_method)
51
51
 
52
52
  add_offense(range, message: message) do |corrector|
@@ -54,6 +54,7 @@ module RuboCop
54
54
  end
55
55
  end
56
56
  end
57
+ alias on_csend on_send
57
58
 
58
59
  NOT_EQ_ANONYMOUS_RE = /\A([\w.]+)\s+(?:!=|<>)\s+\?\z/.freeze # column != ?, column <> ?
59
60
  NOT_IN_ANONYMOUS_RE = /\A([\w.]+)\s+NOT\s+IN\s+\(\?\)\z/i.freeze # column NOT IN (?)
@@ -86,13 +87,14 @@ module RuboCop
86
87
  [Regexp.last_match(1), value]
87
88
  end
88
89
 
89
- def build_good_method(column, value)
90
+ def build_good_method(dot, column, value)
91
+ dot ||= '.'
90
92
  if column.include?('.')
91
93
  table, column = column.split('.')
92
94
 
93
- "where.not(#{table}: { #{column}: #{value} })"
95
+ "where#{dot}not(#{table}: { #{column}: #{value} })"
94
96
  else
95
- "where.not(#{column}: #{value})"
97
+ "where#{dot}not(#{column}: #{value})"
96
98
  end
97
99
  end
98
100
  end
@@ -3,6 +3,7 @@
3
3
  require_relative 'mixin/active_record_helper'
4
4
  require_relative 'mixin/active_record_migrations_helper'
5
5
  require_relative 'mixin/class_send_node_helper'
6
+ require_relative 'mixin/database_type_resolvable'
6
7
  require_relative 'mixin/enforce_superclass'
7
8
  require_relative 'mixin/index_method'
8
9
  require_relative 'mixin/migrations_helper'
@@ -32,6 +33,7 @@ require_relative 'rails/bulk_change_table'
32
33
  require_relative 'rails/compact_blank'
33
34
  require_relative 'rails/content_tag'
34
35
  require_relative 'rails/create_table_with_timestamps'
36
+ require_relative 'rails/dangerous_column_names'
35
37
  require_relative 'rails/date'
36
38
  require_relative 'rails/default_scope'
37
39
  require_relative 'rails/delegate'
@@ -45,6 +47,7 @@ require_relative 'rails/dynamic_find_by'
45
47
  require_relative 'rails/eager_evaluation_log_message'
46
48
  require_relative 'rails/enum_hash'
47
49
  require_relative 'rails/enum_uniqueness'
50
+ require_relative 'rails/env_local'
48
51
  require_relative 'rails/environment_comparison'
49
52
  require_relative 'rails/environment_variable_access'
50
53
  require_relative 'rails/exit'
@@ -87,6 +90,7 @@ require_relative 'rails/presence'
87
90
  require_relative 'rails/present'
88
91
  require_relative 'rails/rake_environment'
89
92
  require_relative 'rails/read_write_attribute'
93
+ require_relative 'rails/redundant_active_record_all_method'
90
94
  require_relative 'rails/redundant_allow_nil'
91
95
  require_relative 'rails/redundant_foreign_key'
92
96
  require_relative 'rails/redundant_presence_validation_on_belongs_to'
@@ -110,6 +114,7 @@ require_relative 'rails/safe_navigation_with_blank'
110
114
  require_relative 'rails/save_bang'
111
115
  require_relative 'rails/schema_comment'
112
116
  require_relative 'rails/scope_args'
117
+ require_relative 'rails/select_map'
113
118
  require_relative 'rails/short_i18n'
114
119
  require_relative 'rails/skips_model_validations'
115
120
  require_relative 'rails/squished_sql_heredocs'
@@ -126,6 +131,7 @@ require_relative 'rails/uniq_before_pluck'
126
131
  require_relative 'rails/unique_validation_without_index'
127
132
  require_relative 'rails/unknown_env'
128
133
  require_relative 'rails/unused_ignored_columns'
134
+ require_relative 'rails/unused_render_content'
129
135
  require_relative 'rails/validation'
130
136
  require_relative 'rails/where_equals'
131
137
  require_relative 'rails/where_exists'
@@ -30,6 +30,7 @@ module RuboCop
30
30
 
31
31
  def build!(ast)
32
32
  raise "Unexpected type: #{ast.type}" unless ast.block_type?
33
+ return unless ast.body
33
34
 
34
35
  each_table(ast) do |table_def|
35
36
  next unless table_def.method?(:create_table)
@@ -127,7 +128,7 @@ module RuboCop
127
128
  private
128
129
 
129
130
  def analyze_keywords!(node)
130
- pairs = node.arguments.last
131
+ pairs = node.last_argument
131
132
  return unless pairs.hash_type?
132
133
 
133
134
  pairs.each_pair do |k, v|
@@ -158,7 +159,7 @@ module RuboCop
158
159
  end
159
160
 
160
161
  def analyze_keywords!(node)
161
- pairs = node.arguments.last
162
+ pairs = node.last_argument
162
163
  return unless pairs.hash_type?
163
164
 
164
165
  pairs.each_pair do |k, v|
@@ -12,10 +12,10 @@ module RuboCop
12
12
  # So a cop that uses the loader should handle `nil` properly.
13
13
  #
14
14
  # @return [Schema, nil]
15
- def load(target_ruby_version)
15
+ def load(target_ruby_version, parser_engine)
16
16
  return @load if defined?(@load)
17
17
 
18
- @load = load!(target_ruby_version)
18
+ @load = load!(target_ruby_version, parser_engine)
19
19
  end
20
20
 
21
21
  def reset!
@@ -38,23 +38,13 @@ module RuboCop
38
38
 
39
39
  private
40
40
 
41
- def load!(target_ruby_version)
41
+ def load!(target_ruby_version, parser_engine)
42
42
  path = db_schema_path
43
43
  return unless path
44
44
 
45
- ast = parse(path, target_ruby_version)
46
- Schema.new(ast)
47
- end
48
-
49
- def parse(path, target_ruby_version)
50
- klass_name = :"Ruby#{target_ruby_version.to_s.sub('.', '')}"
51
- klass = ::Parser.const_get(klass_name)
52
- parser = klass.new(RuboCop::AST::Builder.new)
53
-
54
- buffer = Parser::Source::Buffer.new(path, 1)
55
- buffer.source = path.read
45
+ ast = RuboCop::ProcessedSource.new(File.read(path), target_ruby_version, path, parser_engine: parser_engine).ast
56
46
 
57
- parser.parse(buffer)
47
+ Schema.new(ast) if ast
58
48
  end
59
49
  end
60
50
  end
@@ -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.20.2'
7
+ STRING = '2.24.1'
8
8
 
9
9
  def self.document_version
10
10
  STRING.match('\d+\.\d+').to_s
data/lib/rubocop-rails.rb CHANGED
@@ -17,6 +17,14 @@ require_relative 'rubocop/cop/rails_cops'
17
17
 
18
18
  RuboCop::Cop::Style::HashExcept.minimum_target_ruby_version(2.0)
19
19
 
20
+ RuboCop::Cop::Style::InverseMethods.singleton_class.prepend(
21
+ Module.new do
22
+ def autocorrect_incompatible_with
23
+ super.push(RuboCop::Cop::Rails::NegateInclude)
24
+ end
25
+ end
26
+ )
27
+
20
28
  RuboCop::Cop::Style::MethodCallWithArgsParentheses.singleton_class.prepend(
21
29
  Module.new do
22
30
  def autocorrect_incompatible_with
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.20.2
4
+ version: 2.24.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Bozhidar Batsov
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2023-06-19 00:00:00.000000000 Z
13
+ date: 2024-03-25 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: activesupport
@@ -60,6 +60,26 @@ dependencies:
60
60
  - - "<"
61
61
  - !ruby/object:Gem::Version
62
62
  version: '2.0'
63
+ - !ruby/object:Gem::Dependency
64
+ name: rubocop-ast
65
+ requirement: !ruby/object:Gem::Requirement
66
+ requirements:
67
+ - - ">="
68
+ - !ruby/object:Gem::Version
69
+ version: 1.31.1
70
+ - - "<"
71
+ - !ruby/object:Gem::Version
72
+ version: '2.0'
73
+ type: :runtime
74
+ prerelease: false
75
+ version_requirements: !ruby/object:Gem::Requirement
76
+ requirements:
77
+ - - ">="
78
+ - !ruby/object:Gem::Version
79
+ version: 1.31.1
80
+ - - "<"
81
+ - !ruby/object:Gem::Version
82
+ version: '2.0'
63
83
  description: |
64
84
  Automatic Rails code style checking tool.
65
85
  A RuboCop extension focused on enforcing Rails best practices and coding conventions.
@@ -78,6 +98,7 @@ files:
78
98
  - lib/rubocop/cop/mixin/active_record_helper.rb
79
99
  - lib/rubocop/cop/mixin/active_record_migrations_helper.rb
80
100
  - lib/rubocop/cop/mixin/class_send_node_helper.rb
101
+ - lib/rubocop/cop/mixin/database_type_resolvable.rb
81
102
  - lib/rubocop/cop/mixin/enforce_superclass.rb
82
103
  - lib/rubocop/cop/mixin/index_method.rb
83
104
  - lib/rubocop/cop/mixin/migrations_helper.rb
@@ -106,6 +127,7 @@ files:
106
127
  - lib/rubocop/cop/rails/compact_blank.rb
107
128
  - lib/rubocop/cop/rails/content_tag.rb
108
129
  - lib/rubocop/cop/rails/create_table_with_timestamps.rb
130
+ - lib/rubocop/cop/rails/dangerous_column_names.rb
109
131
  - lib/rubocop/cop/rails/date.rb
110
132
  - lib/rubocop/cop/rails/default_scope.rb
111
133
  - lib/rubocop/cop/rails/delegate.rb
@@ -119,6 +141,7 @@ files:
119
141
  - lib/rubocop/cop/rails/eager_evaluation_log_message.rb
120
142
  - lib/rubocop/cop/rails/enum_hash.rb
121
143
  - lib/rubocop/cop/rails/enum_uniqueness.rb
144
+ - lib/rubocop/cop/rails/env_local.rb
122
145
  - lib/rubocop/cop/rails/environment_comparison.rb
123
146
  - lib/rubocop/cop/rails/environment_variable_access.rb
124
147
  - lib/rubocop/cop/rails/exit.rb
@@ -161,6 +184,7 @@ files:
161
184
  - lib/rubocop/cop/rails/present.rb
162
185
  - lib/rubocop/cop/rails/rake_environment.rb
163
186
  - lib/rubocop/cop/rails/read_write_attribute.rb
187
+ - lib/rubocop/cop/rails/redundant_active_record_all_method.rb
164
188
  - lib/rubocop/cop/rails/redundant_allow_nil.rb
165
189
  - lib/rubocop/cop/rails/redundant_foreign_key.rb
166
190
  - lib/rubocop/cop/rails/redundant_presence_validation_on_belongs_to.rb
@@ -184,6 +208,7 @@ files:
184
208
  - lib/rubocop/cop/rails/save_bang.rb
185
209
  - lib/rubocop/cop/rails/schema_comment.rb
186
210
  - lib/rubocop/cop/rails/scope_args.rb
211
+ - lib/rubocop/cop/rails/select_map.rb
187
212
  - lib/rubocop/cop/rails/short_i18n.rb
188
213
  - lib/rubocop/cop/rails/skips_model_validations.rb
189
214
  - lib/rubocop/cop/rails/squished_sql_heredocs.rb
@@ -200,6 +225,7 @@ files:
200
225
  - lib/rubocop/cop/rails/unique_validation_without_index.rb
201
226
  - lib/rubocop/cop/rails/unknown_env.rb
202
227
  - lib/rubocop/cop/rails/unused_ignored_columns.rb
228
+ - lib/rubocop/cop/rails/unused_render_content.rb
203
229
  - lib/rubocop/cop/rails/validation.rb
204
230
  - lib/rubocop/cop/rails/where_equals.rb
205
231
  - lib/rubocop/cop/rails/where_exists.rb
@@ -219,7 +245,7 @@ metadata:
219
245
  homepage_uri: https://docs.rubocop.org/rubocop-rails/
220
246
  changelog_uri: https://github.com/rubocop/rubocop-rails/blob/master/CHANGELOG.md
221
247
  source_code_uri: https://github.com/rubocop/rubocop-rails/
222
- documentation_uri: https://docs.rubocop.org/rubocop-rails/2.20/
248
+ documentation_uri: https://docs.rubocop.org/rubocop-rails/2.24/
223
249
  bug_tracker_uri: https://github.com/rubocop/rubocop-rails/issues
224
250
  rubygems_mfa_required: 'true'
225
251
  post_install_message:
@@ -237,7 +263,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
237
263
  - !ruby/object:Gem::Version
238
264
  version: '0'
239
265
  requirements: []
240
- rubygems_version: 3.5.0.dev
266
+ rubygems_version: 3.3.26
241
267
  signing_key:
242
268
  specification_version: 4
243
269
  summary: Automatic Rails code style checking tool.