rubocop-dev_doc 0.18.0 → 0.19.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 (32) hide show
  1. checksums.yaml +4 -4
  2. data/config/default.yml +161 -2
  3. data/lib/dev_doc/i18n/pseudo_locale.rb +1 -1
  4. data/lib/dev_doc/test/lints/cross_tenant_canary_check.rb +1 -1
  5. data/lib/dev_doc/test/lints/cross_tenant_canary_sweep.rb +6 -3
  6. data/lib/dev_doc/test/lints/http_driven_controller_tests.rb +2 -0
  7. data/lib/dev_doc/test/lints/no_file_excludes.rb +1 -1
  8. data/lib/dev_doc/test/pseudo_i18n_crawler.rb +4 -0
  9. data/lib/rubocop/cop/dev_doc/auth/adjacent_justification.rb +44 -7
  10. data/lib/rubocop/cop/dev_doc/auth/load_resource_current_user_guard.rb +2 -2
  11. data/lib/rubocop/cop/dev_doc/auth/login_only_policy_justification.rb +1 -1
  12. data/lib/rubocop/cop/dev_doc/auth/unscoped_find_justification.rb +2 -2
  13. data/lib/rubocop/cop/dev_doc/bundler/conflicting_gem.rb +74 -0
  14. data/lib/rubocop/cop/dev_doc/exception_class_list.rb +32 -0
  15. data/lib/rubocop/cop/dev_doc/i18n/translation_key_prefix.rb +1 -1
  16. data/lib/rubocop/cop/dev_doc/migration/legacy_migration.rb +26 -0
  17. data/lib/rubocop/cop/dev_doc/migration/redundant_reference_index.rb +5 -15
  18. data/lib/rubocop/cop/dev_doc/migration/require_reference_index.rb +115 -0
  19. data/lib/rubocop/cop/dev_doc/rails/avoid_lifecycle_method_override.rb +1 -1
  20. data/lib/rubocop/cop/dev_doc/rails/no_error_message_comparison.rb +178 -0
  21. data/lib/rubocop/cop/dev_doc/rails/no_form_param_lookup_in_controller.rb +1 -1
  22. data/lib/rubocop/cop/dev_doc/style/avoid_kernel_array.rb +103 -0
  23. data/lib/rubocop/cop/dev_doc/style/no_silent_rescue.rb +36 -26
  24. data/lib/rubocop/cop/dev_doc/style/no_unscoped_method_definitions.rb +1 -1
  25. data/lib/rubocop/cop/dev_doc/style/rescue_justification.rb +330 -0
  26. data/lib/rubocop/cop/dev_doc/test/justification_covers.rb +216 -0
  27. data/lib/rubocop/cop/dev_doc/test/justification_header.rb +86 -5
  28. data/lib/rubocop/cop/dev_doc/test/require_job_invocation_in_job_tests.rb +154 -0
  29. data/lib/rubocop/cop/dev_doc/test/require_unit_test_justification.rb +5 -24
  30. data/lib/rubocop/cop/dev_doc/test/test_file_placement.rb +30 -2
  31. data/lib/rubocop/dev_doc/version.rb +1 -1
  32. metadata +12 -3
