rubocop-dev_doc 0.21.0 → 0.22.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 1059b7ea3042b2063f1720a795b9e2c21f9a03c2f30294e2b1947c27f226df6c
4
- data.tar.gz: 1f6b849f309dc6a9b054db65309069ba80d0d78e31f7a86e1e6640149d333955
3
+ metadata.gz: f8fa4d94cab992e1b82b6fb63085ea2f8a50b6665a218b2e66cac75db2018fcf
4
+ data.tar.gz: 5d22cb887930146ab98be92c2471700c5940777d24e6d8184b77cc97eddf69b8
5
5
  SHA512:
6
- metadata.gz: ed1f6fdbd41240058bc10efda89b902f470e5f10fb774d95f7856f455fcf37a4c8b126996fbb3210289376d011407370e6e29d17f0b91a7788689a9d3c69b5d9
7
- data.tar.gz: dfdacfbd3fbe5234292fd9e526c153f3c0284d2cf091ea7046201d0e9b0f7af63b63c261ebbd4810858a95280e908edcf680b595621afc4f3615943fc5de1c8f
6
+ metadata.gz: 8a0aa950c73164749b65385086cac1230d6bc4c060118b61d0bd0d1a3e74a6b0feed183d10c363a3620bf3365c2b88b3788a984e1e26c788df81184cc4a6f3f1
7
+ data.tar.gz: 5f1e7fa36f2d3232d4d9817889f1ea3c8f5f47bde4ec23da086d460c348c7194a644120eedda4fb2784dee7ea759a94e7e50f88c8bdda0b7d2f2e2146c363ee9
data/config/default.yml CHANGED
@@ -312,6 +312,13 @@ DevDoc/Rails/NoBlockPredicateOnRelation:
312
312
  - "db/seeds/**/*.rb"
313
313
  - "lib/tasks/**/*.rb"
314
314
 
315
+ DevDoc/Rails/NoWithDeletedAssociationScope:
316
+ Description: "Association scopes must not lift the soft-delete default scope (with_deleted, unscoped, unscope(where: :deleted_at)); read deleted rows at the call site or via a helper method instead."
317
+ Enabled: true
318
+ Exclude:
319
+ - "spec/**/*"
320
+ - "test/**/*"
321
+
315
322
  DevDoc/Style/NoUnscopedMethodDefinitions:
316
323
  Description: "Define methods inside an explicit `module` or `class`; bare `def` outside a class/module body lands on `Object`."
317
324
  Enabled: true
@@ -1332,6 +1339,48 @@ DevDoc/View/PreferPropOverName:
1332
1339
  - "app/views/**/*.jbuilder"
1333
1340
  - "app/views/**/*.rb"
1334
1341
 
1342
+ DevDoc/View/ImplementationVocabulary:
1343
+ Description: "Flag implementation vocabulary (\"recompute\", \"enqueue\", …) in user-facing text props; write for the reader instead (07_view item 10)."
1344
+ # Disabled by default — per-consumer opt-in: the term list is
1345
+ # project-specific, and projects whose users are developers may say
1346
+ # "backend" to them legitimately (the precedent is PreferPropOverName).
1347
+ # A clean run is not "the copy is fine": locale YAML is unread and
1348
+ # clarity is out of the cop's reach — review reads every added or
1349
+ # changed string (07_view.md item 10).
1350
+ Enabled: false
1351
+ # Terms: words that mark a sentence as written in the code's
1352
+ # vocabulary. Deliberately conservative — words with ordinary
1353
+ # non-technical uses ("record", "sync", "processed") are left to
1354
+ # review; a project adds the ones its system says out loud.
1355
+ # Calibration (2026-11, one consumer's app/views): 607 files,
1356
+ # 1 offence — the sentence the cop was written for; 0 false positives.
1357
+ Terms:
1358
+ - recompute
1359
+ - recomputed
1360
+ - recomputation
1361
+ - "nil"
1362
+ - "null"
1363
+ - boolean
1364
+ - payload
1365
+ - enqueue
1366
+ - enqueued
1367
+ - cron
1368
+ - backend
1369
+ - frontend
1370
+ - callback
1371
+ - async
1372
+ # WatchedMethods: the glib component builder methods whose hash props
1373
+ # carry user-facing text (as RequireTranslation watches), plus `render`:
1374
+ # shared confirmation dialogs and partials take their copy as kwargs.
1375
+ # The list is not repeated here — the cop extends the shared module
1376
+ # default with `render` in code (WATCHED_METHODS), so it tracks the
1377
+ # module list; an explicit WatchedMethods config in a consumer
1378
+ # replaces the whole list. LocalizableKeys (the prop names checked)
1379
+ # stays the module default.
1380
+ Include:
1381
+ - "app/views/**/*.jbuilder"
1382
+ - "app/views/**/*.rb"
1383
+
1335
1384
  DevDoc/I18n/RequireTranslation:
1336
1385
  Description: "Localize user-facing strings in glib JSON-UI props; pass `t(...)` instead of a hardcoded string."
1337
1386
  Enabled: false
@@ -1514,6 +1563,31 @@ DevDoc/Style/RescueJustification:
1514
1563
  Meaning: "a controller rendering a domain error raised below it"
1515
1564
  Path: "app/controllers/"
1516
1565
 
