rubocop-rails 2.27.0 → 2.30.2

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 (49) hide show
  1. checksums.yaml +4 -4
  2. data/LICENSE.txt +1 -1
  3. data/README.md +23 -6
  4. data/config/default.yml +22 -0
  5. data/lib/rubocop/cop/mixin/active_record_helper.rb +1 -1
  6. data/lib/rubocop/cop/mixin/index_method.rb +68 -61
  7. data/lib/rubocop/cop/mixin/routes_helper.rb +20 -0
  8. data/lib/rubocop/cop/rails/add_column_index.rb +1 -0
  9. data/lib/rubocop/cop/rails/belongs_to.rb +1 -1
  10. data/lib/rubocop/cop/rails/blank.rb +1 -1
  11. data/lib/rubocop/cop/rails/bulk_change_table.rb +1 -0
  12. data/lib/rubocop/cop/rails/content_tag.rb +1 -1
  13. data/lib/rubocop/cop/rails/dangerous_column_names.rb +2 -0
  14. data/lib/rubocop/cop/rails/delegate.rb +50 -7
  15. data/lib/rubocop/cop/rails/duplicate_association.rb +8 -4
  16. data/lib/rubocop/cop/rails/file_path.rb +61 -9
  17. data/lib/rubocop/cop/rails/http_positional_arguments.rb +7 -0
  18. data/lib/rubocop/cop/rails/index_by.rb +28 -12
  19. data/lib/rubocop/cop/rails/index_with.rb +28 -12
  20. data/lib/rubocop/cop/rails/inquiry.rb +1 -1
  21. data/lib/rubocop/cop/rails/lexically_scoped_action_filter.rb +11 -1
  22. data/lib/rubocop/cop/rails/match_route.rb +1 -9
  23. data/lib/rubocop/cop/rails/multiple_route_paths.rb +50 -0
  24. data/lib/rubocop/cop/rails/not_null_column.rb +6 -2
  25. data/lib/rubocop/cop/rails/pluck.rb +21 -1
  26. data/lib/rubocop/cop/rails/pluralization_grammar.rb +1 -1
  27. data/lib/rubocop/cop/rails/presence.rb +1 -1
  28. data/lib/rubocop/cop/rails/present.rb +1 -1
  29. data/lib/rubocop/cop/rails/redundant_active_record_all_method.rb +1 -1
  30. data/lib/rubocop/cop/rails/reversible_migration.rb +3 -1
  31. data/lib/rubocop/cop/rails/root_pathname_methods.rb +6 -1
  32. data/lib/rubocop/cop/rails/save_bang.rb +7 -6
  33. data/lib/rubocop/cop/rails/schema_comment.rb +1 -0
  34. data/lib/rubocop/cop/rails/select_map.rb +1 -1
  35. data/lib/rubocop/cop/rails/skips_model_validations.rb +1 -1
  36. data/lib/rubocop/cop/rails/strip_heredoc.rb +1 -1
  37. data/lib/rubocop/cop/rails/strong_parameters_expect.rb +104 -0
  38. data/lib/rubocop/cop/rails/three_state_boolean_column.rb +2 -1
  39. data/lib/rubocop/cop/rails/time_zone.rb +10 -6
  40. data/lib/rubocop/cop/rails/uniq_before_pluck.rb +10 -33
  41. data/lib/rubocop/cop/rails/unique_validation_without_index.rb +1 -1
  42. data/lib/rubocop/cop/rails_cops.rb +3 -0
  43. data/lib/rubocop/rails/migration_file_skippable.rb +54 -0
  44. data/lib/rubocop/rails/plugin.rb +48 -0
  45. data/lib/rubocop/rails/version.rb +1 -1
  46. data/lib/rubocop/rails.rb +1 -8
  47. data/lib/rubocop-rails.rb +4 -4
  48. metadata +28 -9
  49. data/lib/rubocop/rails/inject.rb +0 -18
@@ -73,7 +73,7 @@ module RuboCop
73
73
 
74
74
  def column_names(node, uniqueness_part)
75
75
  arg = node.first_argument
76
- return unless arg.str_type? || arg.sym_type?
76
+ return unless arg.type?(:str, :sym)
77
77
 
78
78
  ret = [arg.value]
79
79
  names_from_scope = column_names_from_scope(uniqueness_part)
@@ -7,9 +7,11 @@ require_relative 'mixin/database_type_resolvable'
7
7
  require_relative 'mixin/enforce_superclass'