@@ -0,0 +1,154 @@
1
+ require_relative 'test_file_placement'
2
+
3
+ module RuboCop
4
+ module Cop
5
+ module DevDoc
6
+ module Test
7
+ # A test class under test/jobs must invoke the job it is parked
8
+ # next to: its own body, or the body of a same-file ancestor
9
+ # class, contains a send from the entry-point set (`perform`,
10
+ # `perform_now`, `perform_later`, `perform_enqueued_jobs`).
11
+ #
12
+ # ## Rationale
13
+ # test/jobs is the inbound-edge directory: the job IS the
14
+ # boundary, and a job test that never dispatches it tests nothing
15
+ # the directory promises. The observed evasion (fictional names):
16
+ # a service-flow test moved by file only —
17
+ # `SyncOrdersFromVendor.new(row, client: FakeClient.new([...])).call`
18
+ # — under the integration base, ~18 cases in one consumer file.
19
+ # The job's dispatch, guards and follow-up enqueues never ran, the
20
+ # whole Test pack stayed quiet, and other files' justification
21
+ # headers still carried `Wiring:` lines pointing at the file as
22
+ # their cover. Suffix-based unit-class detection
23
+ # (DevDoc/Test/NoUnitIdiomsInIntegrationTests) cannot catch it — a
24
+ # verb-phrase service name is not a unit suffix — and extending
25
+ # that cop's Include into test/jobs was measured and rejected:
26
+ # over the 32-file consumer corpus (five projects) the suffix rule
27
+ # found 0 true hits while the pack's other idiom rules would fire
28
+ # ~70 times on legitimate outbound-edge fakes (stub/Mock machinery
29
+ # in 5 files, one holding 52 stub sends; direct mailer sends in
30
+ # 4). Requiring the entry point instead catches the whole file
31
+ # regardless of how the service is named.
32
+ #
33
+ # The signal is per `*Test` class with same-file ancestry, because
34
+ # that is how honest corpora are shaped: one consumer holds a
35
+ # shared in-file base whose helper drives the job (`run_review`
36
+ # calling `ReviewJob.new.perform(row.id)`) with ~20 subclasses
37
+ # whose own bodies call only the helper — body-only checking
38
+ # would flag every one of them. Only `*Test`-named classes are
39
+ # checked, so in-file scaffolding bases and fake doubles never
40
+ # flag themselves. The rule is base-agnostic: any base is
41
+ # legitimate in this directory; the entry-point contract is the
42
+ # directory's, not the base's.
43
+ #
44
+ # NOTE: Residuals. (a) An enqueue-routing test whose trigger is
45
+ # not a job send (a request, a service call) inside
46
+ # `assert_enqueued_with` never invokes the job — such a test takes
47
+ # an inline disable with a rationale. (b) A performing helper in
48
+ # an included test-helper MODULE is invisible to same-file
49
+ # ancestry; that shape takes an inline disable too. (c) Service
50
+ # instantiation inside an honest perform-driving job test, suffix
51
+ # or not, is not flagged — review's to catch. (d) The cop makes
52
+ # no semantic is-really-testing-the-job judgement: presence of an
53
+ # entry-point send is the whole test, and a bare `perform_later`
54
+ # with no drain satisfies without ever running the job.
55
+ # (e) Ancestry matches const names as spelled — `class
56
+ # Prs::PostTest < Prs::FlowTestCase` does not link to `module Prs;
57
+ # class FlowTestCase` in the same file. Spell both sides the same
58
+ # way, or take an inline disable.
59
+ #
60
+ # @example
61
+ # # bad — test/jobs/sync_orders_job_test.rb
62
+ # class SyncOrdersJobTest < Glib::IntegrationTest
63
+ # test 'vendor timeout falls back' do
64
+ # row = orders(:one)
65
+ # SyncOrdersFromVendor.new(row, client: FakeClient.new([...])).call
66
+ # assert row.reload.synced?
67
+ # end
68
+ # end
69
+ #
70
+ # # good — the job is the entry point, the far side is faked
71
+ # class SyncOrdersJobTest < Glib::IntegrationTest
72
+ # test 'vendor timeout falls back' do
73
+ # row = orders(:one)
74
+ # SyncOrdersJob.perform_now(row, client: fake_client(timeout: true))
75
+ # assert row.reload.synced?
76
+ # end
77
+ # end
78
+ class RequireJobInvocationInJobTests < Base
79
+ include TestFilePlacement
80
+
81
+ MSG = 'This test class never invokes the job. A test under test/jobs is a boundary test — ' \
82
+ 'drive the entry point (`perform`, `perform_now`, `perform_later`, ' \
83
+ '`perform_enqueued_jobs`) with the far side faked and assert what is observable; ' \
84
+ 'a service-flow test that never dispatches the job belongs where the service is ' \
85
+ 'the boundary.'.freeze
86
+
87
+ # The entry-point set lives in code, not config: config lists are
88
+ # droppable, code baselines are not (see
89
+ # NoUnitIdiomsInIntegrationTests::DEFAULT_UNIT_CLASS_SUFFIXES for
90
+ # the incident that taught this).
91
+ ENTRY_POINT_SENDS = %i[perform perform_now perform_later perform_enqueued_jobs].freeze
92
+
93
+ def on_new_investigation
94
+ return if processed_source.blank?
95
+ # In-module guard on purpose: the config Include says the same,
96
+ # but the cop must stay correct even when run with a forced
97
+ # config.
98
+ return unless test_subdirectory == 'jobs'
99
+
100
+ classes_by_name = {}
101
+ processed_source.ast.each_node(:class) do |class_node|
102
+ (classes_by_name[class_node.identifier.const_name] ||= []) << class_node
103
+ end
104
+
105
+ each_test_class do |class_node, _parent|
106
+ next if invokes_job?(class_node, classes_by_name)
107
+
108
+ add_offense(class_node.loc.name)
109
+ end
110
+ end
111
+
112
+ private
113
+
114
+ # Satisfied by an entry-point send anywhere in the class's own
115
+ # body, or in the body of an ancestor class defined in the same
116
+ # file: a shared in-file base whose helper drives the job is the
117
+ # class's driver as much as its own test blocks are. Ancestors
118
+ # resolve by const name against the file's class nodes; a parent
119
+ # defined elsewhere (or none) ends the chain. `visited` keeps the
120
+ # walk finite under reopened class names.
121
+ def invokes_job?(class_node, classes_by_name)
122
+ performs_by_name?(class_node.identifier.const_name, classes_by_name, {})
123
+ end
124
+
125
+ def performs_by_name?(name, classes_by_name, visited)
126
+ return false if visited[name]
127
+
128
+ visited[name] = true
129
+ nodes = classes_by_name[name]
130
+ return false unless nodes
131
+
132
+ nodes.any? { |node| performs_entry_point?(node.body) } ||
133
+ nodes.any? { |node| same_file_parent_performs?(node, classes_by_name, visited) }
134
+ end
135
+
136
+ def same_file_parent_performs?(node, classes_by_name, visited)
137
+ parent = node.parent_class&.const_name
138
+ return false unless parent
139
+
140
+ performs_by_name?(parent, classes_by_name, visited)
141
+ end
142
+
143
+ def performs_entry_point?(body)
144
+ return false unless body
145
+
146
+ body.each_node(:send, :csend).any? do |send|
147
+ ENTRY_POINT_SENDS.include?(send.method_name)
148
+ end
149
+ end
150
+ end
151
+ end
152
+ end
153
+ end
154
+ end
@@ -135,7 +135,6 @@ module RuboCop
135
135
 