1566
+ # No marker satisfies this one: a `rescue-reason:` states why the catch-all
1567
+ # exists, not how bugs are reported. The remedy is always available — name the
1568
+ # expected classes in their own clause, report the remainder at error level.
1569
+ DevDoc/Style/BroadRescueReportsError:
1570
+ Description: "A catch-all rescue (bare, `rescue => e`, or rescuing a broad class, alone or among named classes) must re-raise or report at error level — a warn-level catch-all files bugs as noise."
1571
+ Enabled: true
1572
+ Include:
1573
+ - "app/**/*.rb"
1574
+ - "lib/**/*.rb"
1575
+ BroadClasses:
1576
+ - "StandardError"
1577
+ - "Exception"
1578
+ # `report` is deliberately absent: Rails.error.report defaults to warning
1579
+ # severity for a handled error. `notify` is absent for the same reason.
1580
+ ErrorReportingMethods:
1581
+ - "error"
1582
+ - "exception"
1583
+ - "fatal"
1584
+ - "critical"
1585
+ # Names starting with these prefixes never count: a local-only log call
1586
+ # (glib's GLog.local_error is Rails.logger.error) never reaches the
1587
+ # error monitor, which is the entire point of the level.
1588
+ LocalOnlyPrefixes:
1589
+ - "local_"
1590
+
1517
1591
  DevDoc/Style/UseGLog:
1518
1592
  Description: "Route logging through GLog (glib-web) — flag Rails.logger.<any> and Rollbar's reporting methods (error/warning/info/debug/critical/log) outside the facade; Rollbar.configure and other setup calls are not reporting."
1519
1593
  Enabled: true
@@ -77,7 +77,7 @@ module DevDoc
77
77
 
78
78
  def __dev_doc_response_body
79
79
  response&.body.to_s
80
- rescue StandardError
80
+ rescue StandardError # rubocop:disable DevDoc/Style/BroadRescueReportsError -- error-level reporting here would raise in the consumer's test run (their error channel re-raises in test), failing the very test the canary rides on; the swallow is the design
81
81
  # rescue-reason: side-effect: the canary rides on every request test
82
82
  # and must not fail it.
83
83
  # silent-rescue: the canary check must never fail on an unreadable
