rubocop-munra 0.2.0 → 1.0.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 (53) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +42 -0
  3. data/README.md +11 -1
  4. data/config/default.yml +101 -1
  5. data/lib/rubocop/cop/munra/00_model_scope_names.rb +42 -0
  6. data/lib/rubocop/cop/munra/00_model_spec_section_checks.rb +71 -0
  7. data/lib/rubocop/cop/munra/00_rspec_helpers.rb +26 -3
  8. data/lib/rubocop/cop/munra/00_transaction_block_mixin.rb +7 -6
  9. data/lib/rubocop/cop/munra/address_fields_order.rb +66 -0
  10. data/lib/rubocop/cop/munra/address_state_select.rb +3 -3
  11. data/lib/rubocop/cop/munra/admin_policy.rb +55 -8
  12. data/lib/rubocop/cop/munra/brazilian_state_inclusion.rb +67 -0
  13. data/lib/rubocop/cop/munra/builtin_validation_options.rb +24 -6
  14. data/lib/rubocop/cop/munra/digits_only_attributes.rb +103 -0
  15. data/lib/rubocop/cop/munra/email_format.rb +21 -26
  16. data/lib/rubocop/cop/munra/flash_success_locale_name.rb +30 -25
  17. data/lib/rubocop/cop/munra/flash_success_name.rb +2 -2
  18. data/lib/rubocop/cop/munra/full_error_messages.rb +3 -6
  19. data/lib/rubocop/cop/munra/let_layout.rb +9 -2
  20. data/lib/rubocop/cop/munra/literal_expectation.rb +68 -0
  21. data/lib/rubocop/cop/munra/model_spec_structure.rb +156 -0
  22. data/lib/rubocop/cop/munra/named_subject_layout.rb +4 -6
  23. data/lib/rubocop/cop/munra/no_current_date_in_system_spec.rb +37 -0
  24. data/lib/rubocop/cop/munra/no_human_attribute_name.rb +1 -1
  25. data/lib/rubocop/cop/munra/no_inline_validation.rb +1 -1
  26. data/lib/rubocop/cop/munra/no_leading_dot.rb +1 -1
  27. data/lib/rubocop/cop/munra/no_mixed_example_siblings.rb +57 -0
  28. data/lib/rubocop/cop/munra/no_shared_examples.rb +9 -4
  29. data/lib/rubocop/cop/munra/one_example_per_context.rb +54 -0
  30. data/lib/rubocop/cop/munra/policy_blank_deny.rb +133 -0
  31. data/lib/rubocop/cop/munra/service_object.rb +14 -6
  32. data/lib/rubocop/cop/munra/validations_before_callbacks.rb +80 -0
  33. data/lib/rubocop/munra/plugin.rb +1 -1
  34. data/lib/rubocop/munra/version.rb +1 -3
  35. metadata +14 -19
  36. data/.github/workflows/ci.yml +0 -29
  37. data/.github/workflows/docs.yml +0 -90
  38. data/.ruby-version +0 -1
  39. data/AGENTS.md +0 -101
  40. data/CODE_OF_CONDUCT.md +0 -10
  41. data/Rakefile +0 -42
  42. data/antora-playbook.yml +0 -22
  43. data/docs/antora.yml +0 -5
  44. data/docs/modules/ROOT/nav.adoc +0 -5
  45. data/docs/modules/ROOT/pages/cops.adoc +0 -2
  46. data/docs/modules/ROOT/pages/cops_munra.adoc +0 -1026
  47. data/docs/modules/ROOT/pages/index.adoc +0 -11
  48. data/docs/modules/ROOT/pages/installation.adoc +0 -50
  49. data/docs/modules/ROOT/pages/usage.adoc +0 -98
  50. data/docs/usage.md +0 -29
  51. data/package-lock.json +0 -1930
  52. data/package.json +0 -12
  53. data/sig/rubocop/munra.rbs +0 -6