136
136
  FORBIDDEN_BASES = %w[ActionDispatch::IntegrationTest Glib::IntegrationTest].freeze
137
137
  EXEMPT_DIRS = %w[controllers integration jobs mailers channels system linters tasks].freeze
138
- NON_HTTP_DIRS = %w[jobs mailers channels].freeze
139
138
 
140
139
  def on_new_investigation
141
140
  return if processed_source.blank?
@@ -149,11 +148,11 @@ module RuboCop
149
148
  private
150
149
 
151
150
  def enforce_directory_rules(dir)
151
+ check_justification if justification_header_required?
152
+
152
153
  if exempt_directories.include?(dir)
153
154
  check_confined_bases(dir)
154
- check_justification if non_http_base_in_non_http_dir?(dir)
155
155
  elsif unit_test_directories.include?(dir)
156
- check_justification
157
156
  check_base_classes
158
157
  check_confined_bases(dir)
159
158
  else
@@ -161,13 +160,6 @@ module RuboCop
161
160
  end
162
161
  end
163
162
 
164
- # Landing on the non-HTTP side-effect base is a conscious exception
165
- # too (the class opted out of HTTP inside an integration-shaped
166
- # home), so it carries the same header contract as a unit directory.
167
- def non_http_base_in_non_http_dir?(dir)
168
- non_http_directories.include?(dir) && class_with_base?(non_http_base_classes)
169
- end
170
-
171
163
  # A justified unit test must also DECLARE itself truthfully. Two
172
164
  # tiers: integration bases get the tailored lie-about-type message;
173
165
  # any other base outside UnitBaseClasses (e.g. plain
@@ -221,26 +213,15 @@ module RuboCop
221
213
 
222
214
  def unit_base_classes = cop_config.fetch('UnitBaseClasses', %w[Glib::LastResortUnitTest])
223
215
 
224
- def non_http_base_classes = cop_config.fetch('NonHttpBaseClasses', %w[Glib::NonHttpIntegrationTest])
225
-
226
216
  def require_unit_base? = cop_config.fetch('RequireUnitBase', true)
227
217
 
228
- def unit_test_directories = cop_config.fetch('UnitTestDirectories', %w[models services helpers])
229
-
230
- def non_http_directories = cop_config.fetch('NonHttpDirectories', NON_HTTP_DIRS)
231
-
232
218
  def exempt_directories = cop_config.fetch('ExemptDirectories', EXEMPT_DIRS)
233
219
 
234
- def known_directories = (exempt_directories + unit_test_directories).map { |d| "test/#{d}/" }.join(', ')
220
+ def known_directories = (exempt_directories + unit_test_directories).map { |dir| "test/#{dir}/" }.join(', ')
235
221
 
236
- def unit_directories_list = unit_test_directories.map { |d| "test/#{d}/" }.join(', ')
222
+ def unit_directories_list = unit_test_directories.map { |dir| "test/#{dir}/" }.join(', ')
237
223
 