@@ -0,0 +1,34 @@
1
+ module RuboCop
2
+ module Cop
3
+ module DevDoc
4
+ # Shared method-name token matching for the rescue-reporting cops.
5
+ # RuboCop has no type information, so a reporting or propagating call
6
+ # is matched by its name: after stripping a trailing `?`/`!`/`=`, any
7
+ # of its `_`-separated segments must equal one of the configured
8
+ # verbs. Receiver-agnostic — `logger.error(e)`,
9
+ # `Sentry.capture_exception(e)` and a delegating handler whose name
10
+ # says what it does all count — while a name that merely CONTAINS a
11
+ # verb (`login_path`, `tracking_number`) does not.
12
+ module MethodNameTokenMatch
13
+ private
14
+
15
+ # `warning?`/`save!`/`level=` lose their suffix before splitting.
16
+ def method_name_tokens(name)
17
+ name.to_s.sub(/[?!=]\z/, '').split('_')
18
+ end
19
+
20
+ # +propagating+ is a list of method names (typically
21
+ # NoSilentRescue::PROPAGATING_METHODS) that satisfy the check
22
+ # outright; +verbs+ is matched as whole name tokens, at any
23
+ # position.
24
+ def token_match_call?(call, verbs, propagating: [].freeze)
25
+ name = call.method_name
26
+ return true if propagating.include?(name)
27
+
28
+ tokens = method_name_tokens(name)
29
+ verbs.any? { |verb| tokens.include?(verb) }
30
+ end
31
+ end
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,124 @@
1
+ module RuboCop
2
+ module Cop
3
+ module DevDoc
4
+ module Rails
5
+ # Flags association declarations whose scope lambda lifts the
6
+ # soft-delete default scope, so every reader of the association
7
+ # silently sees soft-deleted rows.
8
+ #
9
+ # ## Rationale
10
+ # The need to read soft-deleted rows is real — a receipt that must
11
+ # still name a since-deleted counterpart, a validation that walks
12
+ # a retired parent — but it belongs at a visible call site, never
13
+ # inside an association every reader inherits. An association
14
+ # whose scope lifts the soft-delete default scope changes what
15
+ # the name means for every present and future reader, with
16
+ # nothing at any call site saying so: counts include rows the
17
+ # schema says are gone, displays resurrect them, and validations
18
+ # walk them. The fix is to move the lift to where it happens: a
19
+ # call-site lookup (`Category.with_deleted.find(id)`) or a plain
20
+ # helper method wrapping one names the lifted scope at the read.
21
+ #
22
+ # Every spelling of the lift fires, not just `with_deleted`: bare
23
+ # `unscoped`, and `unscope(...)` whose arguments mention
24
+ # `:deleted_at` (`unscope(where: :deleted_at)`,
25
+ # `unscope(where: [:deleted_at, :code])`) lift the soft-delete
26
+ # default scope along with whatever else they lift. An `unscope`
27
+ # that never mentions `:deleted_at` lifts some other scope and
28
+ # does not fire. There is no association-name exemption: a
29
+ # suffixed declaration (`belongs_to :category_with_deleted`)
30
+ # reads exactly like a plain one at the call site and stays
31
+ # banned.
32
+ #
33
+ # ## Exception
34
+ # Where an association genuinely must read deleted rows, disable
35
+ # this cop inline with the reason stated at the disable: why this
36
+ # association — not a named call site — is the right reader of
37
+ # deleted rows. The disable-with-reason is the sanctioned exit,
38
+ # the same doctrine as the sibling doctrine cops; call-site
39
+ # lookups and plain helper methods are the intended forms and
40
+ # never fire.
41
+ #
42
+ # NOTE: a `with_deleted` / `unscoped` / `unscope(where:
43
+ # :deleted_at)` call anywhere else is legal by design — at a call
44
+ # site (`Category.with_deleted.find(id)`), inside a helper
45
+ # method, inside `default_scope` (Rails/DefaultScope territory)
46
+ # or a named model scope. Only the association macro's own scope
47
+ # lambda is flagged.
48
+ #
49
+ # @example
50
+ # # bad — every reader of `category` sees deleted rows, silently
51
+ # belongs_to :category, -> { with_deleted }
52
+ # has_many :tags, -> { unscoped }
53
+ # has_one :region, -> { unscope(where: [:deleted_at, :code]) }, through: :country
54
+ #
55
+ # # good — the lift is visible at the read
56
+ # belongs_to :category
57
+ #
58
+ # def category_with_deleted
59
+ # Category.with_deleted.find(category_id)
60
+ # end
61
+ class NoWithDeletedAssociationScope < Base
62
+ MSG = 'Association `%<name>s`\'s scope lifts the soft-delete default scope, so every reader sees deleted ' \
63
+ 'rows silently. Read deleted rows at the call site (`Model.with_deleted.find(...)`) or via a plain ' \
64
+ 'helper method; or disable this cop with a reason.'.freeze
65
+
66
+ RESTRICT_ON_SEND = %i[belongs_to has_one has_many has_and_belongs_to_many].freeze
67
+
68
+ def on_send(node)
69
+ name = association_name(node)
70
+ return unless name
71
+
72
+ scope = scope_lambda(node)
73
+ return unless scope
74
+
75
+ offender = scope.each_descendant(:send).find { |send| lifts_soft_delete?(send) }
76
+ return unless offender
77
+
78
+ add_offense(offender, message: format(MSG, name: name))
79
+ end
80
+
81
+ private
82
+
83
+ # The declared association's name (`category` for
84
+ # `belongs_to :category, -> { with_deleted }`); nil when the
85
+ # macro's first argument is not a name literal, which makes the
86
+ # declaration dynamic and not this cop's to judge.
87
+ def association_name(node)
88
+ name = node.first_argument
89
+ name.value.to_s if name && %i[sym str].include?(name.type)
90
+ end
91
+
92
+ # The macro's scope lambda, a block node among its top-level
93
+ # arguments. A lambda nested inside the options hash is not the
94
+ # scope, and the send's OWN block (an extension module) is not
95
+ # an argument at all — neither matches.
96
+ def scope_lambda(node)
97
+ node.arguments.find { |argument| argument.block_type? || argument.numblock_type? }
98
+ end
99
+
100
+ # `with_deleted` and bare `unscoped` always lift the soft-delete
101
+ # default scope; `unscope` does only when one of its arguments
102
+ # mentions `:deleted_at` — as `where: :deleted_at`, inside an
103
+ # array, or nested deeper in the argument tree.
104
+ def lifts_soft_delete?(send)
105
+ return true if %i[with_deleted unscoped].include?(send.method_name)
106
+ return false unless send.method_name == :unscope
107
+
108
+ send.arguments.any? { |argument| mentions_deleted_at?(argument) }
109
+ end
110
+
111
+ # Self-or-descendant: a positional `:deleted_at` symbol is the
112
+ # node itself; the documented spellings nest it inside a hash
113
+ # pair or an array.
114
+ def mentions_deleted_at?(node)
115
+ return false unless node
116
+
117
+ (node.sym_type? && node.value == :deleted_at) ||
118
+ node.each_descendant(:sym).any? { |sym| sym.value == :deleted_at }
119
+ end
120
+ end
121
+ end
122
+ end
123
+ end
124
+ end
@@ -0,0 +1,364 @@
1
+ module RuboCop
2
+ module Cop
3
+ module DevDoc
4
+ module Style
5
+ # Flag a catch-all `rescue` clause (bare, `rescue => e`, or rescuing
6
+ # a broad class such as `StandardError`/`Exception`, alone or among
7
+ # named classes) whose body neither re-raises nor reports the
8
+ # failure at error level.
9
+ #
10
+ # ## Rationale
11
+ # A catch-all is by definition the clause that sees the failures
12
+ # nobody planned for, and an unplanned failure in our own code is a
13
+ # bug: `NoMethodError`, `TypeError`, a wrong argument. Expected
14
+ # failures belong in their own named clauses before the catch-all,
15
+ # reported or handled at whatever level fits THEM. When the
16
+ # catch-all files everything at warning level, the bugs ride along
17
+ # as noise: production triage skims past them, and in projects
18
+ # whose error channel raises in development and test (an error
19
+ # monitor re-armed to raise there), the suite stays green on code
20
+ # that is actually broken. A justification comment does not fix the
21
+ # severity: a marker states WHY the clause exists and says nothing
22
+ # about HOW bugs are reported — an honest reason beside a
23
+ # warn-level catch-all is still a bug channel pointed at the wrong
24
+ # in-box.
25
+ #
26
+ # ## What an offense means
27
+ # An offense asserts the SEVERITY, nothing else. Whether the clause
28
+ # should exist is `DevDoc/Style/RescueJustification`'s question;
29
+ # whether the failure leaves any trace at all is
30
+ # `DevDoc/Style/NoSilentRescue`'s. This cop accepts that the
31
+ # catch-all exists and asks one thing: do the failures only it can
32
+ # see reach the error monitor at error level? There is no marker
33
+ # escape — a marker is how the warn-level shape got through before.
34
+ # The remedy is always available: name the expected classes in
35
+ # their own clause, and report the remainder at error level (or
36
+ # re-raise it). An irreducible case takes an inline
37
+ # `rubocop:disable` with a reason, under the house disable rules.
38
+ #
39
+ # ## Remedy
40
+ # Most catch-alls should not exist; the message and this section
41
+ # lead with the alternatives in order:
42
+ #
43
+ # # 1. Let it propagate
44
+ # ❌ def sync_prices
45
+ # PriceApi.fetch
46
+ # rescue StandardError => e
47
+ # GLog.warn(e, 'price sync failed')
48
+ # end
49
+ # ✔️ def sync_prices
50
+ # PriceApi.fetch # the job runner reports and retries
51
+ # end
52
+ #
53
+ # # 2. Rescue what you expect, by name
54
+ # ❌ rescue StandardError => e
55
+ # GLog.warn(e, 'vendor timed out')
56
+ # ✔️ rescue Net::OpenTimeout, Net::ReadTimeout => e
57
+ # GLog.warn(e, 'vendor timed out')
58
+ #
59
+ # # 3. Make the failure unable to hurt the main path
60
+ # ❌ store_secret! # irreversible
61
+ # begin
62
+ # write_history
63
+ # rescue StandardError => e
64
+ # GLog.warn(e, 'history write failed')
65
+ # end
66
+ # ✔️ store_secret!
67
+ # WriteHistoryJob.perform_later(key) # a failure retries; the job runner reports it
68
+ #
69
+ # # 4. In a batch, isolate one unit
70
+ # ❌ begin
71
+ # members.each { |member| deliver(member) }
72
+ # rescue StandardError => e
73
+ # GLog.error(e) # one failure stops the rest
74
+ # end
75
+ # ✔️ members.each do |member|
76
+ # deliver(member)
77
+ # rescue StandardError => e # rescue-reason: bulkhead: one member's failure must not stop the batch
78
+ # GLog.error(e, member_id: member.id)
79
+ # end
80
+ #
81
+ # A catch-all that survives all four: named clauses first, the rest
82
+ # justified and at error level.
83
+ #
84
+ # begin
85
+ # write_history
86
+ # rescue ActiveRecord::ConnectionNotEstablished => e
87
+ # GLog.warn(e, 'history write failed: database unavailable')
88
+ # rescue StandardError => e # rescue-reason: side-effect: a bug here must not undo the Redis step it follows
89
+ # GLog.error(e, 'history write failed')
90
+ # end
91
+ #
92
+ # ## Severity is matched on the call name — and only on a call
93
+ # ## whose value is discarded
94
+ # A call counts when it is a statement of the body (or of a block
95
+ # inside it) and its name, after stripping a trailing `?`/`!`,
96
+ # carries one of `ErrorReportingMethods` (default: `error`,
97
+ # `exception`, `fatal`, `critical`) as its FIRST or LAST
98
+ # `_`-separated segment: `GLog.error`, `Rollbar.error`,
99
+ # `logger.error`, `Sentry.capture_exception`,
100
+ # `GLog.error_excluding_test` count. A verb in the MIDDLE of a
101
+ # name builds data ABOUT the error rather than reporting it
102
+ # (`format_error_response`, `classify_error_type`,
103
+ # `resolve_error_type`), and a call whose value is consumed — a
104
+ # receiver slot, an argument, hash value or array element of
105
+ # another call, an assignment's right-hand side, a return value,
106
+ # a branch/loop condition, or a setter (`self.error = e.message`)
107
+ # — does not count: in `Rails.error.report(e)` the `error` names
108
+ # the reporter and the call is `report`; in
109
+ # `GLog.warn(classify_error_type(e))` the nested call builds the
110
+ # message. `warn`, `warning`, `info`, `log`, `notice`, `report`,
111
+ # `track` are not error level; `report` is excluded because
112
+ # `Rails.error.report` defaults to warning severity for a handled
113
+ # error — the one override is explicit:
114
+ # `Rails.error.report(e, severity: :error)` carries the severity
115
+ # as a keyword and counts. A name carrying a
116
+ # `LocalOnlyPrefixes` prefix (default `local_`) never counts:
117
+ # glib's `GLog.local_error` writes the local log only and never
118
+ # reaches the error monitor — reaching the monitor is the entire
119
+ # point of the level. Propagation — `raise`, `fail`, `throw`
120
+ # anywhere in the body — also satisfies the cop, as does raising
121
+ # a translated domain error.
122
+ #
123
+ # Returning the exception as data does NOT count. A body whose
124
+ # result references the bound exception (a rendered error payload,
125
+ # `render json: { error: e.message }`) surfaces the failure to the
126
+ # CALLER, not to us; for a catch-all, the bug still has to reach
127
+ # the error monitor. This deliberately narrows
128
+ # `DevDoc/Style/NoSilentRescue`, which accepts that shape.
129
+ #
130
+ # ## Relationship with `DevDoc/Style/NoSilentRescue` and `DevDoc/Style/RescueJustification`
131
+ # Three legs of one rule. NoSilentRescue judges whether a failure
132
+ # leaves ANY trace (any reporting level, any clause — named or
133
+ # broad); this cop judges whether a catch-all's trace is at error
134
+ # LEVEL; RescueJustification judges whether the clause should exist
135
+ # at all and still requires its `rescue-reason:` marker for a
136
+ # catch-all. A warn-level catch-all with an honest marker passes
137
+ # both siblings and fails here; a named `rescue Net::OpenTimeout`
138
+ # reported at warn level is exactly the expected-failure clause
139
+ # this cop leaves alone.
140
+ #
141
+ # ## Configuration
142
+ # `BroadClasses` (default: `StandardError`, `Exception`) — a clause
143
+ # rescuing ANY of these, alone or among named classes, is a
144
+ # catch-all. Matched against the constant as written (leading `::`
145
+ # ignored), like the sibling cops.
146
+ #
147
+ # `ErrorReportingMethods` (default: `error`, `exception`, `fatal`,
148
+ # `critical`) — whole name tokens that count as error-level
149
+ # reporting, matched at the name's head or tail only. `report`
150
+ # and `notify` are left out on purpose (see "Severity is matched
151
+ # on the call name"); add your project's in-house error verbs
152
+ # here.
153
+ #
154
+ # `LocalOnlyPrefixes` (default: `local_`) — names starting with
155
+ # any of these never count, however they are spelled: a
156
+ # local-only log call never reaches the error monitor.
157
+ #
158
+ # NOTE: The walk judges the body syntactically: a matching call on
159
+ # any branch of the body counts, even one the run does not take,
160
+ # and so does a `raise` on any branch. A report whose value is
161
+ # CONSUMED — assigned (`event_id = Sentry.capture_exception(e)
162
+ # &.event_id`), returned, or chained — is not counted, so make
163
+ # the report its own statement and read the value afterwards;
164
+ # the cop fails closed there on purpose. What still gets through
165
+ # for reviewers to judge: a final expression whose name carries
166
+ # the verb at head or tail but produces a payload
167
+ # (`render_error(e)`, `Result.error(e)`) reads as reporting to
168
+ # the name matcher while its value travels as data. A splat-only
169
+ # clause (`rescue *RETRYABLE`) names no class as written and is
170
+ # not matched — RescueJustification still demands its reason.
171
+ # Modifier rescues (`value rescue fallback`) are out of scope, as
172
+ # in the siblings: `Style/RescueModifier` flags every one on form
173
+ # alone. Only `app/` and `lib/` are inspected.
174
+ #
175
+ # @example
176
+ # # bad — a catch-all files bugs as warnings
177
+ # begin
178
+ # write_history
179
+ # rescue StandardError => e
180
+ # GLog.warn('history write failed', error: e.message)
181
+ # end
182
+ #
183
+ # # good — named clauses first, the rest justified and at error level
184
+ # begin
185
+ # write_history
186
+ # rescue ActiveRecord::ConnectionNotEstablished => e
187
+ # GLog.warn(e, 'history write failed: database unavailable')
188
+ # rescue StandardError => e # rescue-reason: side-effect: a bug here must not undo the Redis step it follows
189
+ # GLog.error(e, 'history write failed')
190
+ # end
191
+ class BroadRescueReportsError < Base
192
+ include ExceptionClassList
193
+ include MethodNameTokenMatch
194
+ include RescueNode
195
+
196
+ MSG = 'A catch-all rescue catches the failures nobody planned for, which are bugs in our code. ' \
197
+ 'Most catch-alls should not exist. Before keeping this one: (1) Let it propagate: Rails, ' \
198
+ 'Sidekiq and the job runner already report unhandled errors at error level with the backtrace; ' \
199
+ 'rescue only when execution must continue. (2) Rescue what you expect, by name (`rescue ' \
200
+ 'Net::OpenTimeout, SocketError => e`, `rescue ActiveRecord::RecordNotUnique`); unexpected ' \
201
+ 'errors then propagate by themselves. (3) Make the failure unable to hurt the main path: do ' \
202
+ 'the fragile step before the irreversible one, or move it into a background job where a ' \
203
+ 'failure retries and is reported without touching the request. (4) In a batch, isolate one ' \
204
+ 'unit: rescue per item, not around the loop. If a catch-all is still needed, it states why ' \
205
+ 'in a `rescue-reason: <category>: <why>` comment (DevDoc/Style/RescueJustification) and ' \
206
+ 'reports at error level (`GLog.error(e, ...)`, `Rollbar.error`, `logger.error`) or re-raises. ' \
207
+ 'A warning-level catch-all files bugs as noise.'.freeze
208
+
209
+ DEFAULT_BROAD_CLASSES = %w[StandardError Exception].freeze
210
+
211
+ DEFAULT_ERROR_REPORTING_METHODS = %w[error exception fatal critical].freeze
212
+
213
+ DEFAULT_LOCAL_ONLY_PREFIXES = %w[local_].freeze
214
+
215
+ # Direct value positions: the right-hand side of an assignment,
216
+ # a returned value, the condition of a branch or loop.
217
+ VALUE_PARENT_TYPES = %i[lvasgn ivasgn gvasgn cvasgn casgn op_asgn or_asgn and_asgn masgn return].freeze
218
+
219
+ CONDITION_PARENT_TYPES = %i[if unless while until].freeze
220
+
221
+ def on_resbody(node)
222
+ return if rescue_modifier?(node)
223
+ return unless catch_all?(node)
224
+ return if propagates_or_reports_error?(node.body)
225
+
226
+ add_offense(node.loc.keyword)
227
+ end
228
+
229
+ private
230
+
231
+ # A bare `rescue` and `rescue => e` rescue StandardError by Ruby
232
+ # semantics, and a clause listing any broad class — alone or
233
+ # among named classes — is a catch-all however it is spelled.
234
+ def catch_all?(node)
235
+ exceptions = node.exceptions
236
+ return true if exceptions.empty?
237
+
238
+ exceptions.any? { |exception| listed_exception?(exception, broad_classes) }
239
+ end
240
+
241
+ # Any error-level reporting or propagating call in the body —
242
+ # including the body itself when it is that call. An empty body
243
+ # reports nothing by construction.
244
+ def propagates_or_reports_error?(body)
245
+ return false if body.nil?
246
+
247
+ body.each_node(:send, :csend).any? do |call|
248
+ statement_call?(call) && error_reporting_call?(call)
249
+ end
250
+ end
251
+
252
+ # A reporting call counts where its value is DISCARDED — a
253
+ # statement of the body, or of a block inside it — never where
254
+ # its value is consumed as data: a receiver slot, an argument,
255
+ # hash value or array element of another call, an assignment's
256
+ # right-hand side, a return value, or a branch/loop condition.
257
+ # In `Rails.error.report(e)` the `error` names the reporter and
258
+ # the call is `report`; in `GLog.warn(classify_error_type(e))`
259
+ # the nested call builds the message and reports nothing.
260
+ def statement_call?(node)
261
+ parent = node.parent
262
+ return true unless parent
263
+ return false if data_parent?(parent, node)
264
+
265
+ enclosing_statement_context?(node)
266
+ end
267
+
268
+ # Walking up from the call: the rescue body itself, or a block
269
+ # body inside it, is a statement context; a send/csend ancestor
270
+ # with no block between consumes the call's value as data.
271
+ def enclosing_statement_context?(node)
272
+ current = node
273
+ while (ancestor = current.parent)
274
+ return true if ancestor.resbody_type?
275
+ return false if ancestor.send_type? || ancestor.csend_type?
276
+ return true if ancestor.block_type? || ancestor.numblock_type?
277
+
278
+ current = ancestor
279
+ end
280
+ true
281
+ end
282
+
283
+ def data_parent?(parent, node)
284
+ return true if VALUE_PARENT_TYPES.include?(parent.type)
285
+ return false unless CONDITION_PARENT_TYPES.include?(parent.type)
286
+
287
+ parent.condition.equal?(node)
288
+ end
289
+
290
+ def error_reporting_call?(call)
291
+ name = call.method_name
292
+ return true if NoSilentRescue::PROPAGATING_METHODS.include?(name)
293
+ return false if setter_name?(name) || local_only_name?(name)
294
+
295
+ verb_at_head_or_tail?(name) || explicit_error_severity?(call)
296
+ end
297
+
298
+ # A setter stores; a middle verb builds data ABOUT the error
299
+ # (`format_error_response`, `classify_error_type`) rather than
300
+ # reporting it — the reporting verb sits at the name's head
301
+ # (`error_excluding_test`) or tail (`capture_exception`,
302
+ # `report_error`).
303
+ def verb_at_head_or_tail?(name)
304
+ tokens = method_name_tokens(name)
305
+ error_reporting_methods.any? do |verb|
306
+ tokens.first == verb || tokens.last == verb
307
+ end
308
+ end
309
+
310
+ # `Rails.error.report(e)` does not count (its default severity
311
+ # is warning), but an explicit `severity: :error` keyword
312
+ # overrides the default and does. Only the call's OWN keyword
313
+ # arguments are read — a `severity:` key nested deeper is part
314
+ # of a data payload (`render json: { severity: ... }`), not a
315
+ # severity the reporting call was invoked with.
316
+ def explicit_error_severity?(call)
317
+ kwargs = call.arguments.last
318
+ return false unless kwargs&.hash_type?
319
+
320
+ kwargs.pairs.any? { |pair| error_severity_pair?(pair) }
321
+ end
322
+
323
+ # A `severity: :error` keyword of the reporting call itself.
324
+ def error_severity_pair?(pair)
325
+ return false unless pair.key.sym_type? && pair.key.value == :severity
326
+ return false unless pair.value.sym_type? || pair.value.str_type?
327
+
328
+ error_reporting_methods.include?(pair.value.value.to_s)
329
+ end
330
+
331
+ # A trailing `=` is a setter (`self.error = e.message`): the
332
+ # name matches after the suffix is stripped, but a setter
333
+ # stores data and reports nothing.
334
+ def setter_name?(name)
335
+ name.to_s.end_with?('=')
336
+ end
337
+
338
+ # `GLog.local_error` writes the local log only and never
339
+ # reaches the error monitor — reaching the monitor is the
340
+ # entire point of the level, so a local-only name does not
341
+ # satisfy the cop however it is spelled.
342
+ def local_only_name?(name)
343
+ local_only_prefixes.any? { |prefix| name.to_s.start_with?(prefix) }
344
+ end
345
+
346
+ def broad_classes
347
+ @broad_classes ||=
348
+ Array(cop_config.fetch('BroadClasses', DEFAULT_BROAD_CLASSES)) # rubocop:disable DevDoc/Style/AvoidKernelArray -- cop config accepts one class name or a list
349
+ end
350
+
351
+ def error_reporting_methods
352
+ @error_reporting_methods ||=
353
+ Array(cop_config.fetch('ErrorReportingMethods', DEFAULT_ERROR_REPORTING_METHODS)) # rubocop:disable DevDoc/Style/AvoidKernelArray -- cop config accepts one method name or a list
354
+ end
355
+
356
+ def local_only_prefixes
357
+ @local_only_prefixes ||=
358
+ Array(cop_config.fetch('LocalOnlyPrefixes', DEFAULT_LOCAL_ONLY_PREFIXES)) # rubocop:disable DevDoc/Style/AvoidKernelArray -- cop config accepts one prefix or a list
359
+ end
360
+ end
361
+ end
362
+ end
363
+ end
364
+ end
@@ -93,7 +93,8 @@ module RuboCop
93
93
  # default: an external failure is still a failure and must be