8
8
  require_relative 'mixin/index_method'
9
9
  require_relative 'mixin/migrations_helper'
10
+ require_relative 'mixin/routes_helper'
10
11
  require_relative 'mixin/target_rails_version'
11
12
 
12
13
  require_relative 'rails/action_controller_flash_before_render'
14
+ require_relative 'rails/strong_parameters_expect'
13
15
  require_relative 'rails/action_controller_test_case'
14
16
  require_relative 'rails/action_filter'
15
17
  require_relative 'rails/action_order'
@@ -77,6 +79,7 @@ require_relative 'rails/link_to_blank'
77
79
  require_relative 'rails/mailer_name'
78
80
  require_relative 'rails/match_route'
79
81
  require_relative 'rails/migration_class_name'
82
+ require_relative 'rails/multiple_route_paths'
80
83
  require_relative 'rails/negate_include'
81
84
  require_relative 'rails/not_null_column'
82
85
  require_relative 'rails/order_by_id'
@@ -0,0 +1,54 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RuboCop
4
+ module Rails
5
+ # This module allows cops to detect and ignore files that have already been migrated
6
+ # by leveraging the `AllCops: MigratedSchemaVersion` configuration.
7
+ #
8
+ # [source,yaml]
9
+ # -----
10
+ # AllCops:
11
+ # MigratedSchemaVersion: '20241225000000'
12
+ # -----
13
+ #
14
+ # When applied to cops, it overrides the `add_global_offense` and `add_offense` methods,
15
+ # ensuring that cops skip processing if the file is determined to be a migrated file
16
+ # based on the schema version.
17
+ #
18
+ # @api private
19
+ module MigrationFileSkippable
20
+ def add_global_offense(message = nil, severity: nil)
21
+ return if already_migrated_file?
22
+
23
+ super if method(__method__).super_method
24
+ end
25
+
26
+ def add_offense(node_or_range, message: nil, severity: nil, &block)
27
+ return if already_migrated_file?
28
+
29
+ super if method(__method__).super_method
30
+ end
31
+
32
+ def self.apply_to_cops!
33
+ RuboCop::Cop::Registry.all.each { |cop| cop.prepend(MigrationFileSkippable) }
34
+ end
35
+
36
+ private
37
+
38
+ def already_migrated_file?
39
+ return false unless migrated_schema_version
40
+
41
+ match_data = File.basename(processed_source.file_path).match(/(?<timestamp>\d{14})/)
42
+ schema_version = match_data['timestamp'] if match_data
43
+
44
+ return false unless schema_version
45
+
46
+ schema_version <= migrated_schema_version.to_s # Ignore applied migration files.
47
+ end
48
+
49
+ def migrated_schema_version
50
+ @migrated_schema_version ||= config.for_all_cops.fetch('MigratedSchemaVersion', nil)
51
+ end
52
+ end
53
+ end
54
+ end
@@ -0,0 +1,48 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'lint_roller'
4
+
5
+ module RuboCop
6
+ module Rails
7
+ # A plugin that integrates RuboCop Rails with RuboCop's plugin system.
8
+ class Plugin < LintRoller::Plugin
9
+ def about
10
+ LintRoller::About.new(
11
+ name: 'rubocop-rails',
12
+ version: Version::STRING,
13
+ homepage: 'https://github.com/rubocop/rubocop-rails',
14
+ description: 'A RuboCop extension focused on enforcing Rails best practices and coding conventions.'
15
+ )
16
+ end
17
+
18
+ def supported?(context)
19
+ context.engine == :rubocop
20
+ end
21
+
22
+ def rules(_context)
23
+ project_root = Pathname.new(__dir__).join('../../..')
24
+
25
+ ConfigObsoletion.files << project_root.join('config', 'obsoletion.yml')
26
+
27
+ # FIXME: This is a dirty hack relying on a private constant to prevent
28
+ # "Warning: AllCops does not support TargetRailsVersion parameter".
29
+ # It should be updated to a better design in the future.
30
+ without_warnings do
31
+ ConfigValidator.const_set(:COMMON_PARAMS, ConfigValidator::COMMON_PARAMS.dup << 'TargetRailsVersion')
32
+ end
33
+
34
+ LintRoller::Rules.new(type: :path, config_format: :rubocop, value: project_root.join('config', 'default.yml'))
35
+ end
36
+
37
+ private
38
+
39
+ def without_warnings
40
+ original_verbose = $VERBOSE
41
+ $VERBOSE = nil
42
+ yield
43
+ ensure
44
+ $VERBOSE = original_verbose
45
+ end
46
+ end
47
+ end
48
+ 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.27.0'
7
+ STRING = '2.30.2'
8
8
 