238
- def non_http_directories_list = non_http_directories.map { |d| "test/#{d}/" }.join(', ')
239
-
240
- def offense_range
241
- range = processed_source.ast&.source_range || processed_source.comments.first&.source_range
242
- range.with(end_pos: range.begin_pos + [range.source_line.length, 1].max)
243
- end
224
+ def non_http_directories_list = non_http_directories.map { |dir| "test/#{dir}/" }.join(', ')
244
225
  end
245
226
  end
246
227
  end
@@ -3,9 +3,13 @@ module RuboCop
3
3
  module DevDoc
4
4
  module Test
5
5
  # Helpers shared by test-placement cops: classifying which test/
6
- # subdirectory a file belongs to, and scanning its classes for base
7
- # classes that placement rules key on.
6
+ # subdirectory a file belongs to, scanning its classes for base
7
+ # classes that placement rules key on, and the shared
8
+ # justification-header applicability predicate (which files require
9
+ # a header at all).
8
10
  module TestFilePlacement
11
+ NON_HTTP_DIRS = %w[jobs mailers channels].freeze
12
+
9
13
  private
10
14
 
11
15
  # First path segment after the (last) `test/` component; nil when the
@@ -67,6 +71,30 @@ module RuboCop
67
71
  each_class_with_base(bases) { |_superclass, _base| found = true }
68
72
  found
69
73
  end
74
+
75
+ # Config keys the applicability predicate below reads. The header
76
+ # cops mirror these keys in their config entries; keep them in
77
+ # sync or the cops police different file sets.
78
+ def unit_test_directories = cop_config.fetch('UnitTestDirectories', %w[models services helpers])
79
+
80
+ def non_http_directories = cop_config.fetch('NonHttpDirectories', NON_HTTP_DIRS)
81
+
82
+ def non_http_base_classes = cop_config.fetch('NonHttpBaseClasses', %w[Glib::NonHttpIntegrationTest])
83
+
84
+ # Exactly the files whose justification header
85
+ # RequireUnitTestJustification polices: every file in a unit-test
86
+ # directory, plus a non-HTTP-base class inside its own directories
87
+ # (landing on the side-effect base is a conscious opt-out of HTTP,
88
+ # so it carries the same header contract as a unit directory).
89
+ # Header piggyback cops (JustificationCovers) run on this same set
90
+ # so their rules fire exactly where a header can exist.
91
+ def justification_header_required?
92
+ dir = test_subdirectory
93
+ return false if dir.nil?
94
+
95
+ unit_test_directories.include?(dir) ||
96
+ (non_http_directories.include?(dir) && class_with_base?(non_http_base_classes))
97
+ end
70
98
  end
71
99
  end
72
100
  end
@@ -1,5 +1,5 @@
1
1
  module RuboCop
2
2
  module DevDoc
3
- VERSION = "0.18.0".freeze
3
+ VERSION = "0.19.0".freeze
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rubocop-dev_doc
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.18.0
4
+ version: 0.19.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - dev-doc contributors
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2026-10-13 00:00:00.000000000 Z
11
+ date: 2026-11-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -113,6 +113,8 @@ files:
113
113
  - lib/rubocop/cop/dev_doc/auth/no_record_presence_in_policy.rb
114
114
  - lib/rubocop/cop/dev_doc/auth/role_predicate_outside_policy.rb
115
115
  - lib/rubocop/cop/dev_doc/auth/unscoped_find_justification.rb
116
+ - lib/rubocop/cop/dev_doc/bundler/conflicting_gem.rb
117
+ - lib/rubocop/cop/dev_doc/exception_class_list.rb
116
118
  - lib/rubocop/cop/dev_doc/hash_pair_removal.rb
117
119
  - lib/rubocop/cop/dev_doc/i18n/avoid_titleize_humanize.rb
118
120
  - lib/rubocop/cop/dev_doc/i18n/hardcoded_text.rb
@@ -130,12 +132,14 @@ files:
130
132
  - lib/rubocop/cop/dev_doc/migration/boolean_column_not_null.rb
131
133
  - lib/rubocop/cop/dev_doc/migration/date_column_naming.rb
132
134
  - lib/rubocop/cop/dev_doc/migration/explicit_null_on_reference.rb
135
+ - lib/rubocop/cop/dev_doc/migration/legacy_migration.rb
133
136
  - lib/rubocop/cop/dev_doc/migration/no_bulk_change_table.rb
134
137
  - lib/rubocop/cop/dev_doc/migration/no_create_join_table.rb