94
94
  # reported, even when the code degrades around it. Whether the
95
95
  # clause should exist at all is `DevDoc/Style/RescueJustification`'s
96
- # question, not this cop's.
96
+ # question, not this cop's; whether a catch-all's trace is at error
97
+ # LEVEL is `DevDoc/Style/BroadRescueReportsError`'s.
97
98
  #
98
99
  # ## Relationship with `Lint/SuppressedException` (stock)
99
100
  # This cop is a strict superset at the stock cop's default settings
@@ -183,6 +184,7 @@ module RuboCop
183
184
  class NoSilentRescue < Base
184
185
  include Auth::AdjacentJustification
185
186
  include ExceptionClassList
187
+ include MethodNameTokenMatch
186
188
  include RescueNode
187
189
 
188
190
  MSG = 'This rescue swallows the failure without a trace — report it (a logger/error-monitor ' \
@@ -252,11 +254,7 @@ module RuboCop
252
254
  # reporting. `warning?`/`save!`/`level=` lose their suffix before
253
255
  # splitting.
254
256
  def reporting_call?(call)
255
- name = call.method_name
256
- return true if PROPAGATING_METHODS.include?(name)
257
-
258
- tokens = name.to_s.sub(/[?!=]\z/, '').split('_')
259
- reporting_methods.any? { |verb| tokens.include?(verb) }
257
+ token_match_call?(call, reporting_methods, propagating: PROPAGATING_METHODS)
260
258
  end