9
9
  def self.document_version
10
10
  STRING.match('\d+\.\d+').to_s
data/lib/rubocop/rails.rb CHANGED
@@ -1,14 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module RuboCop
4
- # RuboCop Rails project namespace
4
+ # RuboCop Rails project namespace.
5
5
  module Rails
6
- PROJECT_ROOT = Pathname.new(__dir__).parent.parent.expand_path.freeze
7
- CONFIG_DEFAULT = PROJECT_ROOT.join('config', 'default.yml').freeze
8
- CONFIG = YAML.safe_load(CONFIG_DEFAULT.read, permitted_classes: [Regexp, Symbol]).freeze
9
-
10
- private_constant(:CONFIG_DEFAULT, :PROJECT_ROOT)
11
-
12
- ::RuboCop::ConfigObsoletion.files << PROJECT_ROOT.join('config', 'obsoletion.yml')
13
6
  end
14
7
  end
data/lib/rubocop-rails.rb CHANGED
@@ -7,14 +7,14 @@ require 'active_support/core_ext/object/blank'
7
7
 
8
8
  require_relative 'rubocop/rails'
9
9
  require_relative 'rubocop/rails/version'
10
- require_relative 'rubocop/rails/inject'
11
10
  require_relative 'rubocop/rails/schema_loader'
12
11
  require_relative 'rubocop/rails/schema_loader/schema'
13
-
14
- RuboCop::Rails::Inject.defaults!
15
-
12
+ require_relative 'rubocop/rails/plugin'
16
13
  require_relative 'rubocop/cop/rails_cops'
17
14
 
15
+ require_relative 'rubocop/rails/migration_file_skippable'
16
+ RuboCop::Rails::MigrationFileSkippable.apply_to_cops!
17
+
18
18
  RuboCop::Cop::Style::HashExcept.minimum_target_ruby_version(2.0)
19
19
 