@@ -1,1026 +0,0 @@
1
- ////
2
- Do NOT edit this file by hand directly, as it is automatically generated.
3
-
4
- Please make any necessary changes to the cop documentation within the source files themselves.
5
- ////
6
-
7
- = Munra
8
-
9
- [#munraaddressstateselect]
10
- == Munra/AddressStateSelect
11
-
12
- |===
13
- | Enabled by default | Safe | Supports autocorrection | Version Added | Version Changed
14
-
15
- | Enabled
16
- | Yes
17
- | No
18
- | 0.2.0
19
- | -
20
- |===
21
-
22
- State fields must use a select backed by the configured options call, never free text.
23
-
24
- [#examples-munraaddressstateselect]
25
- === Examples
26
-
27
- [source,ruby]
28
- ----
29
- # bad
30
- <%= form.text_field :address_state %>
31
- ----
32
-
33
- [source,ruby]
34
- ----
35
- # bad
36
- <%= form.select :address_state, [['PE', 'PE']] %>
37
- ----
38
-
39
- [source,ruby]
40
- ----
41
- # good
42
- <%= form.select :address_state, BrazilianState.options_for_select %>
43
- ----
44
-
45
- [#configurable-attributes-munraaddressstateselect]
46
- === Configurable attributes
47
-
48
- |===
49
- | Name | Default value | Configurable values
50
-
51
- | Include
52
- | `+**/*.erb+`, `+**/*.html.erb+`
53
- | Array
54
-
55
- | Attribute
56
- | `address_state`
57
- | String
58
-
59
- | OptionsCall
60
- | `BrazilianState.options_for_select`
61
- | String
62
- |===
63
-
64
- [#munraadminpolicy]
65
- == Munra/AdminPolicy
66
-
67
- |===
68
- | Enabled by default | Safe | Supports autocorrection | Version Added | Version Changed
69
-
70
- | Enabled
71
- | Yes
72
- | No
73
- | 0.2.0
74
- | -
75
- |===
76
-
77
- Ensures admin policies inherit the configured base class and do not
78
- redefine forbidden predicate methods or an unrestricted `resolve`.
79
-
80
- [#examples-munraadminpolicy]
81
- === Examples
82
-
83
- [source,ruby]
84
- ----
85
- # bad
86
- class Admin::FooPolicy
87
- end
88
-
89
- # bad
90
- class Admin::FooPolicy < Admin::ApplicationPolicy
91
- def new?
92
- true
93
- end
94
- end
95
-
96
- # bad
97
- class Admin::FooPolicy < Admin::ApplicationPolicy
98
- def resolve
99
- scope.all
100
- end
101
- end
102
-
103
- # good
104
- class Admin::FooPolicy < Admin::ApplicationPolicy
105
- end
106
- ----
107
-
108
- [#configurable-attributes-munraadminpolicy]
109
- === Configurable attributes
110
-
111
- |===
112
- | Name | Default value | Configurable values
113
-
114
- | Include
115
- | `+app/policies/admin/**/*.rb+`
116
- | Array
117
-
118
- | ExpectedSuperclass
119
- | `Admin::ApplicationPolicy`
120
- | String
121
-
122
- | ForbiddenMethods
123
- | `new?`, `edit?`, `secretary?`, `teacher?`, `same_account?`
124
- | Array
125
-
126
- | AllowedResolveFiles
127
- | `[]`
128
- | Array
129
- |===
130
-
131
- [#munrabuiltinvalidationoptions]
132
- == Munra/BuiltinValidationOptions
133
-
134
- |===
135
- | Enabled by default | Safe | Supports autocorrection | Version Added | Version Changed
136
-
137
- | Enabled
138
- | Yes
139
- | No
140
- | 0.2.0
141
- | -
142
- |===
143
-
144
- Reject custom shorthand options on `validates`.
145
-
146
- Prefer `validates_with` for custom validations instead of
147
- `validates :attr, foo: true`. Allowed keys come from `AllowedKeys` in
148
- `config/default.yml`.
149
-
150
- [#examples-munrabuiltinvalidationoptions]
151
- === Examples
152
-
153
- [source,ruby]
154
- ----
155
- # bad
156
- validates :name, custom: true
157
-
158
- # good
159
- validates :name, presence: true
160
- validates_with CustomValidator
161
- ----
162
-
163
- [#configurable-attributes-munrabuiltinvalidationoptions]
164
- === Configurable attributes
165
-
166
- |===
167
- | Name | Default value | Configurable values
168
-
169
- | AllowedKeys
170
- | `presence`, `format`, `uniqueness`, `length`, `numericality`, `inclusion`, `exclusion`, `comparison`, `acceptance`, `confirmation`, `absence`, `allow_nil`, `allow_blank`, `if`, `unless`, `true`, `strict`, `message`, `scope`, `with`, `conditions`
171
- | Array
172
- |===
173
-
174
- [#munracustomvalidator]
175
- == Munra/CustomValidator
176
-
177
- |===
178
- | Enabled by default | Safe | Supports autocorrection | Version Added | Version Changed
179
-
180
- | Enabled
181
- | Yes
182
- | No
183
- | 0.2.0
184
- | -
185
- |===
186
-
187
- A `*Validator` class must inherit `ActiveModel::Validator` (not
188
- `EachValidator`) and implement `validate`.
189
-
190
- [#examples-munracustomvalidator]
191
- === Examples
192
-
193
- [source,ruby]
194
- ----
195
- # bad
196
- class FooValidator < ActiveModel::EachValidator
197
- end
198
-
199
- # good
200
- class FooValidator < ActiveModel::Validator
201
- def validate(record)
202
- end
203
- end
204
- ----
205
-
206
- [#configurable-attributes-munracustomvalidator]
207
- === Configurable attributes
208
-
209
- |===
210
- | Name | Default value | Configurable values
211
-
212
- | Include
213
- | `+app/validators/**/*.rb+`
214
- | Array
215
-
216
- | RequiredSuperclass
217
- | `ActiveModel::Validator`
218
- | String
219
-
220
- | ForbiddenSuperclassPattern
221
- | `EachValidator`
222
- | String
223
-
224
- | RequiredMethod
225
- | `validate`
226
- | String
227
- |===
228
-
229
- [#munraemailformat]
230
- == Munra/EmailFormat
231
-
232
- |===
233
- | Enabled by default | Safe | Supports autocorrection | Version Added | Version Changed
234
-
235
- | Enabled
236
- | Yes
237
- | No
238
- | 0.2.0
239
- | -
240
- |===
241
-
242
- A model with an `email` attribute must validate it with `EmailFormatValidator`
243
- (unless Devise `:validatable` is enabled).
244
-
245
- Detection is based on `validates :email` (or the configured Attribute) in the
246
- class body. Schema-only / DB columns without a `validates` call are out of scope.
247
-
248
- [#examples-munraemailformat]
249
- === Examples
250
-
251
- [source,ruby]
252
- ----
253
- # bad
254
- class Foo < ApplicationRecord
255
- validates :email, presence: true
256
- end
257
-
258
- # good
259
- class Foo < ApplicationRecord
260
- validates :email, presence: true
261
- validates_with EmailFormatValidator
262
- end
263
-
264
- # good
265
- class User < ApplicationRecord
266
- devise :database_authenticatable, :validatable
267
- end
268
- ----
269
-
270
- [#configurable-attributes-munraemailformat]
271
- === Configurable attributes
272
-
273
- |===
274
- | Name | Default value | Configurable values
275
-
276
- | Attribute
277
- | `email`
278
- | String
279
-
280
- | Validator
281
- | `EmailFormatValidator`
282
- | String
283
-
284
- | DeviseSkipModule
285
- | `validatable`
286
- | String
287
- |===
288
-
289
- [#munraflashsuccesslocalename]
290
- == Munra/FlashSuccessLocaleName
291
-
292
- |===
293
- | Enabled by default | Safe | Supports autocorrection | Version Added | Version Changed
294
-
295
- | Enabled
296
- | Yes
297
- | No
298
- | 0.2.0
299
- | -
300
- |===
301
-
302
- Controller flash success locale strings must include the configured interpolation.
303
-
304
- Uses a line-oriented YAML scan. Folded/literal multiline scalars, anchors, and
305
- other complex YAML shapes may not be detected; keep success entries as plain
306
- quoted scalars when possible.
307
-
308
- [#examples-munraflashsuccesslocalename]
309
- === Examples
310
-
311
- [source,ruby]
312
- ----
313
- # bad
314
- # config/locales/pt-BR.yml
315
- pt-BR:
316
- controllers:
317
- employees:
318
- create:
319
- success: "Funcionário criado com sucesso."
320
- ----
321
-
322
- [source,ruby]
323
- ----
324
- # good
325
- # config/locales/pt-BR.yml
326
- pt-BR:
327
- controllers:
328
- employees:
329
- create:
330
- success: "Funcionário %{name} criado com sucesso."
331
- ----
332
-
333
- [#configurable-attributes-munraflashsuccesslocalename]
334
- === Configurable attributes
335
-
336
- |===
337
- | Name | Default value | Configurable values
338
-
339
- | Include
340
- | `+config/locales/**/*.yml+`
341
- | Array
342
-
343
- | RequiredInterpolation
344
- | `%{name}`
345
- | String
346
-
347
- | SectionKey
348
- | `controllers`
349
- | String
350
-
351
- | EntryKey
352
- | `success`
353
- | String
354
- |===
355
-
356
- [#munraflashsuccessname]
357
- == Munra/FlashSuccessName
358
-
359
- |===
360
- | Enabled by default | Safe | Supports autocorrection | Version Added | Version Changed
361
-
362
- | Enabled
363
- | Yes
364
- | No
365
- | 0.2.0
366
- | -
367
- |===
368
-
369
- A success flash `t` / `I18n.t` call must pass the configured interpolation key.
370
-
371
- Only `notice:` keyword pairs are in scope (for example
372
- `redirect_to path, notice: t(...)`). Assignments such as
373
- `flash[:notice] = t(...)`, `flash.now[:notice]`, and `alert:` are out of scope.
374
-
375
- [#examples-munraflashsuccessname]
376
- === Examples
377
-
378
- [source,ruby]
379
- ----
380
- # bad
381
- redirect_to root_path, notice: t('messages.success')
382
- ----
383
-
384
- [source,ruby]
385
- ----
386
- # good
387
- redirect_to root_path, notice: t('messages.success', name: record.name)
388
- ----
389
-
390
- [#configurable-attributes-munraflashsuccessname]
391
- === Configurable attributes
392
-
393
- |===
394
- | Name | Default value | Configurable values
395
-
396
- | RequiredInterpolationKey
397
- | `name`
398
- | String
399
-
400
- | LocaleKeyFragment
401
- | `success`
402
- | String
403
- |===
404
-
405
- [#munrafullerrormessages]
406
- == Munra/FullErrorMessages
407
-
408
- |===
409
- | Enabled by default | Safe | Supports autocorrection | Version Added | Version Changed
410
-
411
- | Enabled
412
- | Yes
413
- | Always
414
- | 0.2.0
415
- | -
416
- |===
417
-
418
- Assert the full error message set with `eq`, not `include`.
419
-
420
- Detects `expect(...).to include(...)` when the subject is an `errors`
421
- accessor (`errors`, `errors[:attr]`, `errors.messages`, `errors.full_messages`).
422
-
423
- [#examples-munrafullerrormessages]
424
- === Examples
425
-
426
- [source,ruby]
427
- ----
428
- # bad
429
- expect(record.errors[:name]).to include('is invalid')
430
-
431
- # good
432
- expect(record.errors[:name]).to eq(['is invalid'])
433
- ----
434
-
435
- [#configurable-attributes-munrafullerrormessages]
436
- === Configurable attributes
437
-
438
- |===
439
- | Name | Default value | Configurable values
440
-
441
- | Include
442
- | `+**/spec/**/*.rb+`
443
- | Array
444
- |===
445
-
446
- [#munraletlayout]
447
- == Munra/LetLayout
448
-
449
- |===
450
- | Enabled by default | Safe | Supports autocorrection | Version Added | Version Changed
451
-
452
- | Enabled
453
- | Yes
454
- | No
455
- | 0.2.0
456
- | -
457
- |===
458
-
459
- Enforces blank lines and ordering for single-line versus multi-line `let` blocks.
460
-
461
- Single-line `let` declarations stay together without blank lines between them,
462
- and they come before multi-line `let` blocks. A multi-line `let` has a blank
463
- line before it (unless the previous line is empty or opens the surrounding
464
- block) and a blank line after it (unless the next line is blank or closes the
465
- surrounding block with `end`).
466
-
467
- [#examples-munraletlayout]
468
- === Examples
469
-
470
- [#single-line-lets-stay-together-munraletlayout]
471
- ==== Single-line lets stay together
472
-
473
- [source,ruby]
474
- ----
475
- # bad
476
- RSpec.describe Foo do
477
- let(:name) { 'Ada' }
478
-
479
- let(:role) { 'admin' }
480
- end
481
-
482
- # good
483
- RSpec.describe Foo do
484
- let(:name) { 'Ada' }
485
- let(:role) { 'admin' }
486
- end
487
- ----
488
-
489
- [#multi-line-lets-are-padded-munraletlayout]
490
- ==== Multi-line lets are padded
491
-
492
- [source,ruby]
493
- ----
494
- # bad
495
- RSpec.describe Foo do
496
- let(:name) { 'Ada' }
497
- let(:profile) do
498
- { role: 'admin' }
499
- end
500
- end
501
-
502
- # good
503
- RSpec.describe Foo do
504
- let(:name) { 'Ada' }
505
-
506
- let(:profile) do
507
- { role: 'admin' }
508
- end
509
- end
510
- ----
511
-
512
- [#single-line-lets-come-before-multi-line-lets-munraletlayout]
513
- ==== Single-line lets come before multi-line lets
514
-
515
- [source,ruby]
516
- ----
517
- # bad
518
- RSpec.describe Foo do
519
- let(:profile) do
520
- { role: 'admin' }
521
- end
522
-
523
- let(:name) { 'Ada' }
524
- end
525
-
526
- # good
527
- RSpec.describe Foo do
528
- let(:name) { 'Ada' }
529
-
530
- let(:profile) do
531
- { role: 'admin' }
532
- end
533
- end
534
- ----
535
-
536
- [#configurable-attributes-munraletlayout]
537
- === Configurable attributes
538
-
539
- |===
540
- | Name | Default value | Configurable values
541
-
542
- | Include
543
- | `+**/spec/**/*.rb+`
544
- | Array
545
- |===
546
-
547
- [#munranamedsubjectlayout]
548
- == Munra/NamedSubjectLayout
549
-
550
- |===
551
- | Enabled by default | Safe | Supports autocorrection | Version Added | Version Changed
552
-
553
- | Enabled
554
- | Yes
555
- | Always
556
- | 0.2.0
557
- | -
558
- |===
559
-
560
- Named `subject` must be the first declaration in its example group;
561
- anonymous `subject` is not allowed; do not repeat the subject body
562
- inline inside `expect`.
563
-
564
- [#examples-munranamedsubjectlayout]
565
- === Examples
566
-
567
- [#subject-must-be-named-and-first-munranamedsubjectlayout]
568
- ==== Subject must be named and first
569
-
570
- [source,ruby]
571
- ----
572
- # bad
573
- RSpec.describe FooService do
574
- let(:name) { 'x' }
575
- subject(:result) { described_class.call(name:) }
576
- end
577
-
578
- # bad
579
- RSpec.describe FooService do
580
- subject { described_class.call }
581
- end
582
-
583
- # good
584
- RSpec.describe FooService do
585
- subject(:result) { described_class.call(name: 'x') }
586
-
587
- let(:name) { 'x' }
588
- end
589
- ----
590
-
591
- [#do-not-repeat-the-subject-body-in-expect-munranamedsubjectlayout]
592
- ==== Do not repeat the subject body in expect
593
-
594
- [source,ruby]
595
- ----
596
- # bad
597
- RSpec.describe FooService do
598
- subject(:result) { described_class.call(name: 'x') }
599
-
600
- it 'works' do
601
- expect(described_class.call(name: 'x')).to be(true)
602
- end
603
- end
604
-
605
- # good
606
- RSpec.describe FooService do
607
- subject(:result) { described_class.call(name: 'x') }
608
-
609
- it 'works' do
610
- expect(result).to be(true)
611
- end
612
- end
613
- ----
614
-
615
- [#configurable-attributes-munranamedsubjectlayout]
616
- === Configurable attributes
617
-
618
- |===
619
- | Name | Default value | Configurable values
620
-
621
- | Include
622
- | `+**/spec/**/*.rb+`
623
- | Array
624
-
625
- | HttpMethods
626
- | `get`, `post`, `put`, `patch`, `delete`
627
- | Array
628
- |===
629
-
630
- [#munranohumanattributename]
631
- == Munra/NoHumanAttributeName
632
-
633
- |===
634
- | Enabled by default | Safe | Supports autocorrection | Version Added | Version Changed
635
-
636
- | Enabled
637
- | Yes
638
- | No
639
- | 0.2.0
640
- | -
641
- |===
642
-
643
- Prefer `I18n.t('activerecord.attributes...')` over `human_attribute_name`.
644
-
645
- Calls inside `def self.human_attribute_name` or instance
646
- `def human_attribute_name` are allowed so wrappers can call `super`.
647
-
648
- [#examples-munranohumanattributename]
649
- === Examples
650
-
651
- [source,ruby]
652
- ----
653
- # bad
654
- Student.human_attribute_name(:name)
655
-
656
- # good
657
- I18n.t('activerecord.attributes.student.name')
658
- ----
659
-
660
- [#munranoinlinevalidation]
661
- == Munra/NoInlineValidation
662
-
663
- |===
664
- | Enabled by default | Safe | Supports autocorrection | Version Added | Version Changed
665
-
666
- | Enabled
667
- | Yes
668
- | No
669
- | 0.2.0
670
- | -
671
- |===
672
-
673
- Prefer `validates_with` over an inline `validate`.
674
-
675
- [#examples-munranoinlinevalidation]
676
- === Examples
677
-
678
- [source,ruby]
679
- ----
680
- # bad
681
- validate :check_foo
682
-
683
- # good
684
- validates_with FooValidator
685
- ----
686
-
687
- [#munranoleadingdot]
688
- == Munra/NoLeadingDot
689
-
690
- |===
691
- | Enabled by default | Safe | Supports autocorrection | Version Added | Version Changed
692
-
693
- | Enabled
694
- | Yes
695
- | Always
696
- | 0.2.0
697
- | -
698
- |===
699
-
700
- Flags a method chain broken with a leading dot.
701
-
702
- [#examples-munranoleadingdot]
703
- === Examples
704
-
705
- [source,ruby]
706
- ----
707
- # bad
708
- user
709
- .name
710
-
711
- # good
712
- user.
713
- name
714
- ----
715
-
716
- [#munranosharedexamples]
717
- == Munra/NoSharedExamples
718
-
719
- |===
720
- | Enabled by default | Safe | Supports autocorrection | Version Added | Version Changed
721
-
722
- | Enabled
723
- | Yes
724
- | No
725
- | 0.2.0
726
- | -
727
- |===
728
-
729
- Disallows shared examples and shared contexts.
730
-
731
- Prefer inlined examples over `shared_examples`, `shared_context`, and the
732
- related inclusion helpers.
733
-
734
- [#examples-munranosharedexamples]
735
- === Examples
736
-
737
- [source,ruby]
738
- ----
739
- # bad
740
- shared_examples 'a model' do
741
- end
742
-
743
- # bad
744
- RSpec.shared_examples 'a model' do
745
- end
746
-
747
- # bad
748
- it_behaves_like 'a model'
749
-
750
- # good
751
- it 'validates presence' do
752
- expect(record).to validate_presence_of(:name)
753
- end
754
- ----
755
-
756
- [#configurable-attributes-munranosharedexamples]
757
- === Configurable attributes
758
-
759
- |===
760
- | Name | Default value | Configurable values
761
-
762
- | Include
763
- | `+**/spec/**/*.rb+`
764
- | Array
765
-
766
- | ForbiddenMethods
767
- | `shared_examples`, `shared_examples_for`, `shared_context`, `it_behaves_like`, `it_should_behave_like`, `include_examples`, `include_context`
768
- | Array
769
- |===
770
-
771
- [#munranospecmethod]
772
- == Munra/NoSpecMethod
773
-
774
- |===
775
- | Enabled by default | Safe | Supports autocorrection | Version Added | Version Changed
776
-
777
- | Enabled
778
- | Yes
779
- | No
780
- | 0.2.0
781
- | -
782
- |===
783
-
784
- Disallows `def` in a spec.
785
-
786
- Use `let` or a helper instead of defining a method in the spec file.
787
-
788
- [#examples-munranospecmethod]
789
- === Examples
790
-
791
- [source,ruby]
792
- ----
793
- # bad
794
- RSpec.describe Foo do
795
- def helper
796
- end
797
- end
798
-
799
- # bad
800
- RSpec.describe Foo do
801
- def self.helper
802
- end
803
- end
804
-
805
- # good
806
- RSpec.describe Foo do
807
- let(:user) { build_user }
808
- end
809
- ----
810
-
811
- [#configurable-attributes-munranospecmethod]
812
- === Configurable attributes
813
-
814
- |===
815
- | Name | Default value | Configurable values
816
-
817
- | Include
818
- | `+**/spec/**/*.rb+`
819
- | Array
820
- |===
821
-
822
- [#munranotransactionexit]
823
- == Munra/NoTransactionExit
824
-
825
- |===
826
- | Enabled by default | Safe | Supports autocorrection | Version Added | Version Changed
827
-
828
- | Enabled
829
- | Yes
830
- | No
831
- | 0.2.0
832
- | -
833
- |===
834
-
835
- Disallows `return` and `next` inside a transaction block.
836
-
837
- Abort the transaction with `raise ActiveRecord::Rollback` instead.
838
- `break` and `throw` are out of scope for this cop.
839
-
840
- [#examples-munranotransactionexit]
841
- === Examples
842
-
843
- [source,ruby]
844
- ----
845
- # bad
846
- ApplicationRecord.transaction do
847
- return false
848
- end
849
-
850
- # bad
851
- record.with_lock do
852
- next if skip?
853
- end
854
-
855
- # good
856
- ApplicationRecord.transaction do
857
- raise ActiveRecord::Rollback
858
- end
859
-
860
- # good
861
- record.with_lock do
862
- raise ActiveRecord::Rollback if skip?
863
- end
864
- ----
865
-
866
- [#configurable-attributes-munranotransactionexit]
867
- === Configurable attributes
868
-
869
- |===
870
- | Name | Default value | Configurable values
871
-
872
- | TransactionMethods
873
- | `transaction`, `with_lock`
874
- | Array
875
- |===
876
-
877
- [#munraserviceobject]
878
- == Munra/ServiceObject
879
-
880
- |===
881
- | Enabled by default | Safe | Supports autocorrection | Version Added | Version Changed
882
-
883
- | Enabled
884
- | Yes
885
- | No
886
- | 0.2.0
887
- | -
888
- |===
889
-
890
- Ensures `*Service` classes inherit from the configured base, do not redefine
891
- `self.call`, and keep instance `call` private when required.
892
-
893
- [#examples-munraserviceobject]
894
- === Examples
895
-
896
- [source,ruby]
897
- ----
898
- # bad
899
- class FooService
900
- end
901
-
902
- # bad
903
- class FooService < ApplicationService
904
- def self.call(*)
905
- new.call
906
- end
907
-
908
- private
909
-
910
- def call; end
911
- end
912
-
913
- # bad
914
- class FooService < ApplicationService
915
- def call; end
916
- end
917
-
918
- # good
919
- class FooService < ApplicationService
920
- private
921
-
922
- def call; end
923
- end
924
- ----
925
-
926
- [#configurable-attributes-munraserviceobject]
927
- === Configurable attributes
928
-
929
- |===
930
- | Name | Default value | Configurable values
931
-
932
- | ExpectedSuffix
933
- | `Service`
934
- | String
935
-
936
- | ExpectedSuperclass
937
- | `ApplicationService`
938
- | String
939
-
940
- | RequirePrivateCall
941
- | `true`
942
- | Boolean
943
- |===
944
-
945
- [#munrasuccesserrorsiblings]
946
- == Munra/SuccessErrorSiblings
947
-
948
- |===
949
- | Enabled by default | Safe | Supports autocorrection | Version Added | Version Changed
950
-
951
- | Enabled
952
- | Yes
953
- | No
954
- | 0.2.0
955
- | -
956
- |===
957
-
958
- When a group has a `when success` or `when error` context, sibling
959
- `context` blocks must use only those configured names.
960
-
961
- Non-literal context descriptions are ignored (neither triggers nor
962
- offenses).
963
-
964
- [#examples-munrasuccesserrorsiblings]
965
- === Examples
966
-
967
- [source,ruby]
968
- ----
969
- # bad
970
- RSpec.describe FooService do
971
- describe '.call' do
972
- context 'when success' do
973
- it 'works' do
974
- end
975
- end
976
-
977
- context 'when validation fails' do
978
- it 'fails' do
979
- end
980
- end
981
- end
982
- end
983
-
984
- # good
985
- RSpec.describe FooService do
986
- describe '.call' do
987
- context 'when success' do
988
- it 'works' do
989
- end
990
- end
991
-
992
- context 'when error' do
993
- it 'fails' do
994
- end
995
- end
996
- end
997
- end
998
-
999
- # good
1000
- RSpec.describe FooService do
1001
- context 'when logged in' do
1002
- it 'works' do
1003
- end
1004
- end
1005
-
1006
- context 'when logged out' do
1007
- it 'works' do
1008
- end
1009
- end
1010
- end
1011
- ----
1012
-
1013
- [#configurable-attributes-munrasuccesserrorsiblings]
1014
- === Configurable attributes
1015
-
1016
- |===
1017
- | Name | Default value | Configurable values
1018
-
1019
- | Include
1020
- | `+**/spec/**/*.rb+`
1021
- | Array
1022
-
1023
- | AllowedContextNames
1024
- | `when success`, `when error`
1025
- | Array
1026
- |===