261
259
 
262
260
  def reporting_methods
@@ -114,7 +114,10 @@ module RuboCop
114
114
  # here; a `rescue ActiveRecord::RecordNotUnique; nil` passes both
115
115
  # (NoSilentRescue's `ExpectedOutcomeClasses`). The two markers are
116
116
  # different on purpose and a site may carry both — a bulkhead that
117
- # also degrades silently states each.
117
+ # also degrades silently states each. The third leg is
118
+ # `DevDoc/Style/BroadRescueReportsError`: where NoSilentRescue asks
119
+ # whether a catch-all leaves a trace, that cop asks the trace's
120
+ # severity — error level or re-raise.
118
121
  #
119
122
  # Modifier rescues (`value rescue fallback`) are out of scope, as in
120
123
  # NoSilentRescue: `Style/RescueModifier` flags every one on form
@@ -0,0 +1,110 @@
1
+ require_relative '../i18n/localizable_props'
2
+
3
+ module RuboCop
4
+ module Cop
5
+ module DevDoc
6
+ module View
7
+ # Flag implementation vocabulary in user-facing text props.
8
+ #
9
+ # ## Rationale
10
+ # A message composed beside the code borrows the code's nouns:
11
+ # "recompute", "enqueue", "payload" describe what the system does
12
+ # internally, not what happens to the reader's things. Best practice
13
+ # `07_view.md` item 10: name who reads the screen, then write what
14
+ # happens to their things and when, in their words — a message that
15
+ # passes a spelling check but speaks system is still a defect.
16
+ #
17
+ # The cop reports a configured term appearing as a whole word
18
+ # (case-insensitive) in a string literal that is the value of a
19
+ # localizable key on a watched call: hash props (`view.p text:`),
20
+ # nested hash props (`tooltip: { text: }`), jbuilder positionals
21
+ # (`json.title`), and `render` kwargs — the shape shared
22
+ # confirmation dialogs and partials take their copy in. Adjacent
23
+ # literals joined with `\` arrive as one concatenated string and are
24
+ # inspected whole; the literal parts of an interpolated string are
25
+ # inspected; a value resolved through `t(...)` is not (the term sits
26
+ # in a locale file the cop cannot read).
27
+ #
28
+ # Default-disabled, per-consumer opt-in (the precedent is
29
+ # `DevDoc/View/PreferPropOverName`): the corpus is shared with
30
+ # projects whose users are developers, where a word like "backend"
31
+ # is legitimate user-facing vocabulary. A project enables the cop
32
+ # with its own `Terms:` list.
33
+ #
34
+ # ## Exceptions — a clean run is not "the copy is fine"
35
+ # - Locale YAML is not inspected (RuboCop does not parse it): terms
36
+ # inside `t('...')` values are out of reach.
37
+ # - Whole-word matching only: a term hidden in a longer word
38
+ # ("nullable" when "null" is listed) is not reported.
39
+ # - Vocabulary is the crudest signal. A sentence with no listed term
40
+ # can still be written for the system, not the reader ("resolved",
41
+ # "on the next recompute" pass when the terms are not listed);
42
+ # reading the sentence as its reader is review's judgment —
43
+ # `07_view.md` item 10.
44
+ #
45
+ # @example
46
+ # # bad — the code's word in a user-facing message
47
+ # render 'shared/confirmation_dialog', message: 'Your request will be processed on the next recompute.'
48
+ #
49
+ # # good — what happens to the reader's things, and when
50
+ # render 'shared/confirmation_dialog', message: 'Your request starts now; we will email you when it is done.'
51
+ #
52
+ # # good — a term in a non-localizable key is left alone
53
+ # view.p text: 'Saved', styleClass: 'async-fade'
54
+ class ImplementationVocabulary < Base
55
+ include I18n::LocalizableProps
56
+
57
+ MSG = '`%<term>s` is the code\'s word, not the reader\'s: ' \
58
+ 'say what happens to their things (07_view item 10)'.freeze
59
+
60
+ DEFAULT_TERMS = %w[
61
+ recompute recomputed recomputation nil null boolean payload
62
+ enqueue enqueued cron backend frontend callback async
63
+ ].freeze
64
+
65
+ # The shared traversal's watched calls plus `render`: shared
66
+ # confirmation dialogs and partials take their copy as kwargs.
67
+ # Defined once here instead of a third YAML copy of the list, so
68
+ # it tracks the module default; an explicit WatchedMethods config
69
+ # replaces the whole list, as any configurable list does.
70
+ WATCHED_METHODS =
71
+ (I18n::LocalizableProps::DEFAULT_WATCHED_METHODS + %w[render]).freeze
72
+
73
+ private
74
+
75
+ # `render` joins the module's watched calls (see WATCHED_METHODS).
76
+ def watched_methods
77
+ cop_config.fetch('WatchedMethods', WATCHED_METHODS)
78
+ end
79
+
80
+ def inspect_localizable(_key, value)
81
+ term = literal_parts(value).filter_map { |part| offending_term(part) }.first
82
+ return unless term
83
+
84
+ add_offense(value, message: format(MSG, term: term))
85
+ end
86
+
87
+ # The literal text a reader sees: a string literal (adjacent
88
+ # `\`-joined literals arrive as one concatenated str node) and the
89
+ # literal parts of an interpolated string. A value resolved through
90
+ # `t(...)` is a send node with no literal parts.
91
+ def literal_parts(value)
92
+ case value.type
93
+ when :str then [value.value]
94
+ when :dstr then value.children.select(&:str_type?).map(&:value)
95
+ else []
96
+ end
97
+ end
98
+
99
+ def offending_term(part)
100
+ terms.find { |term| part.match?(/\b#{Regexp.escape(term)}\b/i) }
101
+ end
102
+
103
+ def terms
104
+ cop_config.fetch('Terms', DEFAULT_TERMS)
105
+ end
106
+ end
107
+ end
108
+ end
109
+ end
110
+ end
@@ -1,5 +1,5 @@
1
1
  module RuboCop
2
2
  module DevDoc
3
- VERSION = "0.21.0".freeze
3
+ VERSION = "0.22.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.21.0
4
+ version: 0.22.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-11-19 00:00:00.000000000 Z
11
+ date: 2026-11-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -123,6 +123,7 @@ files:
123
123
  - lib/rubocop/cop/dev_doc/i18n/require_translation.rb
124
124
  - lib/rubocop/cop/dev_doc/i18n/text_shape.rb
125
125
  - lib/rubocop/cop/dev_doc/i18n/translation_key_prefix.rb
126
+ - lib/rubocop/cop/dev_doc/method_name_token_match.rb
126
127
  - lib/rubocop/cop/dev_doc/migration/amount_column_in_cents.rb
127
128
  - lib/rubocop/cop/dev_doc/migration/avoid_boolean_column.rb
128
129
  - lib/rubocop/cop/dev_doc/migration/avoid_column_default.rb
@@ -165,6 +166,7 @@ files:
165
166
  - lib/rubocop/cop/dev_doc/rails/no_perform_later_in_model.rb
166
167
  - lib/rubocop/cop/dev_doc/rails/no_persistence_in_service.rb
167
168
  - lib/rubocop/cop/dev_doc/rails/no_transaction_in_controller.rb
169
+ - lib/rubocop/cop/dev_doc/rails/no_with_deleted_association_scope.rb
168
170
  - lib/rubocop/cop/dev_doc/rails/rescue_record_not_unique_index.rb
169
171
  - lib/rubocop/cop/dev_doc/rails/soft_failure_in_bang_method.rb
170
172
  - lib/rubocop/cop/dev_doc/rails/strong_parameters_expect.rb
@@ -177,6 +179,7 @@ files:
177
179
  - lib/rubocop/cop/dev_doc/style/avoid_kernel_array.rb
178
180
  - lib/rubocop/cop/dev_doc/style/avoid_options_hash.rb
179
181
  - lib/rubocop/cop/dev_doc/style/avoid_symbolizing_boundary_input.rb
182
+ - lib/rubocop/cop/dev_doc/style/broad_rescue_reports_error.rb
180
183
  - lib/rubocop/cop/dev_doc/style/case_else_decision.rb
181
184
  - lib/rubocop/cop/dev_doc/style/in_memory_association_find.rb
182
185
  - lib/rubocop/cop/dev_doc/style/literal_operator_in_condition.rb
@@ -208,6 +211,7 @@ files:
208
211
  - lib/rubocop/cop/dev_doc/test/response_assert_equal.rb
209
212
  - lib/rubocop/cop/dev_doc/test/test_file_placement.rb
210
213
  - lib/rubocop/cop/dev_doc/test/test_name_special_characters.rb
214
+ - lib/rubocop/cop/dev_doc/view/implementation_vocabulary.rb
211
215
  - lib/rubocop/cop/dev_doc/view/prefer_prop_over_name.rb
212
216
  - lib/rubocop/dev_doc.rb
213
217
  - lib/rubocop/dev_doc/plugin.rb