20
20
  RuboCop::Cop::Style::InverseMethods.singleton_class.prepend(
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.27.0
4
+ version: 2.30.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Bozhidar Batsov
@@ -9,7 +9,7 @@ authors:
9
9
  - Yuji Nakayama
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2024-10-26 00:00:00.000000000 Z
12
+ date: 2025-02-24 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activesupport
@@ -25,6 +25,20 @@ dependencies:
25
25
  - - ">="
26
26
  - !ruby/object:Gem::Version
27
27
  version: 4.2.0
28
+ - !ruby/object:Gem::Dependency
29
+ name: lint_roller
30
+ requirement: !ruby/object:Gem::Requirement
31
+ requirements:
32
+ - - "~>"
33
+ - !ruby/object:Gem::Version
34
+ version: '1.1'
35
+ type: :runtime
36
+ prerelease: false
37
+ version_requirements: !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - "~>"
40
+ - !ruby/object:Gem::Version
41
+ version: '1.1'
28
42
  - !ruby/object:Gem::Dependency
29
43
  name: rack
30
44
  requirement: !ruby/object:Gem::Requirement
@@ -45,7 +59,7 @@ dependencies:
45
59
  requirements:
46
60
  - - ">="
47
61
  - !ruby/object:Gem::Version
48
- version: 1.52.0
62
+ version: 1.72.1
49
63
  - - "<"
50
64
  - !ruby/object:Gem::Version
51
65
  version: '2.0'
@@ -55,7 +69,7 @@ dependencies:
55
69
  requirements:
56
70
  - - ">="
57
71
  - !ruby/object:Gem::Version
58
- version: 1.52.0
72
+ version: 1.72.1
59
73
  - - "<"
60
74
  - !ruby/object:Gem::Version
61
75
  version: '2.0'
@@ -65,7 +79,7 @@ dependencies:
65
79
  requirements:
66
80
  - - ">="
67
81
  - !ruby/object:Gem::Version
68
- version: 1.31.1
82
+ version: 1.38.0
69
83
  - - "<"
70
84
  - !ruby/object:Gem::Version
71
85
  version: '2.0'
@@ -75,7 +89,7 @@ dependencies:
75
89
  requirements:
76
90
  - - ">="
77
91
  - !ruby/object:Gem::Version
78
- version: 1.31.1
92
+ version: 1.38.0
79
93
  - - "<"
80
94
  - !ruby/object:Gem::Version
81
95
  version: '2.0'
@@ -101,6 +115,7 @@ files:
101
115
  - lib/rubocop/cop/mixin/enforce_superclass.rb
102
116
  - lib/rubocop/cop/mixin/index_method.rb
103
117
  - lib/rubocop/cop/mixin/migrations_helper.rb
118
+ - lib/rubocop/cop/mixin/routes_helper.rb
104
119
  - lib/rubocop/cop/mixin/target_rails_version.rb
105
120
  - lib/rubocop/cop/rails/action_controller_flash_before_render.rb
106
121
  - lib/rubocop/cop/rails/action_controller_test_case.rb
@@ -170,6 +185,7 @@ files:
170
185
  - lib/rubocop/cop/rails/mailer_name.rb
171
186
  - lib/rubocop/cop/rails/match_route.rb
172
187
  - lib/rubocop/cop/rails/migration_class_name.rb
188
+ - lib/rubocop/cop/rails/multiple_route_paths.rb
173
189
  - lib/rubocop/cop/rails/negate_include.rb
174
190
  - lib/rubocop/cop/rails/not_null_column.rb
175
191
  - lib/rubocop/cop/rails/order_by_id.rb
@@ -213,6 +229,7 @@ files:
213
229
  - lib/rubocop/cop/rails/skips_model_validations.rb
214
230
  - lib/rubocop/cop/rails/squished_sql_heredocs.rb
215
231
  - lib/rubocop/cop/rails/strip_heredoc.rb
232
+ - lib/rubocop/cop/rails/strong_parameters_expect.rb
216
233
  - lib/rubocop/cop/rails/table_name_assignment.rb
217
234
  - lib/rubocop/cop/rails/three_state_boolean_column.rb
218
235
  - lib/rubocop/cop/rails/time_zone.rb
@@ -235,7 +252,8 @@ files:
235
252
  - lib/rubocop/cop/rails/where_range.rb
236
253
  - lib/rubocop/cop/rails_cops.rb
237
254
  - lib/rubocop/rails.rb
238
- - lib/rubocop/rails/inject.rb
255
+ - lib/rubocop/rails/migration_file_skippable.rb
256
+ - lib/rubocop/rails/plugin.rb
239
257
  - lib/rubocop/rails/schema_loader.rb
240
258
  - lib/rubocop/rails/schema_loader/schema.rb
241
259
  - lib/rubocop/rails/version.rb
@@ -246,9 +264,10 @@ metadata:
246
264
  homepage_uri: https://docs.rubocop.org/rubocop-rails/
247
265
  changelog_uri: https://github.com/rubocop/rubocop-rails/blob/master/CHANGELOG.md
248
266
  source_code_uri: https://github.com/rubocop/rubocop-rails/
249
- documentation_uri: https://docs.rubocop.org/rubocop-rails/2.27/
267
+ documentation_uri: https://docs.rubocop.org/rubocop-rails/2.30/
250
268
  bug_tracker_uri: https://github.com/rubocop/rubocop-rails/issues
251
269
  rubygems_mfa_required: 'true'
270
+ default_lint_roller_plugin: RuboCop::Rails::Plugin
252
271
  rdoc_options: []
253
272
  require_paths:
254
273
  - lib
@@ -263,7 +282,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
263
282
  - !ruby/object:Gem::Version
264
283
  version: '0'
265
284
  requirements: []
266
- rubygems_version: 3.6.0.dev
285
+ rubygems_version: 3.6.2
267
286
  specification_version: 4
268
287
  summary: Automatic Rails code style checking tool.
269
288
  test_files: []
@@ -1,18 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module RuboCop
4
- module Rails
5
- # Because RuboCop doesn't yet support plugins, we have to monkey patch in a
6
- # bit of our configuration.
7
- module Inject
8
- def self.defaults!
9
- path = CONFIG_DEFAULT.to_s
10
- hash = ConfigLoader.send(:load_yaml_configuration, path)
11
- config = Config.new(hash, path).tap(&:make_excludes_absolute)
12
- puts "configuration from #{path}" if ConfigLoader.debug?
13
- config = ConfigLoader.merge_with_default(config, path, unset_nil: false)
14
- ConfigLoader.instance_variable_set(:@default_configuration, config)
15
- end
16
- end
17
- end
18
- end