135
138
  - lib/rubocop/cop/dev_doc/migration/prefer_belongs_to.rb
136
139
  - lib/rubocop/cop/dev_doc/migration/redundant_reference_index.rb
137
140
  - lib/rubocop/cop/dev_doc/migration/require_primary_key.rb
138
141
  - lib/rubocop/cop/dev_doc/migration/require_reference_foreign_key.rb
142
+ - lib/rubocop/cop/dev_doc/migration/require_reference_index.rb
139
143
  - lib/rubocop/cop/dev_doc/migration/require_timestamps.rb
140
144
  - lib/rubocop/cop/dev_doc/rails/application_model_base.rb
141
145
  - lib/rubocop/cop/dev_doc/rails/application_record_transaction.rb
@@ -150,6 +154,7 @@ files:
150
154
  - lib/rubocop/cop/dev_doc/rails/no_block_predicate_on_relation.rb
151
155
  - lib/rubocop/cop/dev_doc/rails/no_collection_ids_writer_in_controller.rb
152
156
  - lib/rubocop/cop/dev_doc/rails/no_deliver_later_in_transaction.rb
157
+ - lib/rubocop/cop/dev_doc/rails/no_error_message_comparison.rb
153
158
  - lib/rubocop/cop/dev_doc/rails/no_errors_add_in_controller.rb
154
159
  - lib/rubocop/cop/dev_doc/rails/no_form_param_lookup_in_controller.rb
155
160
  - lib/rubocop/cop/dev_doc/rails/no_manual_record_invalid.rb
@@ -163,6 +168,7 @@ files:
163
168
  - lib/rubocop/cop/dev_doc/route/resources_require_only.rb
164
169
  - lib/rubocop/cop/dev_doc/style/avoid_head_response.rb
165
170
  - lib/rubocop/cop/dev_doc/style/avoid_insecure_send.rb
171
+ - lib/rubocop/cop/dev_doc/style/avoid_kernel_array.rb
166
172
  - lib/rubocop/cop/dev_doc/style/avoid_options_hash.rb
167
173
  - lib/rubocop/cop/dev_doc/style/avoid_symbolizing_boundary_input.rb
168
174
  - lib/rubocop/cop/dev_doc/style/case_else_decision.rb
@@ -177,11 +183,13 @@ files:
177
183
  - lib/rubocop/cop/dev_doc/style/redundant_guard_after_bang.rb
178
184
  - lib/rubocop/cop/dev_doc/style/repeated_bracket_read.rb
179
185
  - lib/rubocop/cop/dev_doc/style/repeated_safe_navigation_receiver.rb
186
+ - lib/rubocop/cop/dev_doc/style/rescue_justification.rb
180
187
  - lib/rubocop/cop/dev_doc/style/string_symbol_comparison.rb
181
188
  - lib/rubocop/cop/dev_doc/style/tap_block_ignores_value.rb
182
189
  - lib/rubocop/cop/dev_doc/style/use_g_log.rb
183
190
  - lib/rubocop/cop/dev_doc/test/avoid_glib_travel_freeze.rb
184
191
  - lib/rubocop/cop/dev_doc/test/avoid_unit_test.rb
192
+ - lib/rubocop/cop/dev_doc/test/justification_covers.rb
185
193
  - lib/rubocop/cop/dev_doc/test/justification_header.rb
186
194
  - lib/rubocop/cop/dev_doc/test/no_persistence_in_mailer_previews.rb
187
195
  - lib/rubocop/cop/dev_doc/test/no_unit_idioms_in_integration_tests.rb
@@ -189,6 +197,7 @@ files:
189
197
  - lib/rubocop/cop/dev_doc/test/require_glib_integration_base.rb
190
198
  - lib/rubocop/cop/dev_doc/test/require_glib_travel.rb
191
199
  - lib/rubocop/cop/dev_doc/test/require_glib_travel_block.rb
200
+ - lib/rubocop/cop/dev_doc/test/require_job_invocation_in_job_tests.rb
192
201
  - lib/rubocop/cop/dev_doc/test/require_unit_test_justification.rb
193
202
  - lib/rubocop/cop/dev_doc/test/response_assert_equal.rb
194
203
  - lib/rubocop/cop/dev_doc/test/test_file_placement.rb
@@ -217,7 +226,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
217
226
  - !ruby/object:Gem::Version
218
227
  version: '0'
219
228
  requirements: []
220
- rubygems_version: 3.4.6
229
+ rubygems_version: 3.5.22
221
230
  signing_key:
222
231
  specification_version: 4
223
232
  summary: RuboCop cops enforcing dev-doc best practices