@@ -4605,6 +4605,62 @@ end
4605
4605
| Boolean
4606
4606
|===
4607
4607
4608
+ == Lint/UnexpectedBlockArity
4609
+
4610
+ |===
4611
+ | Enabled by default | Safe | Supports autocorrection | VersionAdded | VersionChanged
4612
+
4613
+ | Pending
4614
+ | No
4615
+ | No
4616
+ | 1.5
4617
+ | -
4618
+ |===
4619
+
4620
+ This cop checks for a block that is known to need more positional
4621
+ block arguments than are given (by default this is configured for
4622
+ `Enumerable` methods needing 2 arguments). Optional arguments are allowed,
4623
+ although they don't generally make sense as the default value will
4624
+ be used. Blocks that have no receiver, or take splatted arguments
4625
+ (ie. `*args`) are always accepted.
4626
+
4627
+ Keyword arguments (including `**kwargs`) do not get counted towards
4628
+ this, as they are not used by the methods in question.
4629
+
4630
+ NOTE: This cop matches for method names only and hence cannot tell apart
4631
+ methods with same name in different classes.
4632
+
4633
+ Method names and their expected arity can be configured like this:
4634
+
4635
+ Methods:
4636
+ inject: 2
4637
+ reduce: 2
4638
+
4639
+ === Examples
4640
+
4641
+ [source,ruby]
4642
+ ----
4643
+ # bad
4644
+ values.reduce {}
4645
+ values.min { |a| a }
4646
+ values.sort { |a; b| a + b }
4647
+
4648
+ # good
4649
+ values.reduce { |memo, obj| memo << obj }
4650
+ values.min { |a, b| a <=> b }
4651
+ values.sort { |*x| x[0] <=> x[1] }
4652
+ ----
4653
+
4654
+ === Configurable attributes
4655
+
4656
+ |===
4657
+ | Name | Default value | Configurable values
4658
+
4659
+ | Methods
4660
+ | `{"chunk_while"=>2, "each_with_index"=>2, "each_with_object"=>2, "inject"=>2, "max"=>2, "min"=>2, "minmax"=>2, "reduce"=>2, "slice_when"=>2, "sort"=>2}`
4661
+ |
4662
+ |===
4663
+
4608
4664
== Lint/UnifiedInteger
4609
4665
4610
4666
|===
@@ -4645,7 +4701,7 @@ This cop checks for using Fixnum or Bignum constant.
4645
4701
| Yes
4646
4702
| No
4647
4703
| 1.1
4648
- | -
4704
+ | 1.5
4649
4705
|===
4650
4706
4651
4707
Looks for `reduce` or `inject` blocks where the value returned (implicitly or
@@ -4657,8 +4713,7 @@ block will just return a transformation of the last element value, and
4657
4713
could be rewritten as such without a loop.
4658
4714
4659
4715
Also catches instances where an index of the accumulator is returned, as
4660
- this may change the type of object being retained. As well, detects when
4661
- fewer than 2 block arguments are specified.
4716
+ this may change the type of object being retained.
4662
4717
4663
4718
NOTE: For the purpose of reducing false positives, this cop only flags
4664
4719
returns in `reduce` blocks where the element is the only variable in
0 commit comments