m2m_keygen 0.4.9 → 0.5.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 (174) hide show
  1. checksums.yaml +4 -4
  2. data/.overcommit.yml +4 -7
  3. data/.rubocop.yml +19 -16
  4. data/.ruby-version +1 -1
  5. data/.streerc +1 -0
  6. data/.tool-versions +1 -1
  7. data/CHANGELOG.md +60 -1
  8. data/Gemfile +2 -2
  9. data/Gemfile.lock +135 -158
  10. data/README.md +64 -78
  11. data/docs/MIGRATING.md +69 -0
  12. data/docs/SPEC.md +245 -0
  13. data/examples/nonce_store/postgres.rb +40 -0
  14. data/examples/nonce_store/redis.rb +23 -0
  15. data/gemfiles/rack_2.gemfile +5 -0
  16. data/gemfiles/rack_3.gemfile +5 -0
  17. data/lib/m2m_keygen/canonicalizer.rb +57 -0
  18. data/lib/m2m_keygen/nonce_store/disabled.rb +19 -0
  19. data/lib/m2m_keygen/nonce_store/memory.rb +64 -0
  20. data/lib/m2m_keygen/nonce_store.rb +18 -0
  21. data/lib/m2m_keygen/rack_validator.rb +72 -19
  22. data/lib/m2m_keygen/request_signer/signed_request.rb +10 -0
  23. data/lib/m2m_keygen/request_signer.rb +118 -0
  24. data/lib/m2m_keygen/signature.rb +41 -39
  25. data/lib/m2m_keygen/types/params_type.rb +6 -17
  26. data/lib/m2m_keygen/version.rb +1 -1
  27. data/lib/m2m_keygen.rb +6 -0
  28. data/m2m_keygen.gemspec +12 -14
  29. data/sorbet/config +1 -0
  30. data/sorbet/rbi/gems/.gitattributes +1 -0
  31. data/sorbet/rbi/gems/{ast@2.4.2.rbi → ast@2.4.3.rbi} +45 -79
  32. data/sorbet/rbi/gems/{benchmark@0.2.0.rbi → benchmark@0.5.0.rbi} +91 -58
  33. data/sorbet/rbi/gems/bundler-audit@0.9.3.rbi +397 -0
  34. data/sorbet/rbi/gems/byebug@13.0.0.rbi +3651 -0
  35. data/sorbet/rbi/gems/childprocess@5.1.0.rbi +336 -0
  36. data/sorbet/rbi/gems/concurrent-ruby@1.3.7.rbi +384 -0
  37. data/sorbet/rbi/gems/{diff-lcs@1.5.0.rbi → diff-lcs@1.6.2.rbi} +189 -199
  38. data/sorbet/rbi/gems/{docile@1.4.0.rbi → docile@1.4.1.rbi} +147 -147
  39. data/sorbet/rbi/gems/dotenv@3.2.0.rbi +267 -0
  40. data/sorbet/rbi/gems/erubi@1.13.1.rbi +155 -0
  41. data/sorbet/rbi/gems/{faker@2.22.0.rbi → faker@3.8.0.rbi} +8468 -3829
  42. data/sorbet/rbi/gems/{ffi@1.15.5.rbi → ffi@1.17.4.rbi} +1 -0
  43. data/sorbet/rbi/gems/{formatador@1.1.0.rbi → formatador@1.2.3.rbi} +1 -0
  44. data/sorbet/rbi/gems/{guard@2.18.0.rbi → guard@2.20.1.rbi} +1 -0
  45. data/sorbet/rbi/gems/{i18n@1.12.0.rbi → i18n@1.15.2.rbi} +687 -827
  46. data/sorbet/rbi/gems/io-console@0.8.2.rbi +9 -0
  47. data/sorbet/rbi/gems/{json@2.6.2.rbi → json@2.20.0.rbi} +994 -252
  48. data/sorbet/rbi/gems/language_server-protocol@3.17.0.5.rbi +9 -0
  49. data/sorbet/rbi/gems/lint_roller@1.1.0.rbi +189 -0
  50. data/sorbet/rbi/gems/listen@3.10.0.rbi +9 -0
  51. data/sorbet/rbi/gems/logger@1.7.0.rbi +896 -0
  52. data/sorbet/rbi/gems/{lumberjack@1.2.8.rbi → lumberjack@1.4.2.rbi} +1 -0
  53. data/sorbet/rbi/gems/{method_source@1.0.0.rbi → method_source@1.1.0.rbi} +111 -90
  54. data/sorbet/rbi/gems/{overcommit@0.59.1.rbi → overcommit@0.71.0.rbi} +503 -647
  55. data/sorbet/rbi/gems/parallel@2.1.0.rbi +321 -0
  56. data/sorbet/rbi/gems/parser@3.3.11.1.rbi +5229 -0
  57. data/sorbet/rbi/gems/prettier_print@1.2.1.rbi +878 -0
  58. data/sorbet/rbi/gems/prism@1.9.0.rbi +42224 -0
  59. data/sorbet/rbi/gems/pry-byebug@3.12.0.rbi +481 -0
  60. data/sorbet/rbi/gems/{pry@0.14.1.rbi → pry@0.16.0.rbi} +2567 -3550
  61. data/sorbet/rbi/gems/{racc@1.6.0.rbi → racc@1.8.1.rbi} +54 -40
  62. data/sorbet/rbi/gems/rack@3.2.6.rbi +4653 -0
  63. data/sorbet/rbi/gems/{rake@13.0.6.rbi → rake@13.4.2.rbi} +963 -732
  64. data/sorbet/rbi/gems/{rb-inotify@0.10.1.rbi → rb-inotify@0.11.1.rbi} +1 -0
  65. data/sorbet/rbi/gems/rbi@0.3.14.rbi +5519 -0
  66. data/sorbet/rbi/gems/rbs@4.0.3.rbi +6908 -0
  67. data/sorbet/rbi/gems/regexp_parser@2.12.0.rbi +3398 -0
  68. data/sorbet/rbi/gems/reline@0.6.3.rbi +2446 -0
  69. data/sorbet/rbi/gems/require-hooks@0.4.0.rbi +152 -0
  70. data/sorbet/rbi/gems/{rexml@3.2.5.rbi → rexml@3.4.4.rbi} +1085 -894
  71. data/sorbet/rbi/gems/rspec-core@3.13.6.rbi +9475 -0
  72. data/sorbet/rbi/gems/rspec-expectations@3.13.5.rbi +6108 -0
  73. data/sorbet/rbi/gems/rspec-mocks@3.13.8.rbi +4787 -0
  74. data/sorbet/rbi/gems/rspec-support@3.13.7.rbi +1274 -0
  75. data/sorbet/rbi/gems/rspec@3.13.2.rbi +15 -0
  76. data/sorbet/rbi/gems/rspec_in_context@1.2.2.rbi +294 -0
  77. data/sorbet/rbi/gems/rubocop-ast@1.49.1.rbi +7140 -0
  78. data/sorbet/rbi/gems/rubocop-faker@1.3.0.rbi +88 -0
  79. data/sorbet/rbi/gems/rubocop-performance@1.26.1.rbi +3403 -0
  80. data/sorbet/rbi/gems/rubocop-sorbet@0.12.0.rbi +2448 -0
  81. data/sorbet/rbi/gems/rubocop@1.88.1.rbi +63103 -0
  82. data/sorbet/rbi/gems/ruby-lsp@0.26.9.rbi +28 -0
  83. data/sorbet/rbi/gems/ruby-progressbar@1.13.0.rbi +988 -0
  84. data/sorbet/rbi/gems/rubydex@0.2.7.rbi +836 -0
  85. data/sorbet/rbi/gems/simplecov-html@0.13.2.rbi +90 -0
  86. data/sorbet/rbi/gems/{simplecov@0.21.2.rbi → simplecov@0.22.0.rbi} +438 -578
  87. data/sorbet/rbi/gems/spoom@1.8.2.rbi +6691 -0
  88. data/sorbet/rbi/gems/syntax_tree@6.3.0.rbi +22090 -0
  89. data/sorbet/rbi/gems/tapioca@0.19.2.rbi +3597 -0
  90. data/sorbet/rbi/gems/{thor@1.2.1.rbi → thor@1.5.0.rbi} +1085 -1171
  91. data/sorbet/rbi/gems/tsort@0.2.0.rbi +389 -0
  92. data/sorbet/rbi/gems/unicode-display_width@3.2.0.rbi +130 -0
  93. data/sorbet/rbi/gems/unicode-emoji@4.2.0.rbi +332 -0
  94. data/sorbet/rbi/gems/{yard-sorbet@0.7.0.rbi → yard-sorbet@0.9.0.rbi} +142 -99
  95. data/sorbet/rbi/gems/{yard@0.9.28.rbi → yard@0.9.44.rbi} +5350 -6316
  96. data/sorbet/rbi/gems/zeitwerk@2.8.2.rbi +1178 -0
  97. metadata +105 -111
  98. data/.prettierrc.js +0 -4
  99. data/docs/M2mKeygen/Error.html +0 -135
  100. data/docs/M2mKeygen/ParamsEncoder.html +0 -321
  101. data/docs/M2mKeygen/RackValidator.html +0 -533
  102. data/docs/M2mKeygen/Signature.html +0 -680
  103. data/docs/M2mKeygen/Types.html +0 -147
  104. data/docs/M2mKeygen.html +0 -157
  105. data/docs/_index.html +0 -182
  106. data/docs/class_list.html +0 -51
  107. data/docs/css/common.css +0 -1
  108. data/docs/css/full_list.css +0 -58
  109. data/docs/css/style.css +0 -497
  110. data/docs/file.README.html +0 -230
  111. data/docs/file_list.html +0 -56
  112. data/docs/frames.html +0 -17
  113. data/docs/index.html +0 -230
  114. data/docs/js/app.js +0 -314
  115. data/docs/js/full_list.js +0 -216
  116. data/docs/js/jquery.js +0 -4
  117. data/docs/method_list.html +0 -139
  118. data/docs/top-level-namespace.html +0 -110
  119. data/lib/m2m_keygen/params_encoder.rb +0 -56
  120. data/package.json +0 -12
  121. data/sig/m2m_keygen.rbs +0 -4
  122. data/sorbet/rbi/gems/activesupport@7.0.3.1.rbi +0 -18608
  123. data/sorbet/rbi/gems/backport@1.2.0.rbi +0 -522
  124. data/sorbet/rbi/gems/bundler-audit@0.9.1.rbi +0 -308
  125. data/sorbet/rbi/gems/byebug@11.1.3.rbi +0 -3603
  126. data/sorbet/rbi/gems/childprocess@4.1.0.rbi +0 -401
  127. data/sorbet/rbi/gems/concurrent-ruby@1.1.10.rbi +0 -11581
  128. data/sorbet/rbi/gems/dotenv@2.8.1.rbi +0 -234
  129. data/sorbet/rbi/gems/e2mmap@0.1.0.rbi +0 -8
  130. data/sorbet/rbi/gems/haml@5.2.2.rbi +0 -3190
  131. data/sorbet/rbi/gems/jaro_winkler@1.5.4.rbi +0 -19
  132. data/sorbet/rbi/gems/kramdown-parser-gfm@1.1.0.rbi +0 -133
  133. data/sorbet/rbi/gems/kramdown@2.4.0.rbi +0 -3261
  134. data/sorbet/rbi/gems/listen@3.7.1.rbi +0 -1181
  135. data/sorbet/rbi/gems/minitest@5.16.3.rbi +0 -1459
  136. data/sorbet/rbi/gems/nokogiri@1.13.8.rbi +0 -6514
  137. data/sorbet/rbi/gems/parallel@1.22.1.rbi +0 -277
  138. data/sorbet/rbi/gems/parser@3.1.2.1.rbi +0 -6826
  139. data/sorbet/rbi/gems/prettier@3.2.0.rbi +0 -22
  140. data/sorbet/rbi/gems/prettier_print@0.1.0.rbi +0 -8
  141. data/sorbet/rbi/gems/pry-byebug@3.10.1.rbi +0 -1222
  142. data/sorbet/rbi/gems/rack@2.2.4.rbi +0 -5630
  143. data/sorbet/rbi/gems/rbi@0.0.15.rbi +0 -3007
  144. data/sorbet/rbi/gems/rbs@2.6.0.rbi +0 -8
  145. data/sorbet/rbi/gems/regexp_parser@2.5.0.rbi +0 -3366
  146. data/sorbet/rbi/gems/reverse_markdown@2.1.1.rbi +0 -389
  147. data/sorbet/rbi/gems/rspec-core@3.11.0.rbi +0 -10786
  148. data/sorbet/rbi/gems/rspec-expectations@3.11.0.rbi +0 -8170
  149. data/sorbet/rbi/gems/rspec-mocks@3.11.1.rbi +0 -5385
  150. data/sorbet/rbi/gems/rspec-support@3.11.0.rbi +0 -1746
  151. data/sorbet/rbi/gems/rspec@3.11.0.rbi +0 -187
  152. data/sorbet/rbi/gems/rspec_in_context@1.1.0.3.rbi +0 -1113
  153. data/sorbet/rbi/gems/rubocop-ast@1.21.0.rbi +0 -7044
  154. data/sorbet/rbi/gems/rubocop-faker@1.1.0.rbi +0 -106
  155. data/sorbet/rbi/gems/rubocop-performance@1.14.3.rbi +0 -2982
  156. data/sorbet/rbi/gems/rubocop-sorbet@0.6.11.rbi +0 -990
  157. data/sorbet/rbi/gems/rubocop@1.35.1.rbi +0 -52002
  158. data/sorbet/rbi/gems/ruby-progressbar@1.11.0.rbi +0 -1239
  159. data/sorbet/rbi/gems/simplecov-html@0.12.3.rbi +0 -219
  160. data/sorbet/rbi/gems/solargraph@0.46.0.rbi +0 -9075
  161. data/sorbet/rbi/gems/spoom@1.1.12.rbi +0 -2369
  162. data/sorbet/rbi/gems/syntax_tree-haml@1.3.1.rbi +0 -8
  163. data/sorbet/rbi/gems/syntax_tree-rbs@0.5.0.rbi +0 -8
  164. data/sorbet/rbi/gems/syntax_tree@3.5.0.rbi +0 -8
  165. data/sorbet/rbi/gems/tapioca@0.9.4.rbi +0 -2946
  166. data/sorbet/rbi/gems/temple@0.8.2.rbi +0 -1712
  167. data/sorbet/rbi/gems/tilt@2.0.11.rbi +0 -742
  168. data/sorbet/rbi/gems/tzinfo@2.0.5.rbi +0 -5914
  169. data/sorbet/rbi/gems/unicode-display_width@2.2.0.rbi +0 -48
  170. data/sorbet/rbi/gems/unparser@0.6.5.rbi +0 -4529
  171. data/sorbet/rbi/gems/webrick@1.7.0.rbi +0 -2553
  172. data/sorbet/rbi/gems/zeitwerk@2.6.0.rbi +0 -867
  173. data/sorbet/rbi/manual.rbi +0 -7
  174. data/yarn.lock +0 -20
@@ -0,0 +1,3403 @@
1
+ # typed: true
2
+
3
+ # DO NOT EDIT MANUALLY
4
+ # This is an autogenerated file for types exported from the `rubocop-performance` gem.
5
+ # Please instead update this file by running `bin/tapioca gem rubocop-performance`.
6
+
7
+
8
+ # pkg:gem/rubocop-performance#lib/rubocop/performance.rb:3
9
+ module RuboCop; end
10
+
11
+ # pkg:gem/rubocop-performance#lib/rubocop/cop/mixin/regexp_metacharacter.rb:4
12
+ module RuboCop::Cop; end
13
+
14
+ module RuboCop::Cop::Lint; end
15
+ class RuboCop::Cop::Lint::UnusedMethodArgument < ::RuboCop::Cop::Base; end
16
+ module RuboCop::Cop::Naming; end
17
+ class RuboCop::Cop::Naming::BlockForwarding < ::RuboCop::Cop::Base; end
18
+
19
+ # pkg:gem/rubocop-performance#lib/rubocop/cop/performance/ancestors_include.rb:5
20
+ module RuboCop::Cop::Performance; end
21
+
22
+ # Identifies usages of `ancestors.include?` and change them to use `<=` instead.
23
+ #
24
+ # @safety
25
+ # This cop is unsafe because it can't tell whether the receiver is a class or an object.
26
+ # e.g. the false positive was for `Nokogiri::XML::Node#ancestors`.
27
+ #
28
+ # @example
29
+ # # bad
30
+ # A.ancestors.include?(B)
31
+ #
32
+ # # good
33
+ # A <= B
34
+ #
35
+ # pkg:gem/rubocop-performance#lib/rubocop/cop/performance/ancestors_include.rb:19
36
+ class RuboCop::Cop::Performance::AncestorsInclude < ::RuboCop::Cop::Base
37
+ include ::RuboCop::Cop::RangeHelp
38
+ extend ::RuboCop::Cop::AutoCorrector
39
+
40
+ # pkg:gem/rubocop-performance#lib/rubocop/cop/performance/ancestors_include.rb:26
41
+ def ancestors_include_candidate?(param0 = T.unsafe(nil)); end
42
+
43
+ # pkg:gem/rubocop-performance#lib/rubocop/cop/performance/ancestors_include.rb:30
44
+ def on_send(node); end
45
+
46
+ private
47
+
48
+ # pkg:gem/rubocop-performance#lib/rubocop/cop/performance/ancestors_include.rb:43
49
+ def range(node); end
50
+ end
51
+
52
+ # pkg:gem/rubocop-performance#lib/rubocop/cop/performance/ancestors_include.rb:23
53
+ RuboCop::Cop::Performance::AncestorsInclude::MSG = T.let(T.unsafe(nil), String)
54
+
55
+ # pkg:gem/rubocop-performance#lib/rubocop/cop/performance/ancestors_include.rb:24
56
+ RuboCop::Cop::Performance::AncestorsInclude::RESTRICT_ON_SEND = T.let(T.unsafe(nil), Array)
57
+
58
+ # Identifies places where slicing arrays with semi-infinite ranges
59
+ # can be replaced by `Array#take` and `Array#drop`.
60
+ # This cop was created due to a mistake in microbenchmark and hence is disabled by default.
61
+ # Refer https://github.com/rubocop/rubocop-performance/pull/175#issuecomment-731892717
62
+ #
63
+ # @safety
64
+ # This cop is unsafe for string slices because strings do not have `#take` and `#drop` methods.
65
+ #
66
+ # @example
67
+ # # bad
68
+ # array[..2]
69
+ # array[...2]
70
+ # array[2..]
71
+ # array[2...]
72
+ # array.slice(..2)
73
+ #
74
+ # # good
75
+ # array.take(3)
76
+ # array.take(2)
77
+ # array.drop(2)
78
+ # array.drop(2)
79
+ # array.take(3)
80
+ #
81
+ # pkg:gem/rubocop-performance#lib/rubocop/cop/performance/array_semi_infinite_range_slice.rb:29
82
+ class RuboCop::Cop::Performance::ArraySemiInfiniteRangeSlice < ::RuboCop::Cop::Base
83
+ include ::RuboCop::Cop::RangeHelp
84
+ extend ::RuboCop::Cop::AutoCorrector
85
+ extend ::RuboCop::Cop::TargetRubyVersion
86
+
87
+ # pkg:gem/rubocop-performance#lib/rubocop/cop/performance/array_semi_infinite_range_slice.rb:45
88
+ def endless_range?(param0 = T.unsafe(nil)); end
89
+
90
+ # pkg:gem/rubocop-performance#lib/rubocop/cop/performance/array_semi_infinite_range_slice.rb:41
91
+ def endless_range_slice?(param0 = T.unsafe(nil)); end
92
+
93
+ # pkg:gem/rubocop-performance#lib/rubocop/cop/performance/array_semi_infinite_range_slice.rb:62
94
+ def on_csend(node); end
95
+
96
+ # pkg:gem/rubocop-performance#lib/rubocop/cop/performance/array_semi_infinite_range_slice.rb:52
97
+ def on_send(node); end
98
+
99
+ private
100
+
101
+ # pkg:gem/rubocop-performance#lib/rubocop/cop/performance/array_semi_infinite_range_slice.rb:66
102
+ def correction(receiver, range_node); end
103
+ end
104
+
105
+ # pkg:gem/rubocop-performance#lib/rubocop/cop/performance/array_semi_infinite_range_slice.rb:36
106
+ RuboCop::Cop::Performance::ArraySemiInfiniteRangeSlice::MSG = T.let(T.unsafe(nil), String)
107
+
108
+ # pkg:gem/rubocop-performance#lib/rubocop/cop/performance/array_semi_infinite_range_slice.rb:39
109
+ RuboCop::Cop::Performance::ArraySemiInfiniteRangeSlice::RESTRICT_ON_SEND = T.let(T.unsafe(nil), Set)
110
+
111
+ # pkg:gem/rubocop-performance#lib/rubocop/cop/performance/array_semi_infinite_range_slice.rb:38
112
+ RuboCop::Cop::Performance::ArraySemiInfiniteRangeSlice::SLICE_METHODS = T.let(T.unsafe(nil), Set)
113
+
114
+ # Identifies places where a float argument to BigDecimal should be converted to a string.
115
+ # Initializing from String is faster than from Float for BigDecimal.
116
+ #
117
+ # Also identifies places where an integer string argument to BigDecimal should be converted to
118
+ # an integer. Initializing from Integer is faster than from String for BigDecimal.
119
+ #
120
+ # NOTE: This cop is disabled by default because the performance of initializing with a String
121
+ # and Number differ between versions. Additionally, performance depends on the size of the Number,
122
+ # and if it is an Integer or a Float. Since this is very specific to `bigdecimal` internals,
123
+ # suggestions from this cop are not unlikely to result in code that performs worse than before.
124
+ #
125
+ # @example
126
+ # # bad
127
+ # BigDecimal(1.2, 3, exception: true)
128
+ # 4.5.to_d(6, exception: true)
129
+ #
130
+ # # good
131
+ # BigDecimal('1.2', 3, exception: true)
132
+ # BigDecimal('4.5', 6, exception: true)
133
+ #
134
+ # # bad
135
+ # BigDecimal('1', 2)
136
+ # BigDecimal('4', 6)
137
+ #
138
+ # # good
139
+ # BigDecimal(1, 2)
140
+ # 4.to_d(6)
141
+ #
142
+ # pkg:gem/rubocop-performance#lib/rubocop/cop/performance/big_decimal_with_numeric_argument.rb:34
143
+ class RuboCop::Cop::Performance::BigDecimalWithNumericArgument < ::RuboCop::Cop::Base
144
+ extend ::RuboCop::Cop::AutoCorrector
145
+ extend ::RuboCop::Cop::TargetRubyVersion
146
+
147
+ # pkg:gem/rubocop-performance#lib/rubocop/cop/performance/big_decimal_with_numeric_argument.rb:44
148
+ def big_decimal_with_numeric_argument(param0 = T.unsafe(nil)); end
149
+
150
+ # pkg:gem/rubocop-performance#lib/rubocop/cop/performance/big_decimal_with_numeric_argument.rb:53
151
+ def on_send(node); end
152
+
153
+ # pkg:gem/rubocop-performance#lib/rubocop/cop/performance/big_decimal_with_numeric_argument.rb:48
154
+ def to_d(param0 = T.unsafe(nil)); end
155
+ end
156
+
157
+ # pkg:gem/rubocop-performance#lib/rubocop/cop/performance/big_decimal_with_numeric_argument.rb:40
158
+ RuboCop::Cop::Performance::BigDecimalWithNumericArgument::MSG_FROM_FLOAT_TO_STRING = T.let(T.unsafe(nil), String)
159
+
160
+ # pkg:gem/rubocop-performance#lib/rubocop/cop/performance/big_decimal_with_numeric_argument.rb:41
161
+ RuboCop::Cop::Performance::BigDecimalWithNumericArgument::MSG_FROM_INTEGER_TO_STRING = T.let(T.unsafe(nil), String)
162
+
163
+ # pkg:gem/rubocop-performance#lib/rubocop/cop/performance/big_decimal_with_numeric_argument.rb:42
164
+ RuboCop::Cop::Performance::BigDecimalWithNumericArgument::RESTRICT_ON_SEND = T.let(T.unsafe(nil), Array)
165
+
166
+ # In Ruby 2.7, `UnboundMethod#bind_call` has been added.
167
+ #
168
+ # This cop identifies places where `bind(obj).call(args, ...)`
169
+ # can be replaced by `bind_call(obj, args, ...)`.
170
+ #
171
+ # The `bind_call(obj, args, ...)` method is faster than
172
+ # `bind(obj).call(args, ...)`.
173
+ #
174
+ # @example
175
+ # # bad
176
+ # umethod.bind(obj).call(foo, bar)
177
+ # umethod.bind(obj).(foo, bar)
178
+ #
179
+ # # good
180
+ # umethod.bind_call(obj, foo, bar)
181
+ #
182
+ # pkg:gem/rubocop-performance#lib/rubocop/cop/performance/bind_call.rb:22
183
+ class RuboCop::Cop::Performance::BindCall < ::RuboCop::Cop::Base
184
+ include ::RuboCop::Cop::RangeHelp
185
+ extend ::RuboCop::Cop::AutoCorrector
186
+ extend ::RuboCop::Cop::TargetRubyVersion
187
+
188
+ # pkg:gem/rubocop-performance#lib/rubocop/cop/performance/bind_call.rb:32
189
+ def bind_with_call_method?(param0 = T.unsafe(nil)); end
190
+
191
+ # pkg:gem/rubocop-performance#lib/rubocop/cop/performance/bind_call.rb:40
192
+ def on_send(node); end
193
+
194
+ private
195
+
196
+ # pkg:gem/rubocop-performance#lib/rubocop/cop/performance/bind_call.rb:71
197
+ def build_call_args(call_args_node); end
198
+
199
+ # pkg:gem/rubocop-performance#lib/rubocop/cop/performance/bind_call.rb:64
200
+ def correction_range(receiver, node); end
201
+
202
+ # pkg:gem/rubocop-performance#lib/rubocop/cop/performance/bind_call.rb:58
203
+ def message(bind_arg, call_args); end
204
+ end
205
+
206
+ # pkg:gem/rubocop-performance#lib/rubocop/cop/performance/bind_call.rb:29
207
+ RuboCop::Cop::Performance::BindCall::MSG = T.let(T.unsafe(nil), String)
208
+
209
+ # pkg:gem/rubocop-performance#lib/rubocop/cop/performance/bind_call.rb:30
210
+ RuboCop::Cop::Performance::BindCall::RESTRICT_ON_SEND = T.let(T.unsafe(nil), Array)
211
+
212
+ # Identifies unnecessary use of a `block_given?` where explicit check
213
+ # of block argument would suffice.
214
+ #
215
+ # NOTE: This cop produces code with significantly worse performance when a
216
+ # block is being passed to the method and as such should not be enabled.
217
+ #
218
+ # @example
219
+ # # bad
220
+ # def method(&block)
221
+ # do_something if block_given?
222
+ # end
223
+ #
224
+ # # good
225
+ # def method(&block)
226
+ # do_something if block
227
+ # end
228
+ #
229
+ # # good - block is reassigned
230
+ # def method(&block)
231
+ # block ||= -> { do_something }
232
+ # warn "Using default ..." unless block_given?
233
+ # # ...
234
+ # end
235
+ #
236
+ # pkg:gem/rubocop-performance#lib/rubocop/cop/performance/block_given_with_explicit_block.rb:30
237
+ class RuboCop::Cop::Performance::BlockGivenWithExplicitBlock < ::RuboCop::Cop::Base
238
+ extend ::RuboCop::Cop::AutoCorrector
239
+
240
+ # pkg:gem/rubocop-performance#lib/rubocop/cop/performance/block_given_with_explicit_block.rb:38
241
+ def on_send(node); end
242
+
243
+ # pkg:gem/rubocop-performance#lib/rubocop/cop/performance/block_given_with_explicit_block.rb:36
244
+ def reassigns_block_arg?(param0 = T.unsafe(nil), param1); end
245
+
246
+ class << self
247
+ # pkg:gem/rubocop-performance#lib/rubocop/cop/performance/block_given_with_explicit_block.rb:54
248
+ def autocorrect_incompatible_with; end
249
+ end
250
+ end
251
+
252
+ # pkg:gem/rubocop-performance#lib/rubocop/cop/performance/block_given_with_explicit_block.rb:34
253
+ RuboCop::Cop::Performance::BlockGivenWithExplicitBlock::MSG = T.let(T.unsafe(nil), String)
254
+
255
+ # pkg:gem/rubocop-performance#lib/rubocop/cop/performance/block_given_with_explicit_block.rb:33
256
+ RuboCop::Cop::Performance::BlockGivenWithExplicitBlock::RESTRICT_ON_SEND = T.let(T.unsafe(nil), Array)
257
+
258
+ # Identifies places where `caller[n]` can be replaced by `caller(n..n).first`.
259
+ #
260
+ # @example
261
+ # # bad
262
+ # caller[1]
263
+ # caller.first
264
+ # caller_locations[1]
265
+ # caller_locations.first
266
+ #
267
+ # # good
268
+ # caller(2..2).first
269
+ # caller(1..1).first
270
+ # caller_locations(2..2).first
271
+ # caller_locations(1..1).first
272
+ #
273
+ # pkg:gem/rubocop-performance#lib/rubocop/cop/performance/caller.rb:20
274
+ class RuboCop::Cop::Performance::Caller < ::RuboCop::Cop::Base
275
+ extend ::RuboCop::Cop::AutoCorrector
276
+
277
+ # pkg:gem/rubocop-performance#lib/rubocop/cop/performance/caller.rb:33
278
+ def caller_with_scope_method?(param0 = T.unsafe(nil)); end
279
+
280
+ # pkg:gem/rubocop-performance#lib/rubocop/cop/performance/caller.rb:40
281
+ def on_send(node); end
282
+
283
+ # pkg:gem/rubocop-performance#lib/rubocop/cop/performance/caller.rb:26
284
+ def slow_caller?(param0 = T.unsafe(nil)); end
285
+
286
+ private
287
+
288
+ # pkg:gem/rubocop-performance#lib/rubocop/cop/performance/caller.rb:61
289
+ def int_value(node); end
290
+ end
291
+
292
+ # pkg:gem/rubocop-performance#lib/rubocop/cop/performance/caller.rb:23
293
+ RuboCop::Cop::Performance::Caller::MSG = T.let(T.unsafe(nil), String)
294
+
295
+ # pkg:gem/rubocop-performance#lib/rubocop/cop/performance/caller.rb:24
296
+ RuboCop::Cop::Performance::Caller::RESTRICT_ON_SEND = T.let(T.unsafe(nil), Array)
297
+
298
+ # Reordering `when` conditions with a splat to the end
299
+ # of the `when` branches can improve performance.
300
+ #
301
+ # Ruby has to allocate memory for the splat expansion every time
302
+ # that the `case` `when` statement is run. Since Ruby does not support
303
+ # fall through inside of `case` `when`, like some other languages do,
304
+ # the order of the `when` branches should not matter. By placing any
305
+ # splat expansions at the end of the list of `when` branches we will
306
+ # reduce the number of times that memory has to be allocated for
307
+ # the expansion. The exception to this is if multiple of your `when`
308
+ # conditions can be true for any given condition. A likely scenario for
309
+ # this defining a higher level when condition to override a condition
310
+ # that is inside of the splat expansion.
311
+ #
312
+ # @safety
313
+ # This cop is not unsafe autocorrection because it is not a guaranteed
314
+ # performance improvement. If the data being processed by the `case` condition is
315
+ # normalized in a manner that favors hitting a condition in the splat expansion,
316
+ # it is possible that moving the splat condition to the end will use more memory,
317
+ # and run slightly slower.
318
+ # See for more details: https://github.com/rubocop/rubocop/pull/6163
319
+ #
320
+ # @example
321
+ # # bad
322
+ # case foo
323
+ # when *condition
324
+ # bar
325
+ # when baz
326
+ # foobar
327
+ # end
328
+ #
329
+ # case foo
330
+ # when *[1, 2, 3, 4]
331
+ # bar
332
+ # when 5
333
+ # baz
334
+ # end
335
+ #
336
+ # # good
337
+ # case foo
338
+ # when baz
339
+ # foobar
340
+ # when *condition
341
+ # bar
342
+ # end
343
+ #
344
+ # case foo
345
+ # when 1, 2, 3, 4
346
+ # bar
347
+ # when 5
348
+ # baz
349
+ # end
350
+ #
351
+ # pkg:gem/rubocop-performance#lib/rubocop/cop/performance/case_when_splat.rb:58
352
+ class RuboCop::Cop::Performance::CaseWhenSplat < ::RuboCop::Cop::Base
353
+ include ::RuboCop::Cop::Alignment
354
+ include ::RuboCop::Cop::RangeHelp
355
+ include ::RuboCop::Cop::CommentsHelp
356
+ extend ::RuboCop::Cop::AutoCorrector
357
+
358
+ # pkg:gem/rubocop-performance#lib/rubocop/cop/performance/case_when_splat.rb:67
359
+ def on_case(case_node); end
360
+
361
+ private
362
+
363
+ # pkg:gem/rubocop-performance#lib/rubocop/cop/performance/case_when_splat.rb:84
364
+ def autocorrect(corrector, when_node); end
365
+
366
+ # pkg:gem/rubocop-performance#lib/rubocop/cop/performance/case_when_splat.rb:154
367
+ def indent_for(node); end
368
+
369
+ # pkg:gem/rubocop-performance#lib/rubocop/cop/performance/case_when_splat.rb:101
370
+ def inline_fix_branch(corrector, when_node); end
371
+
372
+ # pkg:gem/rubocop-performance#lib/rubocop/cop/performance/case_when_splat.rb:178
373
+ def needs_reorder?(when_node); end
374
+
375
+ # pkg:gem/rubocop-performance#lib/rubocop/cop/performance/case_when_splat.rb:144
376
+ def new_branch_without_then(node, new_condition); end
377
+
378
+ # pkg:gem/rubocop-performance#lib/rubocop/cop/performance/case_when_splat.rb:140
379
+ def new_condition_with_then(node, new_condition); end
380
+
381
+ # pkg:gem/rubocop-performance#lib/rubocop/cop/performance/case_when_splat.rb:172
382
+ def non_splat?(condition); end
383
+
384
+ # pkg:gem/rubocop-performance#lib/rubocop/cop/performance/case_when_splat.rb:92
385
+ def range(node); end
386
+
387
+ # pkg:gem/rubocop-performance#lib/rubocop/cop/performance/case_when_splat.rb:108
388
+ def reorder_condition(corrector, when_node); end
389
+
390
+ # pkg:gem/rubocop-performance#lib/rubocop/cop/performance/case_when_splat.rb:117
391
+ def reordering_correction(when_node); end
392
+
393
+ # pkg:gem/rubocop-performance#lib/rubocop/cop/performance/case_when_splat.rb:96
394
+ def replacement(conditions); end
395
+
396
+ # pkg:gem/rubocop-performance#lib/rubocop/cop/performance/case_when_splat.rb:158
397
+ def splat_offenses(when_conditions); end
398
+
399
+ # pkg:gem/rubocop-performance#lib/rubocop/cop/performance/case_when_splat.rb:134
400
+ def when_branch_range(when_node); end
401
+ end
402
+
403
+ # pkg:gem/rubocop-performance#lib/rubocop/cop/performance/case_when_splat.rb:65
404
+ RuboCop::Cop::Performance::CaseWhenSplat::ARRAY_MSG = T.let(T.unsafe(nil), String)
405
+
406
+ # pkg:gem/rubocop-performance#lib/rubocop/cop/performance/case_when_splat.rb:64
407
+ RuboCop::Cop::Performance::CaseWhenSplat::MSG = T.let(T.unsafe(nil), String)
408
+
409
+ # Identifies places where a case-insensitive string comparison
410
+ # can better be implemented using `casecmp`.
411
+ #
412
+ # This cop is disabled by default because `String#casecmp` only works with
413
+ # ASCII characters. See https://github.com/rubocop/rubocop/issues/9753.
414
+ #
415
+ # If you are working only with ASCII characters, then this cop can be
416
+ # safely enabled.
417
+ #
418
+ # @safety
419
+ # This cop is unsafe because `String#casecmp` and `String#casecmp?` behave
420
+ # differently when using Non-ASCII characters.
421
+ #
422
+ # @example
423
+ # # bad
424
+ # str.downcase == 'abc'
425
+ # str.upcase.eql? 'ABC'
426
+ # 'abc' == str.downcase
427
+ # 'ABC'.eql? str.upcase
428
+ # str.downcase == str.downcase
429
+ #
430
+ # # good
431
+ # str.casecmp('ABC').zero?
432
+ # 'abc'.casecmp(str).zero?
433
+ #
434
+ # pkg:gem/rubocop-performance#lib/rubocop/cop/performance/casecmp.rb:30
435
+ class RuboCop::Cop::Performance::Casecmp < ::RuboCop::Cop::Base
436
+ extend ::RuboCop::Cop::AutoCorrector
437
+
438
+ # pkg:gem/rubocop-performance#lib/rubocop/cop/performance/casecmp.rb:51
439
+ def downcase_downcase(param0 = T.unsafe(nil)); end
440
+
441
+ # pkg:gem/rubocop-performance#lib/rubocop/cop/performance/casecmp.rb:37
442
+ def downcase_eq(param0 = T.unsafe(nil)); end
443
+
444
+ # pkg:gem/rubocop-performance#lib/rubocop/cop/performance/casecmp.rb:44
445
+ def eq_downcase(param0 = T.unsafe(nil)); end
446
+
447
+ # pkg:gem/rubocop-performance#lib/rubocop/cop/performance/casecmp.rb:58
448
+ def on_send(node); end
449
+
450
+ private
451
+
452
+ # pkg:gem/rubocop-performance#lib/rubocop/cop/performance/casecmp.rb:90
453
+ def autocorrect(corrector, node, replacement); end
454
+
455
+ # pkg:gem/rubocop-performance#lib/rubocop/cop/performance/casecmp.rb:94
456
+ def build_good_method(method, arg, variable); end
457
+
458
+ # pkg:gem/rubocop-performance#lib/rubocop/cop/performance/casecmp.rb:73
459
+ def take_method_apart(node); end
460
+ end
461
+
462
+ # pkg:gem/rubocop-performance#lib/rubocop/cop/performance/casecmp.rb:35
463
+ RuboCop::Cop::Performance::Casecmp::CASE_METHODS = T.let(T.unsafe(nil), Array)
464
+
465
+ # pkg:gem/rubocop-performance#lib/rubocop/cop/performance/casecmp.rb:33
466
+ RuboCop::Cop::Performance::Casecmp::MSG = T.let(T.unsafe(nil), String)
467
+
468
+ # pkg:gem/rubocop-performance#lib/rubocop/cop/performance/casecmp.rb:34
469
+ RuboCop::Cop::Performance::Casecmp::RESTRICT_ON_SEND = T.let(T.unsafe(nil), Array)
470
+
471
+ # Identifies usages of `array.compact.flatten.map { |x| x.downcase }`.
472
+ # Each of these methods (`compact`, `flatten`, `map`) will generate a new intermediate array
473
+ # that is promptly thrown away. Instead it is faster to mutate when we know it's safe.
474
+ #
475
+ # @example
476
+ # # bad
477
+ # array = ["a", "b", "c"]
478
+ # array.compact.flatten.map { |x| x.downcase }
479
+ #
480
+ # # good
481
+ # array = ["a", "b", "c"]
482
+ # array.compact!
483
+ # array.flatten!
484
+ # array.map! { |x| x.downcase }
485
+ # array
486
+ #
487
+ # pkg:gem/rubocop-performance#lib/rubocop/cop/performance/chain_array_allocation.rb:21
488
+ class RuboCop::Cop::Performance::ChainArrayAllocation < ::RuboCop::Cop::Base
489
+ # pkg:gem/rubocop-performance#lib/rubocop/cop/performance/chain_array_allocation.rb:54
490
+ def chain_array_allocation?(param0 = T.unsafe(nil)); end
491
+
492
+ # pkg:gem/rubocop-performance#lib/rubocop/cop/performance/chain_array_allocation.rb:62
493
+ def on_send(node); end
494
+
495
+ private
496
+
497
+ # pkg:gem/rubocop-performance#lib/rubocop/cop/performance/chain_array_allocation.rb:75
498
+ def enumerable_select_method?(node); end
499
+ end
500
+
501
+ # These methods ALWAYS return a new array
502
+ # after they're called it's safe to mutate the resulting array
503
+ #
504
+ # pkg:gem/rubocop-performance#lib/rubocop/cop/performance/chain_array_allocation.rb:35
505
+ RuboCop::Cop::Performance::ChainArrayAllocation::ALWAYS_RETURNS_NEW_ARRAY = T.let(T.unsafe(nil), Set)
506
+
507
+ # These methods have a mutation alternative. For example :collect
508
+ # can be called as :collect!
509
+ #
510
+ # pkg:gem/rubocop-performance#lib/rubocop/cop/performance/chain_array_allocation.rb:43
511
+ RuboCop::Cop::Performance::ChainArrayAllocation::HAS_MUTATION_ALTERNATIVE = T.let(T.unsafe(nil), Set)
512
+
513
+ # pkg:gem/rubocop-performance#lib/rubocop/cop/performance/chain_array_allocation.rb:50
514
+ RuboCop::Cop::Performance::ChainArrayAllocation::MSG = T.let(T.unsafe(nil), String)
515
+
516
+ # pkg:gem/rubocop-performance#lib/rubocop/cop/performance/chain_array_allocation.rb:48
517
+ RuboCop::Cop::Performance::ChainArrayAllocation::RESTRICT_ON_SEND = T.let(T.unsafe(nil), Set)
518
+
519
+ # pkg:gem/rubocop-performance#lib/rubocop/cop/performance/chain_array_allocation.rb:46
520
+ RuboCop::Cop::Performance::ChainArrayAllocation::RETURNS_NEW_ARRAY = T.let(T.unsafe(nil), Set)
521
+
522
+ # These methods return a new array only when called without a block.
523
+ #
524
+ # pkg:gem/rubocop-performance#lib/rubocop/cop/performance/chain_array_allocation.rb:31
525
+ RuboCop::Cop::Performance::ChainArrayAllocation::RETURNS_NEW_ARRAY_WHEN_NO_BLOCK = T.let(T.unsafe(nil), Set)
526
+
527
+ # These methods return a new array but only sometimes. They must be
528
+ # called with an argument. For example:
529
+ #
530
+ # [1,2].first # => 1
531
+ # [1,2].first(1) # => [1]
532
+ #
533
+ # pkg:gem/rubocop-performance#lib/rubocop/cop/performance/chain_array_allocation.rb:28
534
+ RuboCop::Cop::Performance::ChainArrayAllocation::RETURN_NEW_ARRAY_WHEN_ARGS = T.let(T.unsafe(nil), Set)
535
+
536
+ # Identifies places where Array and Hash literals are used within loops.
537
+ # It is better to extract them into a local variable or constant
538
+ # to avoid unnecessary allocations on each iteration.
539
+ #
540
+ # You can set the minimum number of elements to consider
541
+ # an offense with `MinSize`.
542
+ #
543
+ # NOTE: Since Ruby 3.4, certain simple arguments to `Array#include?` are
544
+ # optimized directly in Ruby. This avoids allocations without changing the
545
+ # code, as such no offense will be registered in those cases. Currently that
546
+ # includes: strings, `self`, local variables, instance variables, and method
547
+ # calls without arguments. Additionally, any number of methods can be chained:
548
+ # `[1, 2, 3].include?(@foo)` and `[1, 2, 3].include?(@foo.bar.baz)` both avoid
549
+ # the array allocation.
550
+ #
551
+ # @example
552
+ # # bad
553
+ # users.select do |user|
554
+ # %i[superadmin admin].include?(user.role)
555
+ # end
556
+ #
557
+ # # good
558
+ # admin_roles = %i[superadmin admin]
559
+ # users.select do |user|
560
+ # admin_roles.include?(user.role)
561
+ # end
562
+ #
563
+ # # good
564
+ # ADMIN_ROLES = %i[superadmin admin]
565
+ # ...
566
+ # users.select do |user|
567
+ # ADMIN_ROLES.include?(user.role)
568
+ # end
569
+ #
570
+ # pkg:gem/rubocop-performance#lib/rubocop/cop/performance/collection_literal_in_loop.rb:42
571
+ class RuboCop::Cop::Performance::CollectionLiteralInLoop < ::RuboCop::Cop::Base
572
+ # pkg:gem/rubocop-performance#lib/rubocop/cop/performance/collection_literal_in_loop.rb:86
573
+ def enumerable_loop?(param0 = T.unsafe(nil)); end
574
+
575
+ # pkg:gem/rubocop-performance#lib/rubocop/cop/performance/collection_literal_in_loop.rb:80
576
+ def kernel_loop?(param0 = T.unsafe(nil)); end
577
+
578
+ # pkg:gem/rubocop-performance#lib/rubocop/cop/performance/collection_literal_in_loop.rb:92
579
+ def on_send(node); end
580
+
581
+ private
582
+
583
+ # pkg:gem/rubocop-performance#lib/rubocop/cop/performance/collection_literal_in_loop.rb:102
584
+ def check_literal?(node, method, arguments); end
585
+
586
+ # pkg:gem/rubocop-performance#lib/rubocop/cop/performance/collection_literal_in_loop.rb:161
587
+ def enumerable_method?(method_name); end
588
+
589
+ # pkg:gem/rubocop-performance#lib/rubocop/cop/performance/collection_literal_in_loop.rb:143
590
+ def keyword_loop?(type); end
591
+
592
+ # pkg:gem/rubocop-performance#lib/rubocop/cop/performance/collection_literal_in_loop.rb:153
593
+ def literal_class(node); end
594
+
595
+ # pkg:gem/rubocop-performance#lib/rubocop/cop/performance/collection_literal_in_loop.rb:139
596
+ def loop?(ancestor, node); end
597
+
598
+ # pkg:gem/rubocop-performance#lib/rubocop/cop/performance/collection_literal_in_loop.rb:165
599
+ def min_size; end
600
+
601
+ # pkg:gem/rubocop-performance#lib/rubocop/cop/performance/collection_literal_in_loop.rb:147
602
+ def node_within_enumerable_loop?(node, ancestor); end
603
+
604
+ # pkg:gem/rubocop-performance#lib/rubocop/cop/performance/collection_literal_in_loop.rb:130
605
+ def nonmutable_method_of_array_or_hash?(node, method); end
606
+
607
+ # Since Ruby 3.4, simple arguments to Array#include? are optimized.
608
+ # See https://github.com/ruby/ruby/pull/12123 for more details.
609
+ #
610
+ # pkg:gem/rubocop-performance#lib/rubocop/cop/performance/collection_literal_in_loop.rb:113
611
+ def optimized_array_include?(node, method, arguments); end
612
+
613
+ # pkg:gem/rubocop-performance#lib/rubocop/cop/performance/collection_literal_in_loop.rb:135
614
+ def parent_is_loop?(node); end
615
+ end
616
+
617
+ # pkg:gem/rubocop-performance#lib/rubocop/cop/performance/collection_literal_in_loop.rb:66
618
+ RuboCop::Cop::Performance::CollectionLiteralInLoop::ARRAY_INCLUDE_OPTIMIZED_TYPES = T.let(T.unsafe(nil), Array)
619
+
620
+ # pkg:gem/rubocop-performance#lib/rubocop/cop/performance/collection_literal_in_loop.rb:64
621
+ RuboCop::Cop::Performance::CollectionLiteralInLoop::ARRAY_METHODS = T.let(T.unsafe(nil), Set)
622
+
623
+ # pkg:gem/rubocop-performance#lib/rubocop/cop/performance/collection_literal_in_loop.rb:49
624
+ RuboCop::Cop::Performance::CollectionLiteralInLoop::ENUMERABLE_METHOD_NAMES = T.let(T.unsafe(nil), Set)
625
+
626
+ # pkg:gem/rubocop-performance#lib/rubocop/cop/performance/collection_literal_in_loop.rb:76
627
+ RuboCop::Cop::Performance::CollectionLiteralInLoop::HASH_METHODS = T.let(T.unsafe(nil), Set)
628
+
629
+ # pkg:gem/rubocop-performance#lib/rubocop/cop/performance/collection_literal_in_loop.rb:47
630
+ RuboCop::Cop::Performance::CollectionLiteralInLoop::LOOP_TYPES = T.let(T.unsafe(nil), Array)
631
+
632
+ # pkg:gem/rubocop-performance#lib/rubocop/cop/performance/collection_literal_in_loop.rb:43
633
+ RuboCop::Cop::Performance::CollectionLiteralInLoop::MSG = T.let(T.unsafe(nil), String)
634
+
635
+ # pkg:gem/rubocop-performance#lib/rubocop/cop/performance/collection_literal_in_loop.rb:50
636
+ RuboCop::Cop::Performance::CollectionLiteralInLoop::NONMUTATING_ARRAY_METHODS = T.let(T.unsafe(nil), Array)
637
+
638
+ # pkg:gem/rubocop-performance#lib/rubocop/cop/performance/collection_literal_in_loop.rb:68
639
+ RuboCop::Cop::Performance::CollectionLiteralInLoop::NONMUTATING_HASH_METHODS = T.let(T.unsafe(nil), Array)
640
+
641
+ # pkg:gem/rubocop-performance#lib/rubocop/cop/performance/collection_literal_in_loop.rb:46
642
+ RuboCop::Cop::Performance::CollectionLiteralInLoop::POST_CONDITION_LOOP_TYPES = T.let(T.unsafe(nil), Array)
643
+
644
+ # pkg:gem/rubocop-performance#lib/rubocop/cop/performance/collection_literal_in_loop.rb:78
645
+ RuboCop::Cop::Performance::CollectionLiteralInLoop::RESTRICT_ON_SEND = T.let(T.unsafe(nil), Set)
646
+
647
+ # Identifies places where `sort { |a, b| a.foo <=> b.foo }`
648
+ # can be replaced by `sort_by(&:foo)`.
649
+ # This cop also checks `sort!`, `min`, `max` and `minmax` methods.
650
+ #
651
+ # @example
652
+ # # bad
653
+ # array.sort { |a, b| a.foo <=> b.foo }
654
+ # array.sort! { |a, b| a.foo <=> b.foo }
655
+ # array.max { |a, b| a.foo <=> b.foo }
656
+ # array.min { |a, b| a.foo <=> b.foo }
657
+ # array.minmax { |a, b| a.foo <=> b.foo }
658
+ # array.sort { |a, b| a[:foo] <=> b[:foo] }
659
+ #
660
+ # # good
661
+ # array.sort_by(&:foo)
662
+ # array.sort_by!(&:foo)
663
+ # array.sort_by { |v| v.foo }
664
+ # array.sort_by do |var|
665
+ # var.foo
666
+ # end
667
+ # array.max_by(&:foo)
668
+ # array.min_by(&:foo)
669
+ # array.minmax_by(&:foo)
670
+ # array.sort_by { |a| a[:foo] }
671
+ #
672
+ # pkg:gem/rubocop-performance#lib/rubocop/cop/performance/compare_with_block.rb:30
673
+ class RuboCop::Cop::Performance::CompareWithBlock < ::RuboCop::Cop::Base
674
+ include ::RuboCop::Cop::RangeHelp
675
+ extend ::RuboCop::Cop::AutoCorrector
676
+
677
+ # pkg:gem/rubocop-performance#lib/rubocop/cop/performance/compare_with_block.rb:41
678
+ def compare?(param0 = T.unsafe(nil)); end
679
+
680
+ # pkg:gem/rubocop-performance#lib/rubocop/cop/performance/compare_with_block.rb:55
681
+ def on_block(node); end
682
+
683
+ # pkg:gem/rubocop-performance#lib/rubocop/cop/performance/compare_with_block.rb:48
684
+ def replaceable_body?(param0 = T.unsafe(nil), param1, param2); end
685
+
686
+ private
687
+
688
+ # pkg:gem/rubocop-performance#lib/rubocop/cop/performance/compare_with_block.rb:114
689
+ def compare_range(send, node); end
690
+
691
+ # pkg:gem/rubocop-performance#lib/rubocop/cop/performance/compare_with_block.rb:91
692
+ def message(send, method, var_a, var_b, args); end
693
+
694
+ # pkg:gem/rubocop-performance#lib/rubocop/cop/performance/compare_with_block.rb:76
695
+ def slow_compare?(method, args_a, args_b); end
696
+ end
697
+
698
+ # pkg:gem/rubocop-performance#lib/rubocop/cop/performance/compare_with_block.rb:34
699
+ RuboCop::Cop::Performance::CompareWithBlock::MSG = T.let(T.unsafe(nil), String)
700
+
701
+ # pkg:gem/rubocop-performance#lib/rubocop/cop/performance/compare_with_block.rb:38
702
+ RuboCop::Cop::Performance::CompareWithBlock::REPLACEMENT = T.let(T.unsafe(nil), Hash)
703
+
704
+ # Identifies places where `Concurrent.monotonic_time`
705
+ # can be replaced by `Process.clock_gettime(Process::CLOCK_MONOTONIC)`.
706
+ #
707
+ # @example
708
+ #
709
+ # # bad
710
+ # Concurrent.monotonic_time
711
+ #
712
+ # # good
713
+ # Process.clock_gettime(Process::CLOCK_MONOTONIC)
714
+ #
715
+ # pkg:gem/rubocop-performance#lib/rubocop/cop/performance/concurrent_monotonic_time.rb:17
716
+ class RuboCop::Cop::Performance::ConcurrentMonotonicTime < ::RuboCop::Cop::Base
717
+ extend ::RuboCop::Cop::AutoCorrector
718
+
719
+ # pkg:gem/rubocop-performance#lib/rubocop/cop/performance/concurrent_monotonic_time.rb:23
720
+ def concurrent_monotonic_time?(param0 = T.unsafe(nil)); end
721
+
722
+ # pkg:gem/rubocop-performance#lib/rubocop/cop/performance/concurrent_monotonic_time.rb:28
723
+ def on_send(node); end
724
+ end
725
+
726
+ # pkg:gem/rubocop-performance#lib/rubocop/cop/performance/concurrent_monotonic_time.rb:20
727
+ RuboCop::Cop::Performance::ConcurrentMonotonicTime::MSG = T.let(T.unsafe(nil), String)
728
+
729
+ # pkg:gem/rubocop-performance#lib/rubocop/cop/performance/concurrent_monotonic_time.rb:21
730
+ RuboCop::Cop::Performance::ConcurrentMonotonicTime::RESTRICT_ON_SEND = T.let(T.unsafe(nil), Array)
731
+
732
+ # Finds regular expressions with dynamic components that are all constants.
733
+ #
734
+ # Ruby allocates a new Regexp object every time it executes a code containing such
735
+ # a regular expression. It is more efficient to extract it into a constant,
736
+ # memoize it, or add an `/o` option to perform `#{}` interpolation only once and
737
+ # reuse that Regexp object.
738
+ #
739
+ # @example
740
+ #
741
+ # # bad
742
+ # def tokens(pattern)
743
+ # pattern.scan(TOKEN).reject { |token| token.match?(/\A#{SEPARATORS}\Z/) }
744
+ # end
745
+ #
746
+ # # good
747
+ # ALL_SEPARATORS = /\A#{SEPARATORS}\Z/
748
+ # def tokens(pattern)
749
+ # pattern.scan(TOKEN).reject { |token| token.match?(ALL_SEPARATORS) }
750
+ # end
751
+ #
752
+ # # good
753
+ # def tokens(pattern)
754
+ # pattern.scan(TOKEN).reject { |token| token.match?(/\A#{SEPARATORS}\Z/o) }
755
+ # end
756
+ #
757
+ # # good
758
+ # def separators
759
+ # @separators ||= /\A#{SEPARATORS}\Z/
760
+ # end
761
+ #
762
+ # pkg:gem/rubocop-performance#lib/rubocop/cop/performance/constant_regexp.rb:36
763
+ class RuboCop::Cop::Performance::ConstantRegexp < ::RuboCop::Cop::Base
764
+ extend ::RuboCop::Cop::AutoCorrector
765
+
766
+ # pkg:gem/rubocop-performance#lib/rubocop/cop/performance/constant_regexp.rb:45
767
+ def on_regexp(node); end
768
+
769
+ # pkg:gem/rubocop-performance#lib/rubocop/cop/performance/constant_regexp.rb:59
770
+ def regexp_escape?(param0 = T.unsafe(nil)); end
771
+
772
+ private
773
+
774
+ # pkg:gem/rubocop-performance#lib/rubocop/cop/performance/constant_regexp.rb:64
775
+ def include_interpolated_const?(node); end
776
+
777
+ # pkg:gem/rubocop-performance#lib/rubocop/cop/performance/constant_regexp.rb:55
778
+ def within_allowed_assignment?(node); end
779
+
780
+ class << self
781
+ # pkg:gem/rubocop-performance#lib/rubocop/cop/performance/constant_regexp.rb:41
782
+ def autocorrect_incompatible_with; end
783
+ end
784
+ end
785
+
786
+ # pkg:gem/rubocop-performance#lib/rubocop/cop/performance/constant_regexp.rb:39
787
+ RuboCop::Cop::Performance::ConstantRegexp::MSG = T.let(T.unsafe(nil), String)
788
+
789
+ # Identifies usages of `count` on an `Enumerable` that
790
+ # follow calls to `select`, `find_all`, `filter` or `reject`. Querying logic can instead be
791
+ # passed to the `count` call.
792
+ #
793
+ # @safety
794
+ # This cop is unsafe because it has known compatibility issues with `ActiveRecord` and other
795
+ # frameworks. Before Rails 5.1, `ActiveRecord` will ignore the block that is passed to `count`.
796
+ # Other methods, such as `select`, will convert the association to an
797
+ # array and then run the block on the array. A simple work around to
798
+ # make `count` work with a block is to call `to_a.count {...}`.
799
+ #
800
+ # For example:
801
+ #
802
+ # [source,ruby]
803
+ # ----
804
+ # Model.where(id: [1, 2, 3]).select { |m| m.method == true }.size
805
+ # ----
806
+ #
807
+ # becomes:
808
+ #
809
+ # [source,ruby]
810
+ # ----
811
+ # Model.where(id: [1, 2, 3]).to_a.count { |m| m.method == true }
812
+ # ----
813
+ #
814
+ # @example
815
+ # # bad
816
+ # [1, 2, 3].select { |e| e > 2 }.size
817
+ # [1, 2, 3].reject { |e| e > 2 }.size
818
+ # [1, 2, 3].select { |e| e > 2 }.length
819
+ # [1, 2, 3].reject { |e| e > 2 }.length
820
+ # [1, 2, 3].select { |e| e > 2 }.count { |e| e.odd? }
821
+ # [1, 2, 3].reject { |e| e > 2 }.count { |e| e.even? }
822
+ # array.select(&:value).count
823
+ #
824
+ # # good
825
+ # [1, 2, 3].count { |e| e > 2 }
826
+ # [1, 2, 3].count { |e| e < 2 }
827
+ # [1, 2, 3].count { |e| e > 2 && e.odd? }
828
+ # [1, 2, 3].count { |e| e < 2 && e.even? }
829
+ # Model.select('field AS field_one').count
830
+ # Model.select(:value).count
831
+ #
832
+ # pkg:gem/rubocop-performance#lib/rubocop/cop/performance/count.rb:48
833
+ class RuboCop::Cop::Performance::Count < ::RuboCop::Cop::Base
834
+ include ::RuboCop::Cop::RangeHelp
835
+ extend ::RuboCop::Cop::AutoCorrector
836
+
837
+ # pkg:gem/rubocop-performance#lib/rubocop/cop/performance/count.rb:55
838
+ def count_candidate?(param0 = T.unsafe(nil)); end
839
+
840
+ # pkg:gem/rubocop-performance#lib/rubocop/cop/performance/count.rb:75
841
+ def on_csend(node); end
842
+
843
+ # pkg:gem/rubocop-performance#lib/rubocop/cop/performance/count.rb:62
844
+ def on_send(node); end
845
+
846
+ private
847
+
848
+ # pkg:gem/rubocop-performance#lib/rubocop/cop/performance/count.rb:79
849
+ def autocorrect(corrector, node, selector_node, selector); end
850
+
851
+ # pkg:gem/rubocop-performance#lib/rubocop/cop/performance/count.rb:89
852
+ def eligible_node?(node); end
853
+
854
+ # pkg:gem/rubocop-performance#lib/rubocop/cop/performance/count.rb:134
855
+ def negate_block_pass_as_inline_block(node); end
856
+
857
+ # pkg:gem/rubocop-performance#lib/rubocop/cop/performance/count.rb:113
858
+ def negate_block_pass_reject(corrector, node); end
859
+
860
+ # pkg:gem/rubocop-performance#lib/rubocop/cop/performance/count.rb:120
861
+ def negate_block_reject(corrector, node); end
862
+
863
+ # pkg:gem/rubocop-performance#lib/rubocop/cop/performance/count.rb:130
864
+ def negate_expression(node); end
865
+
866
+ # pkg:gem/rubocop-performance#lib/rubocop/cop/performance/count.rb:105
867
+ def negate_reject(corrector, node); end
868
+
869
+ # pkg:gem/rubocop-performance#lib/rubocop/cop/performance/count.rb:95
870
+ def source_starting_at(node); end
871
+ end
872
+
873
+ # pkg:gem/rubocop-performance#lib/rubocop/cop/performance/count.rb:52
874
+ RuboCop::Cop::Performance::Count::MSG = T.let(T.unsafe(nil), String)
875
+
876
+ # pkg:gem/rubocop-performance#lib/rubocop/cop/performance/count.rb:53
877
+ RuboCop::Cop::Performance::Count::RESTRICT_ON_SEND = T.let(T.unsafe(nil), Array)
878
+
879
+ # In Ruby 2.5, `String#delete_prefix` has been added.
880
+ #
881
+ # This cop identifies places where `gsub(/\Aprefix/, '')` and `sub(/\Aprefix/, '')`
882
+ # can be replaced by `delete_prefix('prefix')`.
883
+ #
884
+ # This cop has `SafeMultiline` configuration option that `true` by default because
885
+ # `^prefix` is unsafe as it will behave incompatible with `delete_prefix`
886
+ # for receiver is multiline string.
887
+ #
888
+ # The `delete_prefix('prefix')` method is faster than `gsub(/\Aprefix/, '')`.
889
+ #
890
+ # @safety
891
+ # This cop is unsafe because `Pathname` has `sub` but not `delete_prefix`.
892
+ #
893
+ # @example
894
+ #
895
+ # # bad
896
+ # str.gsub(/\Aprefix/, '')
897
+ # str.gsub!(/\Aprefix/, '')
898
+ #
899
+ # str.sub(/\Aprefix/, '')
900
+ # str.sub!(/\Aprefix/, '')
901
+ #
902
+ # # good
903
+ # str.delete_prefix('prefix')
904
+ # str.delete_prefix!('prefix')
905
+ #
906
+ # @example SafeMultiline: true (default)
907
+ #
908
+ # # good
909
+ # str.gsub(/^prefix/, '')
910
+ # str.gsub!(/^prefix/, '')
911
+ # str.sub(/^prefix/, '')
912
+ # str.sub!(/^prefix/, '')
913
+ #
914
+ # @example SafeMultiline: false
915
+ #
916
+ # # bad
917
+ # str.gsub(/^prefix/, '')
918
+ # str.gsub!(/^prefix/, '')
919
+ # str.sub(/^prefix/, '')
920
+ # str.sub!(/^prefix/, '')
921
+ #
922
+ # pkg:gem/rubocop-performance#lib/rubocop/cop/performance/delete_prefix.rb:49
923
+ class RuboCop::Cop::Performance::DeletePrefix < ::RuboCop::Cop::Base
924
+ include ::RuboCop::Cop::RegexpMetacharacter
925
+ extend ::RuboCop::Cop::AutoCorrector
926
+ extend ::RuboCop::Cop::TargetRubyVersion
927
+
928
+ # pkg:gem/rubocop-performance#lib/rubocop/cop/performance/delete_prefix.rb:66
929
+ def delete_prefix_candidate?(param0 = T.unsafe(nil)); end
930
+
931
+ # pkg:gem/rubocop-performance#lib/rubocop/cop/performance/delete_prefix.rb:90
932
+ def on_csend(node); end
933
+
934
+ # pkg:gem/rubocop-performance#lib/rubocop/cop/performance/delete_prefix.rb:71
935
+ def on_send(node); end
936
+ end
937
+
938
+ # pkg:gem/rubocop-performance#lib/rubocop/cop/performance/delete_prefix.rb:56
939
+ RuboCop::Cop::Performance::DeletePrefix::MSG = T.let(T.unsafe(nil), String)
940
+
941
+ # pkg:gem/rubocop-performance#lib/rubocop/cop/performance/delete_prefix.rb:59
942
+ RuboCop::Cop::Performance::DeletePrefix::PREFERRED_METHODS = T.let(T.unsafe(nil), Hash)
943
+
944
+ # pkg:gem/rubocop-performance#lib/rubocop/cop/performance/delete_prefix.rb:57
945
+ RuboCop::Cop::Performance::DeletePrefix::RESTRICT_ON_SEND = T.let(T.unsafe(nil), Array)
946
+
947
+ # In Ruby 2.5, `String#delete_suffix` has been added.
948
+ #
949
+ # This cop identifies places where `gsub(/suffix\z/, '')` and `sub(/suffix\z/, '')`
950
+ # can be replaced by `delete_suffix('suffix')`.
951
+ #
952
+ # This cop has `SafeMultiline` configuration option that `true` by default because
953
+ # `suffix$` is unsafe as it will behave incompatible with `delete_suffix?`
954
+ # for receiver is multiline string.
955
+ #
956
+ # The `delete_suffix('suffix')` method is faster than `gsub(/suffix\z/, '')`.
957
+ #
958
+ # @safety
959
+ # This cop is unsafe because `Pathname` has `sub` but not `delete_suffix`.
960
+ #
961
+ # @example
962
+ #
963
+ # # bad
964
+ # str.gsub(/suffix\z/, '')
965
+ # str.gsub!(/suffix\z/, '')
966
+ #
967
+ # str.sub(/suffix\z/, '')
968
+ # str.sub!(/suffix\z/, '')
969
+ #
970
+ # # good
971
+ # str.delete_suffix('suffix')
972
+ # str.delete_suffix!('suffix')
973
+ #
974
+ # @example SafeMultiline: true (default)
975
+ #
976
+ # # good
977
+ # str.gsub(/suffix$/, '')
978
+ # str.gsub!(/suffix$/, '')
979
+ # str.sub(/suffix$/, '')
980
+ # str.sub!(/suffix$/, '')
981
+ #
982
+ # @example SafeMultiline: false
983
+ #
984
+ # # bad
985
+ # str.gsub(/suffix$/, '')
986
+ # str.gsub!(/suffix$/, '')
987
+ # str.sub(/suffix$/, '')
988
+ # str.sub!(/suffix$/, '')
989
+ #
990
+ # pkg:gem/rubocop-performance#lib/rubocop/cop/performance/delete_suffix.rb:49
991
+ class RuboCop::Cop::Performance::DeleteSuffix < ::RuboCop::Cop::Base
992
+ include ::RuboCop::Cop::RegexpMetacharacter
993
+ extend ::RuboCop::Cop::AutoCorrector
994
+ extend ::RuboCop::Cop::TargetRubyVersion
995
+
996
+ # pkg:gem/rubocop-performance#lib/rubocop/cop/performance/delete_suffix.rb:66
997
+ def delete_suffix_candidate?(param0 = T.unsafe(nil)); end
998
+
999
+ # pkg:gem/rubocop-performance#lib/rubocop/cop/performance/delete_suffix.rb:90
1000
+ def on_csend(node); end
1001
+
1002
+ # pkg:gem/rubocop-performance#lib/rubocop/cop/performance/delete_suffix.rb:71
1003
+ def on_send(node); end
1004
+ end
1005
+
1006
+ # pkg:gem/rubocop-performance#lib/rubocop/cop/performance/delete_suffix.rb:56
1007
+ RuboCop::Cop::Performance::DeleteSuffix::MSG = T.let(T.unsafe(nil), String)
1008
+
1009
+ # pkg:gem/rubocop-performance#lib/rubocop/cop/performance/delete_suffix.rb:59
1010
+ RuboCop::Cop::Performance::DeleteSuffix::PREFERRED_METHODS = T.let(T.unsafe(nil), Hash)
1011
+
1012
+ # pkg:gem/rubocop-performance#lib/rubocop/cop/performance/delete_suffix.rb:57
1013
+ RuboCop::Cop::Performance::DeleteSuffix::RESTRICT_ON_SEND = T.let(T.unsafe(nil), Array)
1014
+
1015
+ # Identifies usages of `first`, `last`, `[0]` or `[-1]`
1016
+ # chained to `select`, `find_all` or `filter` and change them to use
1017
+ # `detect` instead.
1018
+ #
1019
+ # @safety
1020
+ # This cop is unsafe because it assumes that the receiver is an
1021
+ # `Array` or equivalent, but can't reliably detect it. For example,
1022
+ # if the receiver is a `Hash`, it may report a false positive.
1023
+ #
1024
+ # @example
1025
+ # # bad
1026
+ # [].select { |item| true }.first
1027
+ # [].select { |item| true }.last
1028
+ # [].find_all { |item| true }.first
1029
+ # [].find_all { |item| true }.last
1030
+ # [].filter { |item| true }.first
1031
+ # [].filter { |item| true }.last
1032
+ # [].filter { |item| true }[0]
1033
+ # [].filter { |item| true }[-1]
1034
+ #
1035
+ # # good
1036
+ # [].detect { |item| true }
1037
+ # [].reverse.detect { |item| true }
1038
+ #
1039
+ # pkg:gem/rubocop-performance#lib/rubocop/cop/performance/detect.rb:30
1040
+ class RuboCop::Cop::Performance::Detect < ::RuboCop::Cop::Base
1041
+ extend ::RuboCop::Cop::AutoCorrector
1042
+
1043
+ # pkg:gem/rubocop-performance#lib/rubocop/cop/performance/detect.rb:41
1044
+ def detect_candidate?(param0 = T.unsafe(nil)); end
1045
+
1046
+ # pkg:gem/rubocop-performance#lib/rubocop/cop/performance/detect.rb:66
1047
+ def on_csend(node); end
1048
+
1049
+ # pkg:gem/rubocop-performance#lib/rubocop/cop/performance/detect.rb:50
1050
+ def on_send(node); end
1051
+
1052
+ private
1053
+
1054
+ # pkg:gem/rubocop-performance#lib/rubocop/cop/performance/detect.rb:70
1055
+ def accept_first_call?(receiver, body); end
1056
+
1057
+ # pkg:gem/rubocop-performance#lib/rubocop/cop/performance/detect.rb:102
1058
+ def autocorrect(corrector, node, replacement); end
1059
+
1060
+ # pkg:gem/rubocop-performance#lib/rubocop/cop/performance/detect.rb:128
1061
+ def lazy?(node); end
1062
+
1063
+ # pkg:gem/rubocop-performance#lib/rubocop/cop/performance/detect.rb:113
1064
+ def message_for_method(method, index); end
1065
+
1066
+ # pkg:gem/rubocop-performance#lib/rubocop/cop/performance/detect.rb:124
1067
+ def preferred_method; end
1068
+
1069
+ # pkg:gem/rubocop-performance#lib/rubocop/cop/performance/detect.rb:79
1070
+ def register_offense(node, receiver, second_method, index); end
1071
+
1072
+ # pkg:gem/rubocop-performance#lib/rubocop/cop/performance/detect.rb:94
1073
+ def replacement(method, index); end
1074
+ end
1075
+
1076
+ # pkg:gem/rubocop-performance#lib/rubocop/cop/performance/detect.rb:33
1077
+ RuboCop::Cop::Performance::Detect::CANDIDATE_METHODS = T.let(T.unsafe(nil), Set)
1078
+
1079
+ # pkg:gem/rubocop-performance#lib/rubocop/cop/performance/detect.rb:37
1080
+ RuboCop::Cop::Performance::Detect::INDEX_MSG = T.let(T.unsafe(nil), String)
1081
+
1082
+ # pkg:gem/rubocop-performance#lib/rubocop/cop/performance/detect.rb:38
1083
+ RuboCop::Cop::Performance::Detect::INDEX_REVERSE_MSG = T.let(T.unsafe(nil), String)
1084
+
1085
+ # pkg:gem/rubocop-performance#lib/rubocop/cop/performance/detect.rb:35
1086
+ RuboCop::Cop::Performance::Detect::MSG = T.let(T.unsafe(nil), String)
1087
+
1088
+ # pkg:gem/rubocop-performance#lib/rubocop/cop/performance/detect.rb:39
1089
+ RuboCop::Cop::Performance::Detect::RESTRICT_ON_SEND = T.let(T.unsafe(nil), Array)
1090
+
1091
+ # pkg:gem/rubocop-performance#lib/rubocop/cop/performance/detect.rb:36
1092
+ RuboCop::Cop::Performance::Detect::REVERSE_MSG = T.let(T.unsafe(nil), String)
1093
+
1094
+ # Checks for consecutive `#start_with?` or `#end_with?` calls.
1095
+ # These methods accept multiple arguments, so in some cases like when
1096
+ # they are separated by `||`, they can be combined into a single method call.
1097
+ #
1098
+ # `IncludeActiveSupportAliases` configuration option is used to check for
1099
+ # `starts_with?` and `ends_with?`. These methods are defined by Active Support.
1100
+ #
1101
+ # @example
1102
+ # # bad
1103
+ # str.start_with?("a") || str.start_with?(Some::CONST)
1104
+ # str.start_with?("a", "b") || str.start_with?("c")
1105
+ # !str.start_with?(foo) && !str.start_with?(bar)
1106
+ # str.end_with?(var1) || str.end_with?(var2)
1107
+ #
1108
+ # # good
1109
+ # str.start_with?("a", Some::CONST)
1110
+ # str.start_with?("a", "b", "c")
1111
+ # !str.start_with?(foo, bar)
1112
+ # str.end_with?(var1, var2)
1113
+ #
1114
+ # @example IncludeActiveSupportAliases: false (default)
1115
+ # # good
1116
+ # str.starts_with?("a", "b") || str.starts_with?("c")
1117
+ # str.ends_with?(var1) || str.ends_with?(var2)
1118
+ #
1119
+ # str.starts_with?("a", "b", "c")
1120
+ # str.ends_with?(var1, var2)
1121
+ #
1122
+ # @example IncludeActiveSupportAliases: true
1123
+ # # bad
1124
+ # str.starts_with?("a", "b") || str.starts_with?("c")
1125
+ # str.ends_with?(var1) || str.ends_with?(var2)
1126
+ #
1127
+ # # good
1128
+ # str.starts_with?("a", "b", "c")
1129
+ # str.ends_with?(var1, var2)
1130
+ #
1131
+ # pkg:gem/rubocop-performance#lib/rubocop/cop/performance/double_start_end_with.rb:43
1132
+ class RuboCop::Cop::Performance::DoubleStartEndWith < ::RuboCop::Cop::Base
1133
+ extend ::RuboCop::Cop::AutoCorrector
1134
+
1135
+ # pkg:gem/rubocop-performance#lib/rubocop/cop/performance/double_start_end_with.rb:57
1136
+ def on_and(node); end
1137
+
1138
+ # pkg:gem/rubocop-performance#lib/rubocop/cop/performance/double_start_end_with.rb:51
1139
+ def on_or(node); end
1140
+
1141
+ # pkg:gem/rubocop-performance#lib/rubocop/cop/performance/double_start_end_with.rb:108
1142
+ def two_start_end_with_calls(param0 = T.unsafe(nil), methods_to_check:); end
1143
+
1144
+ # pkg:gem/rubocop-performance#lib/rubocop/cop/performance/double_start_end_with.rb:114
1145
+ def two_start_end_with_calls_negated(param0 = T.unsafe(nil), methods_to_check:); end
1146
+
1147
+ private
1148
+
1149
+ # pkg:gem/rubocop-performance#lib/rubocop/cop/performance/double_start_end_with.rb:75
1150
+ def autocorrect(corrector, first_call_args, second_call_args, combined_args); end
1151
+
1152
+ # pkg:gem/rubocop-performance#lib/rubocop/cop/performance/double_start_end_with.rb:65
1153
+ def check(node, receiver, method, first_call_args, second_call_args); end
1154
+
1155
+ # pkg:gem/rubocop-performance#lib/rubocop/cop/performance/double_start_end_with.rb:104
1156
+ def check_for_active_support_aliases?; end
1157
+
1158
+ # pkg:gem/rubocop-performance#lib/rubocop/cop/performance/double_start_end_with.rb:100
1159
+ def combine_args(first_call_args, second_call_args); end
1160
+
1161
+ # pkg:gem/rubocop-performance#lib/rubocop/cop/performance/double_start_end_with.rb:91
1162
+ def message(node, receiver, method, combined_args); end
1163
+
1164
+ # pkg:gem/rubocop-performance#lib/rubocop/cop/performance/double_start_end_with.rb:83
1165
+ def methods; end
1166
+ end
1167
+
1168
+ # pkg:gem/rubocop-performance#lib/rubocop/cop/performance/double_start_end_with.rb:48
1169
+ RuboCop::Cop::Performance::DoubleStartEndWith::METHODS = T.let(T.unsafe(nil), Set)
1170
+
1171
+ # pkg:gem/rubocop-performance#lib/rubocop/cop/performance/double_start_end_with.rb:49
1172
+ RuboCop::Cop::Performance::DoubleStartEndWith::METHODS_WITH_ACTIVE_SUPPORT = T.let(T.unsafe(nil), Set)
1173
+
1174
+ # pkg:gem/rubocop-performance#lib/rubocop/cop/performance/double_start_end_with.rb:46
1175
+ RuboCop::Cop::Performance::DoubleStartEndWith::MSG = T.let(T.unsafe(nil), String)
1176
+
1177
+ # Identifies unnecessary use of a regex where `String#end_with?` would suffice.
1178
+ #
1179
+ # This cop has `SafeMultiline` configuration option that `true` by default because
1180
+ # `end$` is unsafe as it will behave incompatible with `end_with?`
1181
+ # for receiver is multiline string.
1182
+ #
1183
+ # @safety
1184
+ # This will change to a new method call which isn't guaranteed to be on the
1185
+ # object. Switching these methods has to be done with knowledge of the types
1186
+ # of the variables which rubocop doesn't have.
1187
+ #
1188
+ # @example
1189
+ # # bad
1190
+ # 'abc'.match?(/bc\Z/)
1191
+ # /bc\Z/.match?('abc')
1192
+ # 'abc' =~ /bc\Z/
1193
+ # /bc\Z/ =~ 'abc'
1194
+ # 'abc'.match(/bc\Z/)
1195
+ # /bc\Z/.match('abc')
1196
+ #
1197
+ # # good
1198
+ # 'abc'.end_with?('bc')
1199
+ #
1200
+ # @example SafeMultiline: true (default)
1201
+ #
1202
+ # # good
1203
+ # 'abc'.match?(/bc$/)
1204
+ # /bc$/.match?('abc')
1205
+ # 'abc' =~ /bc$/
1206
+ # /bc$/ =~ 'abc'
1207
+ # 'abc'.match(/bc$/)
1208
+ # /bc$/.match('abc')
1209
+ #
1210
+ # @example SafeMultiline: false
1211
+ #
1212
+ # # bad
1213
+ # 'abc'.match?(/bc$/)
1214
+ # /bc$/.match?('abc')
1215
+ # 'abc' =~ /bc$/
1216
+ # /bc$/ =~ 'abc'
1217
+ # 'abc'.match(/bc$/)
1218
+ # /bc$/.match('abc')
1219
+ #
1220
+ # pkg:gem/rubocop-performance#lib/rubocop/cop/performance/end_with.rb:49
1221
+ class RuboCop::Cop::Performance::EndWith < ::RuboCop::Cop::Base
1222
+ include ::RuboCop::Cop::RegexpMetacharacter
1223
+ extend ::RuboCop::Cop::AutoCorrector
1224
+
1225
+ # pkg:gem/rubocop-performance#lib/rubocop/cop/performance/end_with.rb:77
1226
+ def on_csend(node); end
1227
+
1228
+ # pkg:gem/rubocop-performance#lib/rubocop/cop/performance/end_with.rb:78
1229
+ def on_match_with_lvasgn(node); end
1230
+
1231
+ # pkg:gem/rubocop-performance#lib/rubocop/cop/performance/end_with.rb:63
1232
+ def on_send(node); end
1233
+
1234
+ # pkg:gem/rubocop-performance#lib/rubocop/cop/performance/end_with.rb:56
1235
+ def redundant_regex?(param0 = T.unsafe(nil)); end
1236
+ end
1237
+
1238
+ # pkg:gem/rubocop-performance#lib/rubocop/cop/performance/end_with.rb:53
1239
+ RuboCop::Cop::Performance::EndWith::MSG = T.let(T.unsafe(nil), String)
1240
+
1241
+ # pkg:gem/rubocop-performance#lib/rubocop/cop/performance/end_with.rb:54
1242
+ RuboCop::Cop::Performance::EndWith::RESTRICT_ON_SEND = T.let(T.unsafe(nil), Array)
1243
+
1244
+ # Do not compute the size of statically sized objects.
1245
+ #
1246
+ # @example
1247
+ # # String methods
1248
+ # # bad
1249
+ # 'foo'.size
1250
+ # %q[bar].count
1251
+ # %(qux).length
1252
+ #
1253
+ # # Symbol methods
1254
+ # # bad
1255
+ # :fred.size
1256
+ # :'baz'.length
1257
+ #
1258
+ # # Array methods
1259
+ # # bad
1260
+ # [1, 2, thud].count
1261
+ # %W(1, 2, bar).size
1262
+ #
1263
+ # # Hash methods
1264
+ # # bad
1265
+ # { a: corge, b: grault }.length
1266
+ #
1267
+ # # good
1268
+ # foo.size
1269
+ # bar.count
1270
+ # qux.length
1271
+ #
1272
+ # # good
1273
+ # :"#{fred}".size
1274
+ # CONST = :baz.length
1275
+ #
1276
+ # # good
1277
+ # [1, 2, *thud].count
1278
+ # garply = [1, 2, 3]
1279
+ # garply.size
1280
+ #
1281
+ # # good
1282
+ # { a: corge, **grault }.length
1283
+ # waldo = { a: corge, b: grault }
1284
+ # waldo.size
1285
+ #
1286
+ # pkg:gem/rubocop-performance#lib/rubocop/cop/performance/fixed_size.rb:48
1287
+ class RuboCop::Cop::Performance::FixedSize < ::RuboCop::Cop::Base
1288
+ # pkg:gem/rubocop-performance#lib/rubocop/cop/performance/fixed_size.rb:52
1289
+ def counter(param0 = T.unsafe(nil)); end
1290
+
1291
+ # pkg:gem/rubocop-performance#lib/rubocop/cop/performance/fixed_size.rb:65
1292
+ def on_csend(node); end
1293
+
1294
+ # pkg:gem/rubocop-performance#lib/rubocop/cop/performance/fixed_size.rb:56
1295
+ def on_send(node); end
1296
+
1297
+ private
1298
+
1299
+ # pkg:gem/rubocop-performance#lib/rubocop/cop/performance/fixed_size.rb:73
1300
+ def allowed_argument?(arg); end
1301
+
1302
+ # pkg:gem/rubocop-performance#lib/rubocop/cop/performance/fixed_size.rb:77
1303
+ def allowed_parent?(node); end
1304
+
1305
+ # pkg:gem/rubocop-performance#lib/rubocop/cop/performance/fixed_size.rb:69
1306
+ def allowed_variable?(var); end
1307
+
1308
+ # pkg:gem/rubocop-performance#lib/rubocop/cop/performance/fixed_size.rb:87
1309
+ def contains_double_splat?(node); end
1310
+
1311
+ # pkg:gem/rubocop-performance#lib/rubocop/cop/performance/fixed_size.rb:81
1312
+ def contains_splat?(node); end
1313
+
1314
+ # pkg:gem/rubocop-performance#lib/rubocop/cop/performance/fixed_size.rb:93
1315
+ def non_string_argument?(node); end
1316
+ end
1317
+
1318
+ # pkg:gem/rubocop-performance#lib/rubocop/cop/performance/fixed_size.rb:49
1319
+ RuboCop::Cop::Performance::FixedSize::MSG = T.let(T.unsafe(nil), String)
1320
+
1321
+ # pkg:gem/rubocop-performance#lib/rubocop/cop/performance/fixed_size.rb:50
1322
+ RuboCop::Cop::Performance::FixedSize::RESTRICT_ON_SEND = T.let(T.unsafe(nil), Array)
1323
+
1324
+ # Identifies usages of `map { ... }.flatten` and
1325
+ # change them to use `flat_map { ... }` instead.
1326
+ #
1327
+ # @example
1328
+ # # bad
1329
+ # [1, 2, 3, 4].map { |e| [e, e] }.flatten(1)
1330
+ # [1, 2, 3, 4].collect { |e| [e, e] }.flatten(1)
1331
+ #
1332
+ # # good
1333
+ # [1, 2, 3, 4].flat_map { |e| [e, e] }
1334
+ # [1, 2, 3, 4].map { |e| [e, e] }.flatten
1335
+ # [1, 2, 3, 4].collect { |e| [e, e] }.flatten
1336
+ #
1337
+ # pkg:gem/rubocop-performance#lib/rubocop/cop/performance/flat_map.rb:18
1338
+ class RuboCop::Cop::Performance::FlatMap < ::RuboCop::Cop::Base
1339
+ include ::RuboCop::Cop::RangeHelp
1340
+ extend ::RuboCop::Cop::AutoCorrector
1341
+
1342
+ # pkg:gem/rubocop-performance#lib/rubocop/cop/performance/flat_map.rb:28
1343
+ def flat_map_candidate?(param0 = T.unsafe(nil)); end
1344
+
1345
+ # pkg:gem/rubocop-performance#lib/rubocop/cop/performance/flat_map.rb:49
1346
+ def on_csend(node); end
1347
+
1348
+ # pkg:gem/rubocop-performance#lib/rubocop/cop/performance/flat_map.rb:39
1349
+ def on_send(node); end
1350
+
1351
+ private
1352
+
1353
+ # pkg:gem/rubocop-performance#lib/rubocop/cop/performance/flat_map.rb:73
1354
+ def autocorrect(corrector, node); end
1355
+
1356
+ # pkg:gem/rubocop-performance#lib/rubocop/cop/performance/flat_map.rb:53
1357
+ def offense_for_levels(node, map_node, first_method, flatten); end
1358
+
1359
+ # pkg:gem/rubocop-performance#lib/rubocop/cop/performance/flat_map.rb:59
1360
+ def offense_for_method(node, map_node, first_method, flatten); end
1361
+
1362
+ # pkg:gem/rubocop-performance#lib/rubocop/cop/performance/flat_map.rb:63
1363
+ def register_offense(node, map_node, first_method, flatten, message); end
1364
+ end
1365
+
1366
+ # pkg:gem/rubocop-performance#lib/rubocop/cop/performance/flat_map.rb:24
1367
+ RuboCop::Cop::Performance::FlatMap::FLATTEN_MULTIPLE_LEVELS = T.let(T.unsafe(nil), String)
1368
+
1369
+ # pkg:gem/rubocop-performance#lib/rubocop/cop/performance/flat_map.rb:22
1370
+ RuboCop::Cop::Performance::FlatMap::MSG = T.let(T.unsafe(nil), String)
1371
+
1372
+ # pkg:gem/rubocop-performance#lib/rubocop/cop/performance/flat_map.rb:23
1373
+ RuboCop::Cop::Performance::FlatMap::RESTRICT_ON_SEND = T.let(T.unsafe(nil), Array)
1374
+
1375
+ # Checks for inefficient searching of keys and values within
1376
+ # hashes.
1377
+ #
1378
+ # `Hash#keys.include?` is less efficient than `Hash#key?` because
1379
+ # the former allocates a new array and then performs an O(n) search
1380
+ # through that array, while `Hash#key?` does not allocate any array and
1381
+ # performs a faster O(1) search for the key.
1382
+ #
1383
+ # `Hash#values.include?` is less efficient than `Hash#value?`. While they
1384
+ # both perform an O(n) search through all of the values, calling `values`
1385
+ # allocates a new array while using `value?` does not.
1386
+ #
1387
+ # @safety
1388
+ # This cop is unsafe because it can't tell whether the receiver is a hash object.
1389
+ #
1390
+ # @example
1391
+ # # bad
1392
+ # { a: 1, b: 2 }.keys.include?(:a)
1393
+ # { a: 1, b: 2 }.keys.include?(:z)
1394
+ # h = { a: 1, b: 2 }; h.keys.include?(100)
1395
+ #
1396
+ # # good
1397
+ # { a: 1, b: 2 }.key?(:a)
1398
+ # { a: 1, b: 2 }.has_key?(:z)
1399
+ # h = { a: 1, b: 2 }; h.key?(100)
1400
+ #
1401
+ # # bad
1402
+ # { a: 1, b: 2 }.values.include?(2)
1403
+ # { a: 1, b: 2 }.values.include?('garbage')
1404
+ # h = { a: 1, b: 2 }; h.values.include?(nil)
1405
+ #
1406
+ # # good
1407
+ # { a: 1, b: 2 }.value?(2)
1408
+ # { a: 1, b: 2 }.has_value?('garbage')
1409
+ # h = { a: 1, b: 2 }; h.value?(nil)
1410
+ #
1411
+ # pkg:gem/rubocop-performance#lib/rubocop/cop/performance/inefficient_hash_search.rb:42
1412
+ class RuboCop::Cop::Performance::InefficientHashSearch < ::RuboCop::Cop::Base
1413
+ extend ::RuboCop::Cop::AutoCorrector
1414
+
1415
+ # pkg:gem/rubocop-performance#lib/rubocop/cop/performance/inefficient_hash_search.rb:47
1416
+ def inefficient_include?(param0 = T.unsafe(nil)); end
1417
+
1418
+ # pkg:gem/rubocop-performance#lib/rubocop/cop/performance/inefficient_hash_search.rb:63
1419
+ def on_csend(node); end
1420
+
1421
+ # pkg:gem/rubocop-performance#lib/rubocop/cop/performance/inefficient_hash_search.rb:51
1422
+ def on_send(node); end
1423
+
1424
+ private
1425
+
1426
+ # pkg:gem/rubocop-performance#lib/rubocop/cop/performance/inefficient_hash_search.rb:90
1427
+ def correct_argument(node); end
1428
+
1429
+ # pkg:gem/rubocop-performance#lib/rubocop/cop/performance/inefficient_hash_search.rb:98
1430
+ def correct_dot(node); end
1431
+
1432
+ # pkg:gem/rubocop-performance#lib/rubocop/cop/performance/inefficient_hash_search.rb:94
1433
+ def correct_hash_expression(node); end
1434
+
1435
+ # pkg:gem/rubocop-performance#lib/rubocop/cop/performance/inefficient_hash_search.rb:75
1436
+ def correct_method(node); end
1437
+
1438
+ # pkg:gem/rubocop-performance#lib/rubocop/cop/performance/inefficient_hash_search.rb:82
1439
+ def current_method(node); end
1440
+
1441
+ # pkg:gem/rubocop-performance#lib/rubocop/cop/performance/inefficient_hash_search.rb:67
1442
+ def message(node); end
1443
+
1444
+ # pkg:gem/rubocop-performance#lib/rubocop/cop/performance/inefficient_hash_search.rb:71
1445
+ def replacement(node); end
1446
+
1447
+ # pkg:gem/rubocop-performance#lib/rubocop/cop/performance/inefficient_hash_search.rb:86
1448
+ def use_long_method?; end
1449
+ end
1450
+
1451
+ # pkg:gem/rubocop-performance#lib/rubocop/cop/performance/inefficient_hash_search.rb:45
1452
+ RuboCop::Cop::Performance::InefficientHashSearch::RESTRICT_ON_SEND = T.let(T.unsafe(nil), Array)
1453
+
1454
+ # Identifies places where inefficient `readlines` method
1455
+ # can be replaced by `each_line` to avoid fully loading file content into memory.
1456
+ #
1457
+ # @example
1458
+ #
1459
+ # # bad
1460
+ # File.readlines('testfile').each { |l| puts l }
1461
+ # IO.readlines('testfile', chomp: true).each { |l| puts l }
1462
+ #
1463
+ # conn.readlines(10).map { |l| l.size }
1464
+ # file.readlines.find { |l| l.start_with?('#') }
1465
+ # file.readlines.each { |l| puts l }
1466
+ #
1467
+ # # good
1468
+ # File.open('testfile', 'r').each_line { |l| puts l }
1469
+ # IO.open('testfile').each_line(chomp: true) { |l| puts l }
1470
+ #
1471
+ # conn.each_line(10).map { |l| l.size }
1472
+ # file.each_line.find { |l| l.start_with?('#') }
1473
+ # file.each_line { |l| puts l }
1474
+ #
1475
+ # pkg:gem/rubocop-performance#lib/rubocop/cop/performance/io_readlines.rb:27
1476
+ class RuboCop::Cop::Performance::IoReadlines < ::RuboCop::Cop::Base
1477
+ include ::RuboCop::Cop::RangeHelp
1478
+ extend ::RuboCop::Cop::AutoCorrector
1479
+
1480
+ # pkg:gem/rubocop-performance#lib/rubocop/cop/performance/io_readlines.rb:42
1481
+ def on_send(node); end
1482
+
1483
+ # pkg:gem/rubocop-performance#lib/rubocop/cop/performance/io_readlines.rb:34
1484
+ def readlines_on_class?(param0 = T.unsafe(nil)); end
1485
+
1486
+ # pkg:gem/rubocop-performance#lib/rubocop/cop/performance/io_readlines.rb:38
1487
+ def readlines_on_instance?(param0 = T.unsafe(nil)); end
1488
+
1489
+ private
1490
+
1491
+ # pkg:gem/rubocop-performance#lib/rubocop/cop/performance/io_readlines.rb:58
1492
+ def autocorrect(corrector, enumerable_call, readlines_call, receiver); end
1493
+
1494
+ # pkg:gem/rubocop-performance#lib/rubocop/cop/performance/io_readlines.rb:90
1495
+ def build_bad_method(enumerable_call); end
1496
+
1497
+ # pkg:gem/rubocop-performance#lib/rubocop/cop/performance/io_readlines.rb:106
1498
+ def build_call_args(call_args_node); end
1499
+
1500
+ # pkg:gem/rubocop-performance#lib/rubocop/cop/performance/io_readlines.rb:82
1501
+ def build_good_method(enumerable_call); end
1502
+
1503
+ # pkg:gem/rubocop-performance#lib/rubocop/cop/performance/io_readlines.rb:94
1504
+ def correction_range(enumerable_call, readlines_call); end
1505
+
1506
+ # pkg:gem/rubocop-performance#lib/rubocop/cop/performance/io_readlines.rb:76
1507
+ def offense_range(enumerable_call, readlines_call); end
1508
+ end
1509
+
1510
+ # pkg:gem/rubocop-performance#lib/rubocop/cop/performance/io_readlines.rb:31
1511
+ RuboCop::Cop::Performance::IoReadlines::MSG = T.let(T.unsafe(nil), String)
1512
+
1513
+ # pkg:gem/rubocop-performance#lib/rubocop/cop/performance/io_readlines.rb:32
1514
+ RuboCop::Cop::Performance::IoReadlines::RESTRICT_ON_SEND = T.let(T.unsafe(nil), Array)
1515
+
1516
+ # In Ruby 2.7, `Enumerable#filter_map` has been added.
1517
+ #
1518
+ # This cop identifies places where `map { ... }.compact` can be replaced by `filter_map`.
1519
+ #
1520
+ # @safety
1521
+ # This cop is unsafe because `map { ... }.compact` might yield
1522
+ # different results than `filter_map`. As illustrated in the example, `filter_map`
1523
+ # also filters out falsey values, while `compact` only gets rid of `nil`.
1524
+ #
1525
+ # [source,ruby]
1526
+ # ----
1527
+ # [true, false, nil].compact #=> [true, false]
1528
+ # [true, false, nil].filter_map(&:itself) #=> [true]
1529
+ # ----
1530
+ #
1531
+ # @example
1532
+ # # bad
1533
+ # ary.map(&:foo).compact
1534
+ # ary.collect(&:foo).compact
1535
+ #
1536
+ # # good
1537
+ # ary.filter_map(&:foo)
1538
+ # ary.map(&:foo).compact!
1539
+ # ary.compact.map(&:foo)
1540
+ #
1541
+ # pkg:gem/rubocop-performance#lib/rubocop/cop/performance/map_compact.rb:31
1542
+ class RuboCop::Cop::Performance::MapCompact < ::RuboCop::Cop::Base
1543
+ include ::RuboCop::Cop::RangeHelp
1544
+ extend ::RuboCop::Cop::AutoCorrector
1545
+ extend ::RuboCop::Cop::TargetRubyVersion
1546
+
1547
+ # pkg:gem/rubocop-performance#lib/rubocop/cop/performance/map_compact.rb:41
1548
+ def map_compact(param0 = T.unsafe(nil)); end
1549
+
1550
+ # pkg:gem/rubocop-performance#lib/rubocop/cop/performance/map_compact.rb:65
1551
+ def on_csend(node); end
1552
+
1553
+ # pkg:gem/rubocop-performance#lib/rubocop/cop/performance/map_compact.rb:54
1554
+ def on_send(node); end
1555
+
1556
+ private
1557
+
1558
+ # pkg:gem/rubocop-performance#lib/rubocop/cop/performance/map_compact.rb:95
1559
+ def compact_method_with_final_newline_range(compact_method_range); end
1560
+
1561
+ # pkg:gem/rubocop-performance#lib/rubocop/cop/performance/map_compact.rb:91
1562
+ def invoke_method_after_map_compact_on_same_line?(compact_node, chained_method); end
1563
+
1564
+ # pkg:gem/rubocop-performance#lib/rubocop/cop/performance/map_compact.rb:87
1565
+ def map_method_and_compact_method_on_same_line?(map_node, compact_node); end
1566
+
1567
+ # pkg:gem/rubocop-performance#lib/rubocop/cop/performance/map_compact.rb:69
1568
+ def remove_compact_method(corrector, map_node, compact_node, chained_method); end
1569
+
1570
+ # pkg:gem/rubocop-performance#lib/rubocop/cop/performance/map_compact.rb:83
1571
+ def use_dot?(node); end
1572
+ end
1573
+
1574
+ # pkg:gem/rubocop-performance#lib/rubocop/cop/performance/map_compact.rb:36
1575
+ RuboCop::Cop::Performance::MapCompact::MSG = T.let(T.unsafe(nil), String)
1576
+
1577
+ # pkg:gem/rubocop-performance#lib/rubocop/cop/performance/map_compact.rb:37
1578
+ RuboCop::Cop::Performance::MapCompact::RESTRICT_ON_SEND = T.let(T.unsafe(nil), Array)
1579
+
1580
+ # Checks if the map method is used in a chain.
1581
+ #
1582
+ # Autocorrection is not supported because an appropriate block variable name cannot be determined automatically.
1583
+ #
1584
+ # @safety
1585
+ # This cop is unsafe because false positives occur if the number of times the first method is executed
1586
+ # affects the return value of subsequent methods.
1587
+ #
1588
+ # [source,ruby]
1589
+ # ----
1590
+ # class X
1591
+ # def initialize
1592
+ # @@num = 0
1593
+ # end
1594
+ #
1595
+ # def foo
1596
+ # @@num += 1
1597
+ # self
1598
+ # end
1599
+ #
1600
+ # def bar
1601
+ # @@num * 2
1602
+ # end
1603
+ # end
1604
+ #
1605
+ # [X.new, X.new].map(&:foo).map(&:bar) # => [4, 4]
1606
+ # [X.new, X.new].map { |x| x.foo.bar } # => [2, 4]
1607
+ # ----
1608
+ #
1609
+ # @example
1610
+ #
1611
+ # # bad
1612
+ # array.map(&:foo).map(&:bar)
1613
+ #
1614
+ # # good
1615
+ # array.map { |item| item.foo.bar }
1616
+ #
1617
+ # pkg:gem/rubocop-performance#lib/rubocop/cop/performance/map_method_chain.rb:43
1618
+ class RuboCop::Cop::Performance::MapMethodChain < ::RuboCop::Cop::Base
1619
+ # pkg:gem/rubocop-performance#lib/rubocop/cop/performance/map_method_chain.rb:49
1620
+ def block_pass_with_symbol_arg?(param0 = T.unsafe(nil)); end
1621
+
1622
+ # pkg:gem/rubocop-performance#lib/rubocop/cop/performance/map_method_chain.rb:53
1623
+ def on_send(node); end
1624
+
1625
+ private
1626
+
1627
+ # pkg:gem/rubocop-performance#lib/rubocop/cop/performance/map_method_chain.rb:72
1628
+ def find_begin_of_chained_map_method(node, map_args); end
1629
+ end
1630
+
1631
+ # pkg:gem/rubocop-performance#lib/rubocop/cop/performance/map_method_chain.rb:46
1632
+ RuboCop::Cop::Performance::MapMethodChain::MSG = T.let(T.unsafe(nil), String)
1633
+
1634
+ # pkg:gem/rubocop-performance#lib/rubocop/cop/performance/map_method_chain.rb:47
1635
+ RuboCop::Cop::Performance::MapMethodChain::RESTRICT_ON_SEND = T.let(T.unsafe(nil), Array)
1636
+
1637
+ # Identifies places where methods are converted to blocks, with the
1638
+ # use of `&method`, and passed as arguments to method calls.
1639
+ # It is faster to replace those with explicit blocks, calling those methods inside.
1640
+ #
1641
+ # @example
1642
+ # # bad
1643
+ # array.map(&method(:do_something))
1644
+ # [1, 2, 3].each(&out.method(:puts))
1645
+ #
1646
+ # # good
1647
+ # array.map { |x| do_something(x) }
1648
+ # [1, 2, 3].each { |x| out.puts(x) }
1649
+ #
1650
+ # pkg:gem/rubocop-performance#lib/rubocop/cop/performance/method_object_as_block.rb:19
1651
+ class RuboCop::Cop::Performance::MethodObjectAsBlock < ::RuboCop::Cop::Base
1652
+ # pkg:gem/rubocop-performance#lib/rubocop/cop/performance/method_object_as_block.rb:22
1653
+ def method_object_as_argument?(param0 = T.unsafe(nil)); end
1654
+
1655
+ # pkg:gem/rubocop-performance#lib/rubocop/cop/performance/method_object_as_block.rb:26
1656
+ def on_block_pass(node); end
1657
+ end
1658
+
1659
+ # pkg:gem/rubocop-performance#lib/rubocop/cop/performance/method_object_as_block.rb:20
1660
+ RuboCop::Cop::Performance::MethodObjectAsBlock::MSG = T.let(T.unsafe(nil), String)
1661
+
1662
+ # Checks for `OpenStruct.new` calls.
1663
+ # Instantiation of an `OpenStruct` invalidates
1664
+ # Ruby global method cache as it causes dynamic method
1665
+ # definition during program runtime.
1666
+ # This could have an effect on performance,
1667
+ # especially in case of single-threaded
1668
+ # applications with multiple `OpenStruct` instantiations.
1669
+ #
1670
+ # @safety
1671
+ # This cop is unsafe because `OpenStruct.new` and `Struct.new`
1672
+ # are not equivalent.
1673
+ #
1674
+ # @example
1675
+ # # bad
1676
+ # class MyClass
1677
+ # def my_method
1678
+ # OpenStruct.new(my_key1: 'my_value1', my_key2: 'my_value2')
1679
+ # end
1680
+ # end
1681
+ #
1682
+ # # good
1683
+ # class MyClass
1684
+ # MyStruct = Struct.new(:my_key1, :my_key2)
1685
+ # def my_method
1686
+ # MyStruct.new('my_value1', 'my_value2')
1687
+ # end
1688
+ # end
1689
+ #
1690
+ # pkg:gem/rubocop-performance#lib/rubocop/cop/performance/open_struct.rb:34
1691
+ class RuboCop::Cop::Performance::OpenStruct < ::RuboCop::Cop::Base
1692
+ # pkg:gem/rubocop-performance#lib/rubocop/cop/performance/open_struct.rb:42
1693
+ def on_send(node); end
1694
+
1695
+ # pkg:gem/rubocop-performance#lib/rubocop/cop/performance/open_struct.rb:38
1696
+ def open_struct(param0 = T.unsafe(nil)); end
1697
+ end
1698
+
1699
+ # pkg:gem/rubocop-performance#lib/rubocop/cop/performance/open_struct.rb:35
1700
+ RuboCop::Cop::Performance::OpenStruct::MSG = T.let(T.unsafe(nil), String)
1701
+
1702
+ # pkg:gem/rubocop-performance#lib/rubocop/cop/performance/open_struct.rb:36
1703
+ RuboCop::Cop::Performance::OpenStruct::RESTRICT_ON_SEND = T.let(T.unsafe(nil), Array)
1704
+
1705
+ # Identifies uses of `Range#include?` and `Range#member?`, which iterates over each
1706
+ # item in a `Range` to see if a specified item is there. In contrast,
1707
+ # `Range#cover?` simply compares the target item with the beginning and
1708
+ # end points of the `Range`. In a great majority of cases, this is what
1709
+ # is wanted.
1710
+ #
1711
+ # @safety
1712
+ # This cop is unsafe because `Range#include?` (or `Range#member?`) and `Range#cover?`
1713
+ # are not equivalent behavior.
1714
+ # Example of a case where `Range#cover?` may not provide the desired result:
1715
+ #
1716
+ # [source,ruby]
1717
+ # ----
1718
+ # ('a'..'z').cover?('yellow') # => true
1719
+ # ----
1720
+ #
1721
+ # @example
1722
+ # # bad
1723
+ # ('a'..'z').include?('b') # => true
1724
+ # ('a'..'z').member?('b') # => true
1725
+ #
1726
+ # # good
1727
+ # ('a'..'z').cover?('b') # => true
1728
+ #
1729
+ # pkg:gem/rubocop-performance#lib/rubocop/cop/performance/range_include.rb:29
1730
+ class RuboCop::Cop::Performance::RangeInclude < ::RuboCop::Cop::Base
1731
+ extend ::RuboCop::Cop::AutoCorrector
1732
+
1733
+ # pkg:gem/rubocop-performance#lib/rubocop/cop/performance/range_include.rb:53
1734
+ def on_csend(node); end
1735
+
1736
+ # pkg:gem/rubocop-performance#lib/rubocop/cop/performance/range_include.rb:44
1737
+ def on_send(node); end
1738
+
1739
+ # pkg:gem/rubocop-performance#lib/rubocop/cop/performance/range_include.rb:40
1740
+ def range_include(param0 = T.unsafe(nil)); end
1741
+ end
1742
+
1743
+ # pkg:gem/rubocop-performance#lib/rubocop/cop/performance/range_include.rb:32
1744
+ RuboCop::Cop::Performance::RangeInclude::MSG = T.let(T.unsafe(nil), String)
1745
+
1746
+ # pkg:gem/rubocop-performance#lib/rubocop/cop/performance/range_include.rb:33
1747
+ RuboCop::Cop::Performance::RangeInclude::RESTRICT_ON_SEND = T.let(T.unsafe(nil), Array)
1748
+
1749
+ # Identifies the use of a `&block` parameter and `block.call`
1750
+ # where `yield` would do just as well.
1751
+ #
1752
+ # @example
1753
+ # # bad
1754
+ # def method(&block)
1755
+ # block.call
1756
+ # end
1757
+ # def another(&func)
1758
+ # func.call 1, 2, 3
1759
+ # end
1760
+ #
1761
+ # # good
1762
+ # def method
1763
+ # yield
1764
+ # end
1765
+ # def another
1766
+ # yield 1, 2, 3
1767
+ # end
1768
+ #
1769
+ # pkg:gem/rubocop-performance#lib/rubocop/cop/performance/redundant_block_call.rb:25
1770
+ class RuboCop::Cop::Performance::RedundantBlockCall < ::RuboCop::Cop::Base
1771
+ extend ::RuboCop::Cop::AutoCorrector
1772
+
1773
+ # pkg:gem/rubocop-performance#lib/rubocop/cop/performance/redundant_block_call.rb:43
1774
+ def blockarg_assigned?(param0, param1); end
1775
+
1776
+ # pkg:gem/rubocop-performance#lib/rubocop/cop/performance/redundant_block_call.rb:39
1777
+ def blockarg_calls(param0, param1); end
1778
+
1779
+ # pkg:gem/rubocop-performance#lib/rubocop/cop/performance/redundant_block_call.rb:34
1780
+ def blockarg_def(param0 = T.unsafe(nil)); end
1781
+
1782
+ # pkg:gem/rubocop-performance#lib/rubocop/cop/performance/redundant_block_call.rb:47
1783
+ def on_def(node); end
1784
+
1785
+ # pkg:gem/rubocop-performance#lib/rubocop/cop/performance/redundant_block_call.rb:60
1786
+ def on_defs(node); end
1787
+
1788
+ private
1789
+
1790
+ # pkg:gem/rubocop-performance#lib/rubocop/cop/performance/redundant_block_call.rb:99
1791
+ def args_include_block_pass?(blockcall); end
1792
+
1793
+ # offenses are registered on the `block.call` nodes
1794
+ #
1795
+ # pkg:gem/rubocop-performance#lib/rubocop/cop/performance/redundant_block_call.rb:65
1796
+ def autocorrect(corrector, node); end
1797
+
1798
+ # pkg:gem/rubocop-performance#lib/rubocop/cop/performance/redundant_block_call.rb:83
1799
+ def calls_to_report(argname, body); end
1800
+
1801
+ # pkg:gem/rubocop-performance#lib/rubocop/cop/performance/redundant_block_call.rb:93
1802
+ def shadowed_block_argument?(body, block_argument_of_method_signature); end
1803
+ end
1804
+
1805
+ # pkg:gem/rubocop-performance#lib/rubocop/cop/performance/redundant_block_call.rb:31
1806
+ RuboCop::Cop::Performance::RedundantBlockCall::CLOSE_PAREN = T.let(T.unsafe(nil), String)
1807
+
1808
+ # pkg:gem/rubocop-performance#lib/rubocop/cop/performance/redundant_block_call.rb:28
1809
+ RuboCop::Cop::Performance::RedundantBlockCall::MSG = T.let(T.unsafe(nil), String)
1810
+
1811
+ # pkg:gem/rubocop-performance#lib/rubocop/cop/performance/redundant_block_call.rb:30
1812
+ RuboCop::Cop::Performance::RedundantBlockCall::OPEN_PAREN = T.let(T.unsafe(nil), String)
1813
+
1814
+ # pkg:gem/rubocop-performance#lib/rubocop/cop/performance/redundant_block_call.rb:32
1815
+ RuboCop::Cop::Performance::RedundantBlockCall::SPACE = T.let(T.unsafe(nil), String)
1816
+
1817
+ # pkg:gem/rubocop-performance#lib/rubocop/cop/performance/redundant_block_call.rb:29
1818
+ RuboCop::Cop::Performance::RedundantBlockCall::YIELD = T.let(T.unsafe(nil), String)
1819
+
1820
+ # Checks for uses `Enumerable#all?`, `Enumerable#any?`, `Enumerable#one?`,
1821
+ # and `Enumerable#none?` are compared with `===` or similar methods in block.
1822
+ #
1823
+ # By default, `Object#===` behaves the same as `Object#==`, but this
1824
+ # behavior is appropriately overridden in subclass. For example,
1825
+ # `Range#===` returns `true` when argument is within the range.
1826
+ #
1827
+ # This cop has `AllowRegexpMatch` option and it is true by default because
1828
+ # `regexp.match?('string')` often used in block changes to the opposite result:
1829
+ #
1830
+ # [source,ruby]
1831
+ # ----
1832
+ # [/pattern/].all? { |regexp| regexp.match?('pattern') } # => true
1833
+ # [/pattern/].all? { |regexp| regexp =~ 'pattern' } # => true
1834
+ # [/pattern/].all?('pattern') # => false
1835
+ # ----
1836
+ #
1837
+ # @safety
1838
+ # This cop is unsafe because `===` and `==` do not always behave the same.
1839
+ #
1840
+ # @example
1841
+ # # bad
1842
+ # items.all? { |item| pattern === item }
1843
+ # items.all? { |item| item == other }
1844
+ # items.all? { |item| item.is_a?(Klass) }
1845
+ # items.all? { |item| item.kind_of?(Klass) }
1846
+ #
1847
+ # # good
1848
+ # items.all?(pattern)
1849
+ # items.all?(Klass)
1850
+ #
1851
+ # @example AllowRegexpMatch: true (default)
1852
+ #
1853
+ # # good
1854
+ # items.all? { |item| item =~ pattern }
1855
+ # items.all? { |item| item.match?(pattern) }
1856
+ #
1857
+ # @example AllowRegexpMatch: false
1858
+ #
1859
+ # # bad
1860
+ # items.all? { |item| item =~ pattern }
1861
+ # items.all? { |item| item.match?(pattern) }
1862
+ #
1863
+ # pkg:gem/rubocop-performance#lib/rubocop/cop/performance/redundant_equality_comparison_block.rb:49
1864
+ class RuboCop::Cop::Performance::RedundantEqualityComparisonBlock < ::RuboCop::Cop::Base
1865
+ extend ::RuboCop::Cop::AutoCorrector
1866
+ extend ::RuboCop::Cop::TargetRubyVersion
1867
+
1868
+ # pkg:gem/rubocop-performance#lib/rubocop/cop/performance/redundant_equality_comparison_block.rb:62
1869
+ def on_block(node); end
1870
+
1871
+ private
1872
+
1873
+ # pkg:gem/rubocop-performance#lib/rubocop/cop/performance/redundant_equality_comparison_block.rb:131
1874
+ def allow_regexp_match?; end
1875
+
1876
+ # pkg:gem/rubocop-performance#lib/rubocop/cop/performance/redundant_equality_comparison_block.rb:104
1877
+ def new_argument(block_argument, block_body); end
1878
+
1879
+ # pkg:gem/rubocop-performance#lib/rubocop/cop/performance/redundant_equality_comparison_block.rb:127
1880
+ def offense_range(node); end
1881
+
1882
+ # pkg:gem/rubocop-performance#lib/rubocop/cop/performance/redundant_equality_comparison_block.rb:82
1883
+ def one_block_argument?(block_arguments); end
1884
+
1885
+ # pkg:gem/rubocop-performance#lib/rubocop/cop/performance/redundant_equality_comparison_block.rb:94
1886
+ def same_block_argument_and_is_a_argument?(block_body, block_argument); end
1887
+
1888
+ # pkg:gem/rubocop-performance#lib/rubocop/cop/performance/redundant_equality_comparison_block.rb:118
1889
+ def use_block_argument_in_method_argument_of_operand?(block_argument, operand); end
1890
+
1891
+ # pkg:gem/rubocop-performance#lib/rubocop/cop/performance/redundant_equality_comparison_block.rb:86
1892
+ def use_equality_comparison_block?(block_body); end
1893
+ end
1894
+
1895
+ # pkg:gem/rubocop-performance#lib/rubocop/cop/performance/redundant_equality_comparison_block.rb:58
1896
+ RuboCop::Cop::Performance::RedundantEqualityComparisonBlock::COMPARISON_METHODS = T.let(T.unsafe(nil), Array)
1897
+
1898
+ # pkg:gem/rubocop-performance#lib/rubocop/cop/performance/redundant_equality_comparison_block.rb:60
1899
+ RuboCop::Cop::Performance::RedundantEqualityComparisonBlock::IS_A_METHODS = T.let(T.unsafe(nil), Array)
1900
+
1901
+ # pkg:gem/rubocop-performance#lib/rubocop/cop/performance/redundant_equality_comparison_block.rb:55
1902
+ RuboCop::Cop::Performance::RedundantEqualityComparisonBlock::MSG = T.let(T.unsafe(nil), String)
1903
+
1904
+ # pkg:gem/rubocop-performance#lib/rubocop/cop/performance/redundant_equality_comparison_block.rb:59
1905
+ RuboCop::Cop::Performance::RedundantEqualityComparisonBlock::REGEXP_METHODS = T.let(T.unsafe(nil), Array)
1906
+
1907
+ # pkg:gem/rubocop-performance#lib/rubocop/cop/performance/redundant_equality_comparison_block.rb:57
1908
+ RuboCop::Cop::Performance::RedundantEqualityComparisonBlock::TARGET_METHODS = T.let(T.unsafe(nil), Array)
1909
+
1910
+ # Identifies the use of `Regexp#match` or `String#match`, which
1911
+ # returns `#<MatchData>`/`nil`. The return value of `=~` is an integral
1912
+ # index/`nil` and is more performant.
1913
+ #
1914
+ # @example
1915
+ # # bad
1916
+ # do_something if str.match(/regex/)
1917
+ # while regex.match('str')
1918
+ # do_something
1919
+ # end
1920
+ #
1921
+ # # good
1922
+ # method(str =~ /regex/)
1923
+ # return value unless regex =~ 'str'
1924
+ #
1925
+ # pkg:gem/rubocop-performance#lib/rubocop/cop/performance/redundant_match.rb:20
1926
+ class RuboCop::Cop::Performance::RedundantMatch < ::RuboCop::Cop::Base
1927
+ extend ::RuboCop::Cop::AutoCorrector
1928
+
1929
+ # pkg:gem/rubocop-performance#lib/rubocop/cop/performance/redundant_match.rb:30
1930
+ def match_call?(param0 = T.unsafe(nil)); end
1931
+
1932
+ # pkg:gem/rubocop-performance#lib/rubocop/cop/performance/redundant_match.rb:39
1933
+ def on_send(node); end
1934
+
1935
+ # pkg:gem/rubocop-performance#lib/rubocop/cop/performance/redundant_match.rb:35
1936
+ def only_truthiness_matters?(param0 = T.unsafe(nil)); end
1937
+
1938
+ private
1939
+
1940
+ # pkg:gem/rubocop-performance#lib/rubocop/cop/performance/redundant_match.rb:51
1941
+ def autocorrect(corrector, node); end
1942
+
1943
+ # pkg:gem/rubocop-performance#lib/rubocop/cop/performance/redundant_match.rb:57
1944
+ def autocorrectable?(node); end
1945
+
1946
+ # pkg:gem/rubocop-performance#lib/rubocop/cop/performance/redundant_match.rb:86
1947
+ def call_like?(arg); end
1948
+
1949
+ # pkg:gem/rubocop-performance#lib/rubocop/cop/performance/redundant_match.rb:63
1950
+ def replacement(node); end
1951
+
1952
+ # pkg:gem/rubocop-performance#lib/rubocop/cop/performance/redundant_match.rb:73
1953
+ def requires_parentheses?(arg); end
1954
+
1955
+ # pkg:gem/rubocop-performance#lib/rubocop/cop/performance/redundant_match.rb:80
1956
+ def requires_parentheses_for_call_like?(arg); end
1957
+ end
1958
+
1959
+ # pkg:gem/rubocop-performance#lib/rubocop/cop/performance/redundant_match.rb:26
1960
+ RuboCop::Cop::Performance::RedundantMatch::HIGHER_PRECEDENCE_OPERATOR_METHODS = T.let(T.unsafe(nil), Array)
1961
+
1962
+ # pkg:gem/rubocop-performance#lib/rubocop/cop/performance/redundant_match.rb:23
1963
+ RuboCop::Cop::Performance::RedundantMatch::MSG = T.let(T.unsafe(nil), String)
1964
+
1965
+ # pkg:gem/rubocop-performance#lib/rubocop/cop/performance/redundant_match.rb:24
1966
+ RuboCop::Cop::Performance::RedundantMatch::RESTRICT_ON_SEND = T.let(T.unsafe(nil), Array)
1967
+
1968
+ # Identifies places where `Hash#merge!` can be replaced by `Hash#[]=`.
1969
+ # You can set the maximum number of key-value pairs to consider
1970
+ # an offense with `MaxKeyValuePairs`.
1971
+ #
1972
+ # @safety
1973
+ # This cop is unsafe because RuboCop cannot determine if the
1974
+ # receiver of `merge!` is actually a hash or not.
1975
+ #
1976
+ # @example
1977
+ # # bad
1978
+ # hash.merge!(a: 1)
1979
+ # hash.merge!({'key' => 'value'})
1980
+ #
1981
+ # # good
1982
+ # hash[:a] = 1
1983
+ # hash['key'] = 'value'
1984
+ #
1985
+ # @example MaxKeyValuePairs: 2 (default)
1986
+ # # bad
1987
+ # hash.merge!(a: 1, b: 2)
1988
+ #
1989
+ # # good
1990
+ # hash[:a] = 1
1991
+ # hash[:b] = 2
1992
+ #
1993
+ # pkg:gem/rubocop-performance#lib/rubocop/cop/performance/redundant_merge.rb:30
1994
+ class RuboCop::Cop::Performance::RedundantMerge < ::RuboCop::Cop::Base
1995
+ include ::RuboCop::Cop::Alignment
1996
+ extend ::RuboCop::Cop::AutoCorrector
1997
+
1998
+ # pkg:gem/rubocop-performance#lib/rubocop/cop/performance/redundant_merge.rb:48
1999
+ def modifier_flow_control?(param0 = T.unsafe(nil)); end
2000
+
2001
+ # pkg:gem/rubocop-performance#lib/rubocop/cop/performance/redundant_merge.rb:52
2002
+ def on_send(node); end
2003
+
2004
+ # pkg:gem/rubocop-performance#lib/rubocop/cop/performance/redundant_merge.rb:44
2005
+ def redundant_merge_candidate(param0 = T.unsafe(nil)); end
2006
+
2007
+ private
2008
+
2009
+ # pkg:gem/rubocop-performance#lib/rubocop/cop/performance/redundant_merge.rb:106
2010
+ def correct_multiple_elements(corrector, node, parent, new_source); end
2011
+
2012
+ # pkg:gem/rubocop-performance#lib/rubocop/cop/performance/redundant_merge.rb:118
2013
+ def correct_single_element(corrector, node, new_source); end
2014
+
2015
+ # pkg:gem/rubocop-performance#lib/rubocop/cop/performance/redundant_merge.rb:79
2016
+ def each_redundant_merge(node); end
2017
+
2018
+ # pkg:gem/rubocop-performance#lib/rubocop/cop/performance/redundant_merge.rb:98
2019
+ def kwsplat_used?(pairs); end
2020
+
2021
+ # pkg:gem/rubocop-performance#lib/rubocop/cop/performance/redundant_merge.rb:144
2022
+ def leading_spaces(node); end
2023
+
2024
+ # pkg:gem/rubocop-performance#lib/rubocop/cop/performance/redundant_merge.rb:148
2025
+ def max_key_value_pairs; end
2026
+
2027
+ # pkg:gem/rubocop-performance#lib/rubocop/cop/performance/redundant_merge.rb:71
2028
+ def message(node); end
2029
+
2030
+ # pkg:gem/rubocop-performance#lib/rubocop/cop/performance/redundant_merge.rb:87
2031
+ def non_redundant_merge?(node, receiver, pairs); end
2032
+
2033
+ # pkg:gem/rubocop-performance#lib/rubocop/cop/performance/redundant_merge.rb:94
2034
+ def non_redundant_pairs?(receiver, pairs); end
2035
+
2036
+ # pkg:gem/rubocop-performance#lib/rubocop/cop/performance/redundant_merge.rb:102
2037
+ def non_redundant_value_used?(receiver, node); end
2038
+
2039
+ # pkg:gem/rubocop-performance#lib/rubocop/cop/performance/redundant_merge.rb:132
2040
+ def rewrite_with_modifier(node, parent, new_source); end
2041
+
2042
+ # pkg:gem/rubocop-performance#lib/rubocop/cop/performance/redundant_merge.rb:122
2043
+ def to_assignments(receiver, pairs); end
2044
+ end
2045
+
2046
+ # pkg:gem/rubocop-performance#lib/rubocop/cop/performance/redundant_merge.rb:34
2047
+ RuboCop::Cop::Performance::RedundantMerge::AREF_ASGN = T.let(T.unsafe(nil), String)
2048
+
2049
+ # A utility class for checking the use of values within an
2050
+ # `each_with_object` call.
2051
+ #
2052
+ # pkg:gem/rubocop-performance#lib/rubocop/cop/performance/redundant_merge.rb:154
2053
+ class RuboCop::Cop::Performance::RedundantMerge::EachWithObjectInspector
2054
+ extend ::RuboCop::AST::NodePattern::Macros
2055
+
2056
+ # pkg:gem/rubocop-performance#lib/rubocop/cop/performance/redundant_merge.rb:157
2057
+ def initialize(node, receiver); end
2058
+
2059
+ # pkg:gem/rubocop-performance#lib/rubocop/cop/performance/redundant_merge.rb:188
2060
+ def each_with_object_node(param0 = T.unsafe(nil)); end
2061
+
2062
+ # pkg:gem/rubocop-performance#lib/rubocop/cop/performance/redundant_merge.rb:162
2063
+ def value_used?; end
2064
+
2065
+ private
2066
+
2067
+ # pkg:gem/rubocop-performance#lib/rubocop/cop/performance/redundant_merge.rb:172
2068
+ def eligible_receiver?; end
2069
+
2070
+ # pkg:gem/rubocop-performance#lib/rubocop/cop/performance/redundant_merge.rb:170
2071
+ def node; end
2072
+
2073
+ # pkg:gem/rubocop-performance#lib/rubocop/cop/performance/redundant_merge.rb:170
2074
+ def receiver; end
2075
+
2076
+ # pkg:gem/rubocop-performance#lib/rubocop/cop/performance/redundant_merge.rb:176
2077
+ def second_argument; end
2078
+
2079
+ # pkg:gem/rubocop-performance#lib/rubocop/cop/performance/redundant_merge.rb:183
2080
+ def unwind(receiver); end
2081
+ end
2082
+
2083
+ # pkg:gem/rubocop-performance#lib/rubocop/cop/performance/redundant_merge.rb:35
2084
+ RuboCop::Cop::Performance::RedundantMerge::MSG = T.let(T.unsafe(nil), String)
2085
+
2086
+ # pkg:gem/rubocop-performance#lib/rubocop/cop/performance/redundant_merge.rb:36
2087
+ RuboCop::Cop::Performance::RedundantMerge::RESTRICT_ON_SEND = T.let(T.unsafe(nil), Array)
2088
+
2089
+ # pkg:gem/rubocop-performance#lib/rubocop/cop/performance/redundant_merge.rb:38
2090
+ RuboCop::Cop::Performance::RedundantMerge::WITH_MODIFIER_CORRECTION = T.let(T.unsafe(nil), String)
2091
+
2092
+ # Identifies places where `sort { |a, b| a <=> b }` can be replaced with `sort`.
2093
+ #
2094
+ # @example
2095
+ # # bad
2096
+ # array.sort { |a, b| a <=> b }
2097
+ #
2098
+ # # good
2099
+ # array.sort
2100
+ #
2101
+ # pkg:gem/rubocop-performance#lib/rubocop/cop/performance/redundant_sort_block.rb:15
2102
+ class RuboCop::Cop::Performance::RedundantSortBlock < ::RuboCop::Cop::Base
2103
+ include ::RuboCop::Cop::RangeHelp
2104
+ include ::RuboCop::Cop::SortBlock
2105
+ extend ::RuboCop::Cop::AutoCorrector
2106
+
2107
+ # pkg:gem/rubocop-performance#lib/rubocop/cop/performance/redundant_sort_block.rb:21
2108
+ def on_block(node); end
2109
+
2110
+ # pkg:gem/rubocop-performance#lib/rubocop/cop/performance/redundant_sort_block.rb:29
2111
+ def on_numblock(node); end
2112
+
2113
+ private
2114
+
2115
+ # pkg:gem/rubocop-performance#lib/rubocop/cop/performance/redundant_sort_block.rb:40
2116
+ def register_offense(send, node); end
2117
+ end
2118
+
2119
+ # pkg:gem/rubocop-performance#lib/rubocop/cop/performance/redundant_sort_block.rb:19
2120
+ RuboCop::Cop::Performance::RedundantSortBlock::MSG = T.let(T.unsafe(nil), String)
2121
+
2122
+ # Identifies places where `split` argument can be replaced from
2123
+ # a deterministic regexp to a string.
2124
+ #
2125
+ # @example
2126
+ # # bad
2127
+ # 'a,b,c'.split(/,/)
2128
+ #
2129
+ # # good
2130
+ # 'a,b,c'.split(',')
2131
+ #
2132
+ # pkg:gem/rubocop-performance#lib/rubocop/cop/performance/redundant_split_regexp_argument.rb:15
2133
+ class RuboCop::Cop::Performance::RedundantSplitRegexpArgument < ::RuboCop::Cop::Base
2134
+ extend ::RuboCop::Cop::AutoCorrector
2135
+
2136
+ # pkg:gem/rubocop-performance#lib/rubocop/cop/performance/redundant_split_regexp_argument.rb:38
2137
+ def on_csend(node); end
2138
+
2139
+ # pkg:gem/rubocop-performance#lib/rubocop/cop/performance/redundant_split_regexp_argument.rb:27
2140
+ def on_send(node); end
2141
+
2142
+ # pkg:gem/rubocop-performance#lib/rubocop/cop/performance/redundant_split_regexp_argument.rb:23
2143
+ def split_call_with_regexp?(param0 = T.unsafe(nil)); end
2144
+
2145
+ private
2146
+
2147
+ # pkg:gem/rubocop-performance#lib/rubocop/cop/performance/redundant_split_regexp_argument.rb:42
2148
+ def determinist_regexp?(regexp_node); end
2149
+
2150
+ # pkg:gem/rubocop-performance#lib/rubocop/cop/performance/redundant_split_regexp_argument.rb:46
2151
+ def replacement(regexp_node); end
2152
+ end
2153
+
2154
+ # pkg:gem/rubocop-performance#lib/rubocop/cop/performance/redundant_split_regexp_argument.rb:20
2155
+ RuboCop::Cop::Performance::RedundantSplitRegexpArgument::DETERMINISTIC_REGEX = T.let(T.unsafe(nil), Regexp)
2156
+
2157
+ # pkg:gem/rubocop-performance#lib/rubocop/cop/performance/redundant_split_regexp_argument.rb:18
2158
+ RuboCop::Cop::Performance::RedundantSplitRegexpArgument::MSG = T.let(T.unsafe(nil), String)
2159
+
2160
+ # pkg:gem/rubocop-performance#lib/rubocop/cop/performance/redundant_split_regexp_argument.rb:19
2161
+ RuboCop::Cop::Performance::RedundantSplitRegexpArgument::RESTRICT_ON_SEND = T.let(T.unsafe(nil), Array)
2162
+
2163
+ # pkg:gem/rubocop-performance#lib/rubocop/cop/performance/redundant_split_regexp_argument.rb:21
2164
+ RuboCop::Cop::Performance::RedundantSplitRegexpArgument::STR_SPECIAL_CHARS = T.let(T.unsafe(nil), Array)
2165
+
2166
+ # Checks for redundant `String#chars`.
2167
+ #
2168
+ # @example
2169
+ # # bad
2170
+ # str.chars[0..2]
2171
+ # str.chars.slice(0..2)
2172
+ # str.chars.last
2173
+ #
2174
+ # # good
2175
+ # str[0..2].chars
2176
+ #
2177
+ # # bad
2178
+ # str.chars.first
2179
+ # str.chars.first(2)
2180
+ #
2181
+ # # good
2182
+ # str[0]
2183
+ # str[0...2].chars
2184
+ # str[-1]
2185
+ #
2186
+ # # bad
2187
+ # str.chars.take(2)
2188
+ # str.chars.length
2189
+ # str.chars.size
2190
+ # str.chars.empty?
2191
+ #
2192
+ # # good
2193
+ # str[0...2].chars
2194
+ # str.length
2195
+ # str.size
2196
+ # str.empty?
2197
+ #
2198
+ # # For example, if the receiver is an empty string, it will be incompatible.
2199
+ # # If a negative value is specified for the receiver, `nil` is returned.
2200
+ # str.chars.last(2) # Incompatible with `str[-2..-1].chars`.
2201
+ # str.chars.drop(2) # Incompatible with `str[2..-1].chars`.
2202
+ #
2203
+ # pkg:gem/rubocop-performance#lib/rubocop/cop/performance/redundant_string_chars.rb:43
2204
+ class RuboCop::Cop::Performance::RedundantStringChars < ::RuboCop::Cop::Base
2205
+ include ::RuboCop::Cop::RangeHelp
2206
+ extend ::RuboCop::Cop::AutoCorrector
2207
+
2208
+ # pkg:gem/rubocop-performance#lib/rubocop/cop/performance/redundant_string_chars.rb:54
2209
+ def on_send(node); end
2210
+
2211
+ # pkg:gem/rubocop-performance#lib/rubocop/cop/performance/redundant_string_chars.rb:50
2212
+ def redundant_chars_call?(param0 = T.unsafe(nil)); end
2213
+
2214
+ private
2215
+
2216
+ # pkg:gem/rubocop-performance#lib/rubocop/cop/performance/redundant_string_chars.rb:113
2217
+ def build_bad_method(method, args); end
2218
+
2219
+ # pkg:gem/rubocop-performance#lib/rubocop/cop/performance/redundant_string_chars.rb:126
2220
+ def build_call_args(call_args_node); end
2221
+
2222
+ # pkg:gem/rubocop-performance#lib/rubocop/cop/performance/redundant_string_chars.rb:86
2223
+ def build_good_method(method, args); end
2224
+
2225
+ # pkg:gem/rubocop-performance#lib/rubocop/cop/performance/redundant_string_chars.rb:101
2226
+ def build_good_method_for_brackets_or_first_method(method, args); end
2227
+
2228
+ # pkg:gem/rubocop-performance#lib/rubocop/cop/performance/redundant_string_chars.rb:80
2229
+ def build_message(method, args); end
2230
+
2231
+ # pkg:gem/rubocop-performance#lib/rubocop/cop/performance/redundant_string_chars.rb:76
2232
+ def correction_range(receiver, node); end
2233
+
2234
+ # pkg:gem/rubocop-performance#lib/rubocop/cop/performance/redundant_string_chars.rb:72
2235
+ def offense_range(receiver, node); end
2236
+ end
2237
+
2238
+ # pkg:gem/rubocop-performance#lib/rubocop/cop/performance/redundant_string_chars.rb:47
2239
+ RuboCop::Cop::Performance::RedundantStringChars::MSG = T.let(T.unsafe(nil), String)
2240
+
2241
+ # pkg:gem/rubocop-performance#lib/rubocop/cop/performance/redundant_string_chars.rb:48
2242
+ RuboCop::Cop::Performance::RedundantStringChars::RESTRICT_ON_SEND = T.let(T.unsafe(nil), Array)
2243
+
2244
+ # In Ruby 2.4, `String#match?`, `Regexp#match?`, and `Symbol#match?`
2245
+ # have been added. The methods are faster than `match`.
2246
+ # Because the methods avoid creating a `MatchData` object or saving
2247
+ # backref.
2248
+ # So, when `MatchData` is not used, use `match?` instead of `match`.
2249
+ #
2250
+ # @example
2251
+ # # bad
2252
+ # def foo
2253
+ # if x =~ /re/
2254
+ # do_something
2255
+ # end
2256
+ # end
2257
+ #
2258
+ # # bad
2259
+ # def foo
2260
+ # if x !~ /re/
2261
+ # do_something
2262
+ # end
2263
+ # end
2264
+ #
2265
+ # # bad
2266
+ # def foo
2267
+ # if x.match(/re/)
2268
+ # do_something
2269
+ # end
2270
+ # end
2271
+ #
2272
+ # # bad
2273
+ # def foo
2274
+ # if /re/ === x
2275
+ # do_something
2276
+ # end
2277
+ # end
2278
+ #
2279
+ # # good
2280
+ # def foo
2281
+ # if x.match?(/re/)
2282
+ # do_something
2283
+ # end
2284
+ # end
2285
+ #
2286
+ # # good
2287
+ # def foo
2288
+ # if !x.match?(/re/)
2289
+ # do_something
2290
+ # end
2291
+ # end
2292
+ #
2293
+ # # good
2294
+ # def foo
2295
+ # if x =~ /re/
2296
+ # do_something(Regexp.last_match)
2297
+ # end
2298
+ # end
2299
+ #
2300
+ # # good
2301
+ # def foo
2302
+ # if x.match(/re/)
2303
+ # do_something($~)
2304
+ # end
2305
+ # end
2306
+ #
2307
+ # # good
2308
+ # def foo
2309
+ # if /re/ === x
2310
+ # do_something($~)
2311
+ # end
2312
+ # end
2313
+ #
2314
+ # pkg:gem/rubocop-performance#lib/rubocop/cop/performance/regexp_match.rb:75
2315
+ class RuboCop::Cop::Performance::RegexpMatch < ::RuboCop::Cop::Base
2316
+ extend ::RuboCop::Cop::AutoCorrector
2317
+ extend ::RuboCop::Cop::TargetRubyVersion
2318
+
2319
+ # pkg:gem/rubocop-performance#lib/rubocop/cop/performance/regexp_match.rb:125
2320
+ def last_matches(param0); end
2321
+
2322
+ # pkg:gem/rubocop-performance#lib/rubocop/cop/performance/regexp_match.rb:86
2323
+ def match_method?(param0 = T.unsafe(nil)); end
2324
+
2325
+ # pkg:gem/rubocop-performance#lib/rubocop/cop/performance/regexp_match.rb:122
2326
+ def match_node?(param0 = T.unsafe(nil)); end
2327
+
2328
+ # pkg:gem/rubocop-performance#lib/rubocop/cop/performance/regexp_match.rb:97
2329
+ def match_operator?(param0 = T.unsafe(nil)); end
2330
+
2331
+ # pkg:gem/rubocop-performance#lib/rubocop/cop/performance/regexp_match.rb:101
2332
+ def match_threequals?(param0 = T.unsafe(nil)); end
2333
+
2334
+ # pkg:gem/rubocop-performance#lib/rubocop/cop/performance/regexp_match.rb:93
2335
+ def match_with_int_arg_method?(param0 = T.unsafe(nil)); end
2336
+
2337
+ # pkg:gem/rubocop-performance#lib/rubocop/cop/performance/regexp_match.rb:105
2338
+ def match_with_lvasgn?(node); end
2339
+
2340
+ # pkg:gem/rubocop-performance#lib/rubocop/cop/performance/regexp_match.rb:142
2341
+ def on_case(node); end
2342
+
2343
+ # pkg:gem/rubocop-performance#lib/rubocop/cop/performance/regexp_match.rb:138
2344
+ def on_if(node); end
2345
+
2346
+ # pkg:gem/rubocop-performance#lib/rubocop/cop/performance/regexp_match.rb:123
2347
+ def search_match_nodes(param0); end
2348
+
2349
+ private
2350
+
2351
+ # pkg:gem/rubocop-performance#lib/rubocop/cop/performance/regexp_match.rb:165
2352
+ def autocorrect(corrector, node); end
2353
+
2354
+ # pkg:gem/rubocop-performance#lib/rubocop/cop/performance/regexp_match.rb:154
2355
+ def check_condition(cond); end
2356
+
2357
+ # pkg:gem/rubocop-performance#lib/rubocop/cop/performance/regexp_match.rb:250
2358
+ def correct_operator(corrector, recv, arg, oper = T.unsafe(nil)); end
2359
+
2360
+ # pkg:gem/rubocop-performance#lib/rubocop/cop/performance/regexp_match.rb:221
2361
+ def find_last_match(body, range, scope_root); end
2362
+
2363
+ # pkg:gem/rubocop-performance#lib/rubocop/cop/performance/regexp_match.rb:181
2364
+ def last_match_used?(match_node); end
2365
+
2366
+ # pkg:gem/rubocop-performance#lib/rubocop/cop/performance/regexp_match.rb:246
2367
+ def match_gvar?(sym); end
2368
+
2369
+ # pkg:gem/rubocop-performance#lib/rubocop/cop/performance/regexp_match.rb:177
2370
+ def message(node); end
2371
+
2372
+ # pkg:gem/rubocop-performance#lib/rubocop/cop/performance/regexp_match.rb:217
2373
+ def modifier_form?(match_node); end
2374
+
2375
+ # pkg:gem/rubocop-performance#lib/rubocop/cop/performance/regexp_match.rb:203
2376
+ def next_match_pos(body, match_node_pos, scope_root); end
2377
+
2378
+ # pkg:gem/rubocop-performance#lib/rubocop/cop/performance/regexp_match.rb:190
2379
+ def range_to_search_for_last_matches(match_node, body, scope_root); end
2380
+
2381
+ # pkg:gem/rubocop-performance#lib/rubocop/cop/performance/regexp_match.rb:259
2382
+ def replace_with_match_predicate_method(corrector, recv, arg, op_range); end
2383
+
2384
+ # pkg:gem/rubocop-performance#lib/rubocop/cop/performance/regexp_match.rb:228
2385
+ def scope_body(node); end
2386
+
2387
+ # pkg:gem/rubocop-performance#lib/rubocop/cop/performance/regexp_match.rb:240
2388
+ def scope_root(node); end
2389
+
2390
+ # pkg:gem/rubocop-performance#lib/rubocop/cop/performance/regexp_match.rb:270
2391
+ def swap_receiver_and_arg(corrector, recv, arg); end
2392
+
2393
+ class << self
2394
+ # pkg:gem/rubocop-performance#lib/rubocop/cop/performance/regexp_match.rb:134
2395
+ def autocorrect_incompatible_with; end
2396
+ end
2397
+ end
2398
+
2399
+ # pkg:gem/rubocop-performance#lib/rubocop/cop/performance/regexp_match.rb:112
2400
+ RuboCop::Cop::Performance::RegexpMatch::MATCH_NODE_PATTERN = T.let(T.unsafe(nil), String)
2401
+
2402
+ # pkg:gem/rubocop-performance#lib/rubocop/cop/performance/regexp_match.rb:84
2403
+ RuboCop::Cop::Performance::RegexpMatch::MSG = T.let(T.unsafe(nil), String)
2404
+
2405
+ # Constants are included in this list because it is unlikely that
2406
+ # someone will store `nil` as a constant and then use it for comparison
2407
+ #
2408
+ # pkg:gem/rubocop-performance#lib/rubocop/cop/performance/regexp_match.rb:83
2409
+ RuboCop::Cop::Performance::RegexpMatch::TYPES_IMPLEMENTING_MATCH = T.let(T.unsafe(nil), Array)
2410
+
2411
+ # Identifies usages of `reverse.each` and change them to use `reverse_each` instead.
2412
+ #
2413
+ # If the return value is used, it will not be detected because the result will be different.
2414
+ #
2415
+ # [source,ruby]
2416
+ # ----
2417
+ # [1, 2, 3].reverse.each {} #=> [3, 2, 1]
2418
+ # [1, 2, 3].reverse_each {} #=> [1, 2, 3]
2419
+ # ----
2420
+ #
2421
+ # @example
2422
+ # # bad
2423
+ # items.reverse.each
2424
+ #
2425
+ # # good
2426
+ # items.reverse_each
2427
+ #
2428
+ # pkg:gem/rubocop-performance#lib/rubocop/cop/performance/reverse_each.rb:22
2429
+ class RuboCop::Cop::Performance::ReverseEach < ::RuboCop::Cop::Base
2430
+ include ::RuboCop::Cop::RangeHelp
2431
+ extend ::RuboCop::Cop::AutoCorrector
2432
+
2433
+ # pkg:gem/rubocop-performance#lib/rubocop/cop/performance/reverse_each.rb:44
2434
+ def on_csend(node); end
2435
+
2436
+ # pkg:gem/rubocop-performance#lib/rubocop/cop/performance/reverse_each.rb:33
2437
+ def on_send(node); end
2438
+
2439
+ # pkg:gem/rubocop-performance#lib/rubocop/cop/performance/reverse_each.rb:29
2440
+ def reverse_each?(param0 = T.unsafe(nil)); end
2441
+
2442
+ private
2443
+
2444
+ # pkg:gem/rubocop-performance#lib/rubocop/cop/performance/reverse_each.rb:54
2445
+ def offense_range(node); end
2446
+
2447
+ # pkg:gem/rubocop-performance#lib/rubocop/cop/performance/reverse_each.rb:48
2448
+ def use_return_value?(node); end
2449
+ end
2450
+
2451
+ # pkg:gem/rubocop-performance#lib/rubocop/cop/performance/reverse_each.rb:26
2452
+ RuboCop::Cop::Performance::ReverseEach::MSG = T.let(T.unsafe(nil), String)
2453
+
2454
+ # pkg:gem/rubocop-performance#lib/rubocop/cop/performance/reverse_each.rb:27
2455
+ RuboCop::Cop::Performance::ReverseEach::RESTRICT_ON_SEND = T.let(T.unsafe(nil), Array)
2456
+
2457
+ # Identifies places where `reverse.first(n)` and `reverse.first`
2458
+ # can be replaced by `last(n).reverse` and `last`.
2459
+ #
2460
+ # @example
2461
+ #
2462
+ # # bad
2463
+ # array.reverse.first(5)
2464
+ # array.reverse.first
2465
+ #
2466
+ # # good
2467
+ # array.last(5).reverse
2468
+ # array.last
2469
+ #
2470
+ # pkg:gem/rubocop-performance#lib/rubocop/cop/performance/reverse_first.rb:19
2471
+ class RuboCop::Cop::Performance::ReverseFirst < ::RuboCop::Cop::Base
2472
+ include ::RuboCop::Cop::RangeHelp
2473
+ extend ::RuboCop::Cop::AutoCorrector
2474
+
2475
+ # pkg:gem/rubocop-performance#lib/rubocop/cop/performance/reverse_first.rb:42
2476
+ def on_csend(node); end
2477
+
2478
+ # pkg:gem/rubocop-performance#lib/rubocop/cop/performance/reverse_first.rb:30
2479
+ def on_send(node); end
2480
+
2481
+ # pkg:gem/rubocop-performance#lib/rubocop/cop/performance/reverse_first.rb:26
2482
+ def reverse_first_candidate?(param0 = T.unsafe(nil)); end
2483
+
2484
+ private
2485
+
2486
+ # pkg:gem/rubocop-performance#lib/rubocop/cop/performance/reverse_first.rb:56
2487
+ def build_good_method(node); end
2488
+
2489
+ # pkg:gem/rubocop-performance#lib/rubocop/cop/performance/reverse_first.rb:50
2490
+ def build_message(node, range); end
2491
+
2492
+ # pkg:gem/rubocop-performance#lib/rubocop/cop/performance/reverse_first.rb:46
2493
+ def correction_range(receiver, node); end
2494
+ end
2495
+
2496
+ # pkg:gem/rubocop-performance#lib/rubocop/cop/performance/reverse_first.rb:23
2497
+ RuboCop::Cop::Performance::ReverseFirst::MSG = T.let(T.unsafe(nil), String)
2498
+
2499
+ # pkg:gem/rubocop-performance#lib/rubocop/cop/performance/reverse_first.rb:24
2500
+ RuboCop::Cop::Performance::ReverseFirst::RESTRICT_ON_SEND = T.let(T.unsafe(nil), Array)
2501
+
2502
+ # In Ruby 2.7, `Enumerable#filter_map` has been added.
2503
+ #
2504
+ # This cop identifies places where `select.map` can be replaced by `filter_map`.
2505
+ #
2506
+ # @example
2507
+ # # bad
2508
+ # ary.select(&:foo).map(&:bar)
2509
+ # ary.filter(&:foo).map(&:bar)
2510
+ #
2511
+ # # good
2512
+ # ary.filter_map { |o| o.bar if o.foo }
2513
+ #
2514
+ # pkg:gem/rubocop-performance#lib/rubocop/cop/performance/select_map.rb:18
2515
+ class RuboCop::Cop::Performance::SelectMap < ::RuboCop::Cop::Base
2516
+ include ::RuboCop::Cop::RangeHelp
2517
+ extend ::RuboCop::Cop::TargetRubyVersion
2518
+
2519
+ # pkg:gem/rubocop-performance#lib/rubocop/cop/performance/select_map.rb:37
2520
+ def on_csend(node); end
2521
+
2522
+ # pkg:gem/rubocop-performance#lib/rubocop/cop/performance/select_map.rb:27
2523
+ def on_send(node); end
2524
+
2525
+ private
2526
+
2527
+ # pkg:gem/rubocop-performance#lib/rubocop/cop/performance/select_map.rb:41
2528
+ def map_method_candidate(node); end
2529
+
2530
+ # pkg:gem/rubocop-performance#lib/rubocop/cop/performance/select_map.rb:51
2531
+ def offense_range(node, map_method); end
2532
+ end
2533
+
2534
+ # pkg:gem/rubocop-performance#lib/rubocop/cop/performance/select_map.rb:24
2535
+ RuboCop::Cop::Performance::SelectMap::MSG = T.let(T.unsafe(nil), String)
2536
+
2537
+ # pkg:gem/rubocop-performance#lib/rubocop/cop/performance/select_map.rb:25
2538
+ RuboCop::Cop::Performance::SelectMap::RESTRICT_ON_SEND = T.let(T.unsafe(nil), Array)
2539
+
2540
+ # Identifies usages of `count` on an `Array` and `Hash` and change them to `size`.
2541
+ #
2542
+ # @example
2543
+ # # bad
2544
+ # [1, 2, 3].count
2545
+ # (1..3).to_a.count
2546
+ # Array[*1..3].count
2547
+ # Array(1..3).count
2548
+ #
2549
+ # # bad
2550
+ # {a: 1, b: 2, c: 3}.count
2551
+ # [[:foo, :bar], [1, 2]].to_h.count
2552
+ # Hash[*('a'..'z')].count
2553
+ # Hash(key: :value).count
2554
+ #
2555
+ # # good
2556
+ # [1, 2, 3].size
2557
+ # (1..3).to_a.size
2558
+ # Array[*1..3].size
2559
+ # Array(1..3).size
2560
+ #
2561
+ # # good
2562
+ # {a: 1, b: 2, c: 3}.size
2563
+ # [[:foo, :bar], [1, 2]].to_h.size
2564
+ # Hash[*('a'..'z')].size
2565
+ # Hash(key: :value).size
2566
+ #
2567
+ # # good
2568
+ # [1, 2, 3].count { |e| e > 2 }
2569
+ # TODO: Add advanced detection of variables that could
2570
+ # have been assigned to an array or a hash.
2571
+ #
2572
+ # pkg:gem/rubocop-performance#lib/rubocop/cop/performance/size.rb:37
2573
+ class RuboCop::Cop::Performance::Size < ::RuboCop::Cop::Base
2574
+ extend ::RuboCop::Cop::AutoCorrector
2575
+
2576
+ # pkg:gem/rubocop-performance#lib/rubocop/cop/performance/size.rb:43
2577
+ def array?(param0 = T.unsafe(nil)); end
2578
+
2579
+ # pkg:gem/rubocop-performance#lib/rubocop/cop/performance/size.rb:61
2580
+ def count?(param0 = T.unsafe(nil)); end
2581
+
2582
+ # pkg:gem/rubocop-performance#lib/rubocop/cop/performance/size.rb:52
2583
+ def hash?(param0 = T.unsafe(nil)); end
2584
+
2585
+ # pkg:gem/rubocop-performance#lib/rubocop/cop/performance/size.rb:72
2586
+ def on_csend(node); end
2587
+
2588
+ # pkg:gem/rubocop-performance#lib/rubocop/cop/performance/size.rb:65
2589
+ def on_send(node); end
2590
+ end
2591
+
2592
+ # pkg:gem/rubocop-performance#lib/rubocop/cop/performance/size.rb:40
2593
+ RuboCop::Cop::Performance::Size::MSG = T.let(T.unsafe(nil), String)
2594
+
2595
+ # pkg:gem/rubocop-performance#lib/rubocop/cop/performance/size.rb:41
2596
+ RuboCop::Cop::Performance::Size::RESTRICT_ON_SEND = T.let(T.unsafe(nil), Array)
2597
+
2598
+ # Identifies places where `sort { |a, b| b <=> a }`
2599
+ # can be replaced by a faster `sort.reverse`.
2600
+ #
2601
+ # @example
2602
+ # # bad
2603
+ # array.sort { |a, b| b <=> a }
2604
+ #
2605
+ # # good
2606
+ # array.sort.reverse
2607
+ #
2608
+ # pkg:gem/rubocop-performance#lib/rubocop/cop/performance/sort_reverse.rb:16
2609
+ class RuboCop::Cop::Performance::SortReverse < ::RuboCop::Cop::Base
2610
+ include ::RuboCop::Cop::RangeHelp
2611
+ include ::RuboCop::Cop::SortBlock
2612
+ extend ::RuboCop::Cop::AutoCorrector
2613
+
2614
+ # pkg:gem/rubocop-performance#lib/rubocop/cop/performance/sort_reverse.rb:22
2615
+ def on_block(node); end
2616
+
2617
+ # pkg:gem/rubocop-performance#lib/rubocop/cop/performance/sort_reverse.rb:30
2618
+ def on_numblock(node); end
2619
+
2620
+ private
2621
+
2622
+ # pkg:gem/rubocop-performance#lib/rubocop/cop/performance/sort_reverse.rb:42
2623
+ def register_offense(send, node); end
2624
+ end
2625
+
2626
+ # pkg:gem/rubocop-performance#lib/rubocop/cop/performance/sort_reverse.rb:20
2627
+ RuboCop::Cop::Performance::SortReverse::MSG = T.let(T.unsafe(nil), String)
2628
+
2629
+ # Identifies places where `gsub(/a+/, 'a')` and `gsub!(/a+/, 'a')`
2630
+ # can be replaced by `squeeze('a')` and `squeeze!('a')`.
2631
+ #
2632
+ # The `squeeze('a')` method is faster than `gsub(/a+/, 'a')`.
2633
+ #
2634
+ # @example
2635
+ #
2636
+ # # bad
2637
+ # str.gsub(/a+/, 'a')
2638
+ # str.gsub!(/a+/, 'a')
2639
+ #
2640
+ # # good
2641
+ # str.squeeze('a')
2642
+ # str.squeeze!('a')
2643
+ #
2644
+ # pkg:gem/rubocop-performance#lib/rubocop/cop/performance/squeeze.rb:21
2645
+ class RuboCop::Cop::Performance::Squeeze < ::RuboCop::Cop::Base
2646
+ extend ::RuboCop::Cop::AutoCorrector
2647
+
2648
+ # pkg:gem/rubocop-performance#lib/rubocop/cop/performance/squeeze.rb:61
2649
+ def on_csend(node); end
2650
+
2651
+ # pkg:gem/rubocop-performance#lib/rubocop/cop/performance/squeeze.rb:39
2652
+ def on_send(node); end
2653
+
2654
+ # pkg:gem/rubocop-performance#lib/rubocop/cop/performance/squeeze.rb:29
2655
+ def squeeze_candidate?(param0 = T.unsafe(nil)); end
2656
+
2657
+ private
2658
+
2659
+ # pkg:gem/rubocop-performance#lib/rubocop/cop/performance/squeeze.rb:65
2660
+ def repeating_literal?(regex_str); end
2661
+ end
2662
+
2663
+ # pkg:gem/rubocop-performance#lib/rubocop/cop/performance/squeeze.rb:24
2664
+ RuboCop::Cop::Performance::Squeeze::MSG = T.let(T.unsafe(nil), String)
2665
+
2666
+ # pkg:gem/rubocop-performance#lib/rubocop/cop/performance/squeeze.rb:27
2667
+ RuboCop::Cop::Performance::Squeeze::PREFERRED_METHODS = T.let(T.unsafe(nil), Hash)
2668
+
2669
+ # pkg:gem/rubocop-performance#lib/rubocop/cop/performance/squeeze.rb:25
2670
+ RuboCop::Cop::Performance::Squeeze::RESTRICT_ON_SEND = T.let(T.unsafe(nil), Array)
2671
+
2672
+ # Identifies unnecessary use of a regex where `String#start_with?` would suffice.
2673
+ #
2674
+ # This cop has `SafeMultiline` configuration option that `true` by default because
2675
+ # `^start` is unsafe as it will behave incompatible with `start_with?`
2676
+ # for receiver is multiline string.
2677
+ #
2678
+ # @safety
2679
+ # This will change to a new method call which isn't guaranteed to be on the
2680
+ # object. Switching these methods has to be done with knowledge of the types
2681
+ # of the variables which rubocop doesn't have.
2682
+ #
2683
+ # @example
2684
+ # # bad
2685
+ # 'abc'.match?(/\Aab/)
2686
+ # /\Aab/.match?('abc')
2687
+ # 'abc' =~ /\Aab/
2688
+ # /\Aab/ =~ 'abc'
2689
+ # 'abc'.match(/\Aab/)
2690
+ # /\Aab/.match('abc')
2691
+ #
2692
+ # # good
2693
+ # 'abc'.start_with?('ab')
2694
+ #
2695
+ # @example SafeMultiline: true (default)
2696
+ #
2697
+ # # good
2698
+ # 'abc'.match?(/^ab/)
2699
+ # /^ab/.match?('abc')
2700
+ # 'abc' =~ /^ab/
2701
+ # /^ab/ =~ 'abc'
2702
+ # 'abc'.match(/^ab/)
2703
+ # /^ab/.match('abc')
2704
+ #
2705
+ # @example SafeMultiline: false
2706
+ #
2707
+ # # bad
2708
+ # 'abc'.match?(/^ab/)
2709
+ # /^ab/.match?('abc')
2710
+ # 'abc' =~ /^ab/
2711
+ # /^ab/ =~ 'abc'
2712
+ # 'abc'.match(/^ab/)
2713
+ # /^ab/.match('abc')
2714
+ #
2715
+ # pkg:gem/rubocop-performance#lib/rubocop/cop/performance/start_with.rb:49
2716
+ class RuboCop::Cop::Performance::StartWith < ::RuboCop::Cop::Base
2717
+ include ::RuboCop::Cop::RegexpMetacharacter
2718
+ extend ::RuboCop::Cop::AutoCorrector
2719
+
2720
+ # pkg:gem/rubocop-performance#lib/rubocop/cop/performance/start_with.rb:77
2721
+ def on_csend(node); end
2722
+
2723
+ # pkg:gem/rubocop-performance#lib/rubocop/cop/performance/start_with.rb:78
2724
+ def on_match_with_lvasgn(node); end
2725
+
2726
+ # pkg:gem/rubocop-performance#lib/rubocop/cop/performance/start_with.rb:63
2727
+ def on_send(node); end
2728
+
2729
+ # pkg:gem/rubocop-performance#lib/rubocop/cop/performance/start_with.rb:56
2730
+ def redundant_regex?(param0 = T.unsafe(nil)); end
2731
+ end
2732
+
2733
+ # pkg:gem/rubocop-performance#lib/rubocop/cop/performance/start_with.rb:53
2734
+ RuboCop::Cop::Performance::StartWith::MSG = T.let(T.unsafe(nil), String)
2735
+
2736
+ # pkg:gem/rubocop-performance#lib/rubocop/cop/performance/start_with.rb:54
2737
+ RuboCop::Cop::Performance::StartWith::RESTRICT_ON_SEND = T.let(T.unsafe(nil), Array)
2738
+
2739
+ # Checks for calls to `#bytes` counting method and suggests using `bytesize` instead.
2740
+ # The `bytesize` method is more efficient and directly returns the size in bytes,
2741
+ # avoiding the intermediate array allocation that `bytes.size` incurs.
2742
+ #
2743
+ # @safety
2744
+ # This cop is unsafe because it assumes that the receiver
2745
+ # responds to `#bytesize` method.
2746
+ #
2747
+ # @example
2748
+ # # bad
2749
+ # string_var.bytes.count
2750
+ # "foobar".bytes.size
2751
+ #
2752
+ # # good
2753
+ # string_var.bytesize
2754
+ # "foobar".bytesize
2755
+ #
2756
+ # pkg:gem/rubocop-performance#lib/rubocop/cop/performance/string_bytesize.rb:22
2757
+ class RuboCop::Cop::Performance::StringBytesize < ::RuboCop::Cop::Base
2758
+ extend ::RuboCop::Cop::AutoCorrector
2759
+
2760
+ # pkg:gem/rubocop-performance#lib/rubocop/cop/performance/string_bytesize.rb:41
2761
+ def on_csend(node); end
2762
+
2763
+ # pkg:gem/rubocop-performance#lib/rubocop/cop/performance/string_bytesize.rb:32
2764
+ def on_send(node); end
2765
+
2766
+ # pkg:gem/rubocop-performance#lib/rubocop/cop/performance/string_bytesize.rb:28
2767
+ def string_bytes_method?(param0 = T.unsafe(nil)); end
2768
+ end
2769
+
2770
+ # pkg:gem/rubocop-performance#lib/rubocop/cop/performance/string_bytesize.rb:25
2771
+ RuboCop::Cop::Performance::StringBytesize::MSG = T.let(T.unsafe(nil), String)
2772
+
2773
+ # pkg:gem/rubocop-performance#lib/rubocop/cop/performance/string_bytesize.rb:26
2774
+ RuboCop::Cop::Performance::StringBytesize::RESTRICT_ON_SEND = T.let(T.unsafe(nil), Array)
2775
+
2776
+ # Identifies places where string identifier argument can be replaced
2777
+ # by symbol identifier argument.
2778
+ # It prevents the redundancy of the internal string-to-symbol conversion.
2779
+ #
2780
+ # This cop targets methods that take identifier (e.g. method name) argument
2781
+ # and the following examples are parts of it.
2782
+ #
2783
+ # @example
2784
+ #
2785
+ # # bad
2786
+ # send('do_something')
2787
+ # attr_accessor 'do_something'
2788
+ # instance_variable_get('@ivar')
2789
+ #
2790
+ # # good
2791
+ # send(:do_something)
2792
+ # attr_accessor :do_something
2793
+ # instance_variable_get(:@ivar)
2794
+ #
2795
+ # # good - these methods don't support namespaced symbols
2796
+ # const_get("#{module_path}::Base")
2797
+ # const_source_location("#{module_path}::Base")
2798
+ # const_defined?("#{module_path}::Base")
2799
+ #
2800
+ # # good - using a symbol when string interpolation is involved causes a performance regression.
2801
+ # respond_to?("string_#{interpolation}")
2802
+ #
2803
+ # pkg:gem/rubocop-performance#lib/rubocop/cop/performance/string_identifier_argument.rb:33
2804
+ class RuboCop::Cop::Performance::StringIdentifierArgument < ::RuboCop::Cop::Base
2805
+ extend ::RuboCop::Cop::AutoCorrector
2806
+
2807
+ # pkg:gem/rubocop-performance#lib/rubocop/cop/performance/string_identifier_argument.rb:62
2808
+ def on_send(node); end
2809
+
2810
+ private
2811
+
2812
+ # pkg:gem/rubocop-performance#lib/rubocop/cop/performance/string_identifier_argument.rb:97
2813
+ def argument_replacement(node, value); end
2814
+
2815
+ # pkg:gem/rubocop-performance#lib/rubocop/cop/performance/string_identifier_argument.rb:87
2816
+ def register_offense(argument, argument_value); end
2817
+
2818
+ # pkg:gem/rubocop-performance#lib/rubocop/cop/performance/string_identifier_argument.rb:75
2819
+ def string_arguments(node); end
2820
+ end
2821
+
2822
+ # pkg:gem/rubocop-performance#lib/rubocop/cop/performance/string_identifier_argument.rb:38
2823
+ RuboCop::Cop::Performance::StringIdentifierArgument::COMMAND_METHODS = T.let(T.unsafe(nil), Array)
2824
+
2825
+ # pkg:gem/rubocop-performance#lib/rubocop/cop/performance/string_identifier_argument.rb:36
2826
+ RuboCop::Cop::Performance::StringIdentifierArgument::MSG = T.let(T.unsafe(nil), String)
2827
+
2828
+ # pkg:gem/rubocop-performance#lib/rubocop/cop/performance/string_identifier_argument.rb:44
2829
+ RuboCop::Cop::Performance::StringIdentifierArgument::MULTIPLE_ARGUMENTS_METHODS = T.let(T.unsafe(nil), Array)
2830
+
2831
+ # NOTE: `attr` method is not included in this list as it can cause false positives in Nokogiri API.
2832
+ # And `attr` may not be used because `Style/Attr` registers an offense.
2833
+ # https://github.com/rubocop/rubocop-performance/issues/278
2834
+ #
2835
+ # pkg:gem/rubocop-performance#lib/rubocop/cop/performance/string_identifier_argument.rb:52
2836
+ RuboCop::Cop::Performance::StringIdentifierArgument::RESTRICT_ON_SEND = T.let(T.unsafe(nil), Array)
2837
+
2838
+ # pkg:gem/rubocop-performance#lib/rubocop/cop/performance/string_identifier_argument.rb:43
2839
+ RuboCop::Cop::Performance::StringIdentifierArgument::TWO_ARGUMENTS_METHOD = T.let(T.unsafe(nil), Symbol)
2840
+
2841
+ # Identifies unnecessary use of a regex where `String#include?` would suffice.
2842
+ #
2843
+ # @safety
2844
+ # This cop's offenses are not safe to autocorrect if a receiver is nil or a Symbol.
2845
+ #
2846
+ # @example
2847
+ # # bad
2848
+ # str.match?(/ab/)
2849
+ # /ab/.match?(str)
2850
+ # str =~ /ab/
2851
+ # /ab/ =~ str
2852
+ # str.match(/ab/)
2853
+ # /ab/.match(str)
2854
+ # /ab/ === str
2855
+ #
2856
+ # # good
2857
+ # str.include?('ab')
2858
+ #
2859
+ # pkg:gem/rubocop-performance#lib/rubocop/cop/performance/string_include.rb:23
2860
+ class RuboCop::Cop::Performance::StringInclude < ::RuboCop::Cop::Base
2861
+ extend ::RuboCop::Cop::AutoCorrector
2862
+
2863
+ # pkg:gem/rubocop-performance#lib/rubocop/cop/performance/string_include.rb:54
2864
+ def on_csend(node); end
2865
+
2866
+ # pkg:gem/rubocop-performance#lib/rubocop/cop/performance/string_include.rb:55
2867
+ def on_match_with_lvasgn(node); end
2868
+
2869
+ # pkg:gem/rubocop-performance#lib/rubocop/cop/performance/string_include.rb:37
2870
+ def on_send(node); end
2871
+
2872
+ # pkg:gem/rubocop-performance#lib/rubocop/cop/performance/string_include.rb:29
2873
+ def redundant_regex?(param0 = T.unsafe(nil)); end
2874
+
2875
+ private
2876
+
2877
+ # pkg:gem/rubocop-performance#lib/rubocop/cop/performance/string_include.rb:59
2878
+ def literal?(regex_str); end
2879
+ end
2880
+
2881
+ # pkg:gem/rubocop-performance#lib/rubocop/cop/performance/string_include.rb:26
2882
+ RuboCop::Cop::Performance::StringInclude::MSG = T.let(T.unsafe(nil), String)
2883
+
2884
+ # pkg:gem/rubocop-performance#lib/rubocop/cop/performance/string_include.rb:27
2885
+ RuboCop::Cop::Performance::StringInclude::RESTRICT_ON_SEND = T.let(T.unsafe(nil), Array)
2886
+
2887
+ # Identifies places where `gsub` can be replaced by `tr` or `delete`.
2888
+ #
2889
+ # @example
2890
+ # # bad
2891
+ # 'abc'.gsub('b', 'd')
2892
+ # 'abc'.gsub('a', '')
2893
+ # 'abc'.gsub(/a/, 'd')
2894
+ # 'abc'.gsub!('a', 'd')
2895
+ #
2896
+ # # good
2897
+ # 'abc'.gsub(/.*/, 'a')
2898
+ # 'abc'.gsub(/a+/, 'd')
2899
+ # 'abc'.tr('b', 'd')
2900
+ # 'a b c'.delete(' ')
2901
+ #
2902
+ # pkg:gem/rubocop-performance#lib/rubocop/cop/performance/string_replacement.rb:20
2903
+ class RuboCop::Cop::Performance::StringReplacement < ::RuboCop::Cop::Base
2904
+ include ::RuboCop::Cop::RangeHelp
2905
+ extend ::RuboCop::Cop::AutoCorrector
2906
+
2907
+ # pkg:gem/rubocop-performance#lib/rubocop/cop/performance/string_replacement.rb:45
2908
+ def on_csend(node); end
2909
+
2910
+ # pkg:gem/rubocop-performance#lib/rubocop/cop/performance/string_replacement.rb:37
2911
+ def on_send(node); end
2912
+
2913
+ # pkg:gem/rubocop-performance#lib/rubocop/cop/performance/string_replacement.rb:31
2914
+ def string_replacement?(param0 = T.unsafe(nil)); end
2915
+
2916
+ private
2917
+
2918
+ # pkg:gem/rubocop-performance#lib/rubocop/cop/performance/string_replacement.rb:84
2919
+ def accept_first_param?(first_param); end
2920
+
2921
+ # pkg:gem/rubocop-performance#lib/rubocop/cop/performance/string_replacement.rb:79
2922
+ def accept_second_param?(second_param); end
2923
+
2924
+ # pkg:gem/rubocop-performance#lib/rubocop/cop/performance/string_replacement.rb:60
2925
+ def autocorrect(corrector, node); end
2926
+
2927
+ # pkg:gem/rubocop-performance#lib/rubocop/cop/performance/string_replacement.rb:100
2928
+ def first_source(first_param); end
2929
+
2930
+ # pkg:gem/rubocop-performance#lib/rubocop/cop/performance/string_replacement.rb:143
2931
+ def message(node, first_source, second_source); end
2932
+
2933
+ # pkg:gem/rubocop-performance#lib/rubocop/cop/performance/string_replacement.rb:149
2934
+ def method_suffix(node); end
2935
+
2936
+ # pkg:gem/rubocop-performance#lib/rubocop/cop/performance/string_replacement.rb:49
2937
+ def offense(node, first_param, second_param); end
2938
+
2939
+ # pkg:gem/rubocop-performance#lib/rubocop/cop/performance/string_replacement.rb:129
2940
+ def range(node); end
2941
+
2942
+ # pkg:gem/rubocop-performance#lib/rubocop/cop/performance/string_replacement.rb:153
2943
+ def remove_second_param(corrector, node, first_param); end
2944
+
2945
+ # pkg:gem/rubocop-performance#lib/rubocop/cop/performance/string_replacement.rb:70
2946
+ def replace_method(corrector, node, first_source, second_source, first_param); end
2947
+
2948
+ # pkg:gem/rubocop-performance#lib/rubocop/cop/performance/string_replacement.rb:133
2949
+ def replacement_method(node, first_source, second_source); end
2950
+
2951
+ # pkg:gem/rubocop-performance#lib/rubocop/cop/performance/string_replacement.rb:118
2952
+ def source_from_regex_constructor(node); end
2953
+
2954
+ # pkg:gem/rubocop-performance#lib/rubocop/cop/performance/string_replacement.rb:111
2955
+ def source_from_regex_literal(node); end
2956
+ end
2957
+
2958
+ # pkg:gem/rubocop-performance#lib/rubocop/cop/performance/string_replacement.rb:29
2959
+ RuboCop::Cop::Performance::StringReplacement::BANG = T.let(T.unsafe(nil), String)
2960
+
2961
+ # pkg:gem/rubocop-performance#lib/rubocop/cop/performance/string_replacement.rb:27
2962
+ RuboCop::Cop::Performance::StringReplacement::DELETE = T.let(T.unsafe(nil), String)
2963
+
2964
+ # pkg:gem/rubocop-performance#lib/rubocop/cop/performance/string_replacement.rb:26
2965
+ RuboCop::Cop::Performance::StringReplacement::DETERMINISTIC_REGEX = T.let(T.unsafe(nil), Regexp)
2966
+
2967
+ # pkg:gem/rubocop-performance#lib/rubocop/cop/performance/string_replacement.rb:24
2968
+ RuboCop::Cop::Performance::StringReplacement::MSG = T.let(T.unsafe(nil), String)
2969
+
2970
+ # pkg:gem/rubocop-performance#lib/rubocop/cop/performance/string_replacement.rb:25
2971
+ RuboCop::Cop::Performance::StringReplacement::RESTRICT_ON_SEND = T.let(T.unsafe(nil), Array)
2972
+
2973
+ # pkg:gem/rubocop-performance#lib/rubocop/cop/performance/string_replacement.rb:28
2974
+ RuboCop::Cop::Performance::StringReplacement::TR = T.let(T.unsafe(nil), String)
2975
+
2976
+ # Identifies places where custom code finding the sum of elements
2977
+ # in some Enumerable object can be replaced by `Enumerable#sum` method.
2978
+ #
2979
+ # @safety
2980
+ # Autocorrections are unproblematic wherever an initial value is provided explicitly:
2981
+ #
2982
+ # [source,ruby]
2983
+ # ----
2984
+ # [1, 2, 3].reduce(4, :+) # => 10
2985
+ # [1, 2, 3].sum(4) # => 10
2986
+ #
2987
+ # [].reduce(4, :+) # => 4
2988
+ # [].sum(4) # => 4
2989
+ # ----
2990
+ #
2991
+ # This also holds true for non-numeric types which implement a `:+` method:
2992
+ #
2993
+ # [source,ruby]
2994
+ # ----
2995
+ # ['l', 'o'].reduce('Hel', :+) # => "Hello"
2996
+ # ['l', 'o'].sum('Hel') # => "Hello"
2997
+ # ----
2998
+ #
2999
+ # When no initial value is provided though, `Enumerable#reduce` will pick the first enumerated value
3000
+ # as initial value and successively add all following values to it, whereas
3001
+ # `Enumerable#sum` will set an initial value of `0` (`Integer`) which can lead to a `TypeError`:
3002
+ #
3003
+ # [source,ruby]
3004
+ # ----
3005
+ # [].reduce(:+) # => nil
3006
+ # [1, 2, 3].reduce(:+) # => 6
3007
+ # ['H', 'e', 'l', 'l', 'o'].reduce(:+) # => "Hello"
3008
+ #
3009
+ # [].sum # => 0
3010
+ # [1, 2, 3].sum # => 6
3011
+ # ['H', 'e', 'l', 'l', 'o'].sum # => in `+': String can't be coerced into Integer (TypeError)
3012
+ # ----
3013
+ #
3014
+ # @example OnlySumOrWithInitialValue: false (default)
3015
+ # # bad
3016
+ # [1, 2, 3].inject(:+) # Autocorrections for cases without initial value are unsafe
3017
+ # [1, 2, 3].inject(&:+) # and will only be performed when using the `-A` option.
3018
+ # [1, 2, 3].reduce { |acc, elem| acc + elem } # They can be prohibited completely using `SafeAutoCorrect: true`.
3019
+ # [1, 2, 3].reduce(10, :+)
3020
+ # [1, 2, 3].map { |elem| elem ** 2 }.sum
3021
+ # [1, 2, 3].collect(&:count).sum(10)
3022
+ #
3023
+ # # good
3024
+ # [1, 2, 3].sum
3025
+ # [1, 2, 3].sum(10)
3026
+ # [1, 2, 3].sum { |elem| elem ** 2 }
3027
+ # [1, 2, 3].sum(10, &:count)
3028
+ #
3029
+ # @example OnlySumOrWithInitialValue: true
3030
+ # # bad
3031
+ # [1, 2, 3].reduce(10, :+)
3032
+ # [1, 2, 3].map { |elem| elem ** 2 }.sum
3033
+ # [1, 2, 3].collect(&:count).sum(10)
3034
+ #
3035
+ # # good
3036
+ # [1, 2, 3].sum(10)
3037
+ # [1, 2, 3].sum { |elem| elem ** 2 }
3038
+ # [1, 2, 3].sum(10, &:count)
3039
+ #
3040
+ # pkg:gem/rubocop-performance#lib/rubocop/cop/performance/sum.rb:70
3041
+ class RuboCop::Cop::Performance::Sum < ::RuboCop::Cop::Base
3042
+ include ::RuboCop::Cop::RangeHelp
3043
+ extend ::RuboCop::Cop::AutoCorrector
3044
+ extend ::RuboCop::Cop::TargetRubyVersion
3045
+
3046
+ # pkg:gem/rubocop-performance#lib/rubocop/cop/performance/sum.rb:102
3047
+ def acc_plus_elem?(param0 = T.unsafe(nil), param1, param2); end
3048
+
3049
+ # pkg:gem/rubocop-performance#lib/rubocop/cop/performance/sum.rb:105
3050
+ def elem_plus_acc?(param0 = T.unsafe(nil), param1, param2); end
3051
+
3052
+ # pkg:gem/rubocop-performance#lib/rubocop/cop/performance/sum.rb:115
3053
+ def on_block(node); end
3054
+
3055
+ # pkg:gem/rubocop-performance#lib/rubocop/cop/performance/sum.rb:113
3056
+ def on_csend(node); end
3057
+
3058
+ # pkg:gem/rubocop-performance#lib/rubocop/cop/performance/sum.rb:107
3059
+ def on_send(node); end
3060
+
3061
+ # pkg:gem/rubocop-performance#lib/rubocop/cop/performance/sum.rb:82
3062
+ def sum_candidate?(param0 = T.unsafe(nil)); end
3063
+
3064
+ # pkg:gem/rubocop-performance#lib/rubocop/cop/performance/sum.rb:86
3065
+ def sum_map_candidate?(param0 = T.unsafe(nil)); end
3066
+
3067
+ # pkg:gem/rubocop-performance#lib/rubocop/cop/performance/sum.rb:95
3068
+ def sum_with_block_candidate?(param0 = T.unsafe(nil)); end
3069
+
3070
+ private
3071
+
3072
+ # pkg:gem/rubocop-performance#lib/rubocop/cop/performance/sum.rb:160
3073
+ def array_literal?(node); end
3074
+
3075
+ # pkg:gem/rubocop-performance#lib/rubocop/cop/performance/sum.rb:165
3076
+ def autocorrect(corrector, init, range); end
3077
+
3078
+ # pkg:gem/rubocop-performance#lib/rubocop/cop/performance/sum.rb:173
3079
+ def autocorrect_sum_map(corrector, sum, map, init); end
3080
+
3081
+ # pkg:gem/rubocop-performance#lib/rubocop/cop/performance/sum.rb:250
3082
+ def build_block_bad_method(method, init, var_acc, var_elem, body); end
3083
+
3084
+ # pkg:gem/rubocop-performance#lib/rubocop/cop/performance/sum.rb:217
3085
+ def build_block_message(send, init, var_acc, var_elem, body); end
3086
+
3087
+ # pkg:gem/rubocop-performance#lib/rubocop/cop/performance/sum.rb:223
3088
+ def build_good_method(init, block_pass = T.unsafe(nil)); end
3089
+
3090
+ # pkg:gem/rubocop-performance#lib/rubocop/cop/performance/sum.rb:236
3091
+ def build_method_bad_method(init, method, operation); end
3092
+
3093
+ # pkg:gem/rubocop-performance#lib/rubocop/cop/performance/sum.rb:198
3094
+ def build_method_message(node, method, init, operation); end
3095
+
3096
+ # pkg:gem/rubocop-performance#lib/rubocop/cop/performance/sum.rb:209
3097
+ def build_sum_map_message(send_node, init); end
3098
+
3099
+ # pkg:gem/rubocop-performance#lib/rubocop/cop/performance/sum.rb:155
3100
+ def empty_array_literal?(node); end
3101
+
3102
+ # pkg:gem/rubocop-performance#lib/rubocop/cop/performance/sum.rb:130
3103
+ def handle_sum_candidate(node); end
3104
+
3105
+ # pkg:gem/rubocop-performance#lib/rubocop/cop/performance/sum.rb:143
3106
+ def handle_sum_map_candidate(node); end
3107
+
3108
+ # pkg:gem/rubocop-performance#lib/rubocop/cop/performance/sum.rb:261
3109
+ def method_call_with_args_range(node); end
3110
+
3111
+ # pkg:gem/rubocop-performance#lib/rubocop/cop/performance/sum.rb:194
3112
+ def sum_block_range(send, node); end
3113
+
3114
+ # pkg:gem/rubocop-performance#lib/rubocop/cop/performance/sum.rb:190
3115
+ def sum_map_range(map, sum); end
3116
+
3117
+ # pkg:gem/rubocop-performance#lib/rubocop/cop/performance/sum.rb:186
3118
+ def sum_method_range(node); end
3119
+ end
3120
+
3121
+ # pkg:gem/rubocop-performance#lib/rubocop/cop/performance/sum.rb:77
3122
+ RuboCop::Cop::Performance::Sum::MSG = T.let(T.unsafe(nil), String)
3123
+
3124
+ # pkg:gem/rubocop-performance#lib/rubocop/cop/performance/sum.rb:78
3125
+ RuboCop::Cop::Performance::Sum::MSG_IF_NO_INIT_VALUE = T.let(T.unsafe(nil), String)
3126
+
3127
+ # pkg:gem/rubocop-performance#lib/rubocop/cop/performance/sum.rb:80
3128
+ RuboCop::Cop::Performance::Sum::RESTRICT_ON_SEND = T.let(T.unsafe(nil), Array)
3129
+
3130
+ # Checks for .times.map calls.
3131
+ # In most cases such calls can be replaced
3132
+ # with an explicit array creation.
3133
+ #
3134
+ # @safety
3135
+ # This cop's autocorrection is unsafe because `Integer#times` does nothing if receiver is 0
3136
+ # or less. However, `Array.new` raises an error if argument is less than 0.
3137
+ #
3138
+ # For example:
3139
+ #
3140
+ # [source,ruby]
3141
+ # ----
3142
+ # -1.times{} # does nothing
3143
+ # Array.new(-1) # ArgumentError: negative array size
3144
+ # ----
3145
+ #
3146
+ # @example
3147
+ # # bad
3148
+ # 9.times.map do |i|
3149
+ # i.to_s
3150
+ # end
3151
+ #
3152
+ # # good
3153
+ # Array.new(9) do |i|
3154
+ # i.to_s
3155
+ # end
3156
+ #
3157
+ # pkg:gem/rubocop-performance#lib/rubocop/cop/performance/times_map.rb:32
3158
+ class RuboCop::Cop::Performance::TimesMap < ::RuboCop::Cop::Base
3159
+ extend ::RuboCop::Cop::AutoCorrector
3160
+
3161
+ # pkg:gem/rubocop-performance#lib/rubocop/cop/performance/times_map.rb:51
3162
+ def on_block(node); end
3163
+
3164
+ # pkg:gem/rubocop-performance#lib/rubocop/cop/performance/times_map.rb:49
3165
+ def on_csend(node); end
3166
+
3167
+ # pkg:gem/rubocop-performance#lib/rubocop/cop/performance/times_map.rb:55
3168
+ def on_itblock(node); end
3169
+
3170
+ # pkg:gem/rubocop-performance#lib/rubocop/cop/performance/times_map.rb:54
3171
+ def on_numblock(node); end
3172
+
3173
+ # pkg:gem/rubocop-performance#lib/rubocop/cop/performance/times_map.rb:46
3174
+ def on_send(node); end
3175
+
3176
+ # pkg:gem/rubocop-performance#lib/rubocop/cop/performance/times_map.rb:39
3177
+ def times_map_call(param0 = T.unsafe(nil)); end
3178
+
3179
+ private
3180
+
3181
+ # pkg:gem/rubocop-performance#lib/rubocop/cop/performance/times_map.rb:59
3182
+ def check(node); end
3183
+
3184
+ # pkg:gem/rubocop-performance#lib/rubocop/cop/performance/times_map.rb:71
3185
+ def handleable_receiver?(node); end
3186
+
3187
+ # pkg:gem/rubocop-performance#lib/rubocop/cop/performance/times_map.rb:78
3188
+ def message(map_or_collect, count); end
3189
+ end
3190
+
3191
+ # pkg:gem/rubocop-performance#lib/rubocop/cop/performance/times_map.rb:35
3192
+ RuboCop::Cop::Performance::TimesMap::MESSAGE = T.let(T.unsafe(nil), String)
3193
+
3194
+ # pkg:gem/rubocop-performance#lib/rubocop/cop/performance/times_map.rb:36
3195
+ RuboCop::Cop::Performance::TimesMap::MESSAGE_ONLY_IF = T.let(T.unsafe(nil), String)
3196
+
3197
+ # pkg:gem/rubocop-performance#lib/rubocop/cop/performance/times_map.rb:37
3198
+ RuboCop::Cop::Performance::TimesMap::RESTRICT_ON_SEND = T.let(T.unsafe(nil), Array)
3199
+
3200
+ # In Ruby 2.3 or later, use unary plus operator to unfreeze a string
3201
+ # literal instead of `String#dup` and `String.new`.
3202
+ # Unary plus operator is faster than `String#dup`.
3203
+ #
3204
+ # @safety
3205
+ # This cop's autocorrection is unsafe because `String.new` (without operator) is not
3206
+ # exactly the same as `+''`. These differ in encoding. `String.new.encoding` is always
3207
+ # `ASCII-8BIT`. However, `(+'').encoding` is the same as script encoding(e.g. `UTF-8`).
3208
+ # if you expect `ASCII-8BIT` encoding, disable this cop.
3209
+ #
3210
+ # @example
3211
+ # # bad
3212
+ # ''.dup # when Ruby 3.2 or lower
3213
+ # "something".dup # when Ruby 3.2 or lower
3214
+ # String.new
3215
+ # String.new('')
3216
+ # String.new('something')
3217
+ #
3218
+ # # good
3219
+ # +'something'
3220
+ # +''
3221
+ #
3222
+ # pkg:gem/rubocop-performance#lib/rubocop/cop/performance/unfreeze_string.rb:27
3223
+ class RuboCop::Cop::Performance::UnfreezeString < ::RuboCop::Cop::Base
3224
+ extend ::RuboCop::Cop::AutoCorrector
3225
+ extend ::RuboCop::Cop::TargetRubyVersion
3226
+
3227
+ # pkg:gem/rubocop-performance#lib/rubocop/cop/performance/unfreeze_string.rb:36
3228
+ def dup_string?(param0 = T.unsafe(nil)); end
3229
+
3230
+ # pkg:gem/rubocop-performance#lib/rubocop/cop/performance/unfreeze_string.rb:47
3231
+ def on_send(node); end
3232
+
3233
+ # pkg:gem/rubocop-performance#lib/rubocop/cop/performance/unfreeze_string.rb:40
3234
+ def string_new?(param0 = T.unsafe(nil)); end
3235
+
3236
+ private
3237
+
3238
+ # pkg:gem/rubocop-performance#lib/rubocop/cop/performance/unfreeze_string.rb:60
3239
+ def string_value(node); end
3240
+ end
3241
+
3242
+ # pkg:gem/rubocop-performance#lib/rubocop/cop/performance/unfreeze_string.rb:33
3243
+ RuboCop::Cop::Performance::UnfreezeString::MSG = T.let(T.unsafe(nil), String)
3244
+
3245
+ # pkg:gem/rubocop-performance#lib/rubocop/cop/performance/unfreeze_string.rb:34
3246
+ RuboCop::Cop::Performance::UnfreezeString::RESTRICT_ON_SEND = T.let(T.unsafe(nil), Array)
3247
+
3248
+ # Identifies places where `URI::Parser.new` can be replaced by `URI::DEFAULT_PARSER`.
3249
+ #
3250
+ # @example
3251
+ # # bad
3252
+ # URI::Parser.new
3253
+ #
3254
+ # # good
3255
+ # URI::DEFAULT_PARSER
3256
+ #
3257
+ # pkg:gem/rubocop-performance#lib/rubocop/cop/performance/uri_default_parser.rb:15
3258
+ class RuboCop::Cop::Performance::UriDefaultParser < ::RuboCop::Cop::Base
3259
+ extend ::RuboCop::Cop::AutoCorrector
3260
+
3261
+ # pkg:gem/rubocop-performance#lib/rubocop/cop/performance/uri_default_parser.rb:27
3262
+ def on_send(node); end
3263
+
3264
+ # pkg:gem/rubocop-performance#lib/rubocop/cop/performance/uri_default_parser.rb:21
3265
+ def uri_parser_new?(param0 = T.unsafe(nil)); end
3266
+ end
3267
+
3268
+ # pkg:gem/rubocop-performance#lib/rubocop/cop/performance/uri_default_parser.rb:18
3269
+ RuboCop::Cop::Performance::UriDefaultParser::MSG = T.let(T.unsafe(nil), String)
3270
+
3271
+ # pkg:gem/rubocop-performance#lib/rubocop/cop/performance/uri_default_parser.rb:19
3272
+ RuboCop::Cop::Performance::UriDefaultParser::RESTRICT_ON_SEND = T.let(T.unsafe(nil), Array)
3273
+
3274
+ # Checks for `map { |id| [id] }` and suggests replacing it with `zip`.
3275
+ #
3276
+ # @safety
3277
+ # This cop is unsafe for novel definitions of `map` and `collect`
3278
+ # on non-Enumerable objects that do not respond to `zip`.
3279
+ # To make your object enumerable, define an `each` method
3280
+ # as described in https://ruby-doc.org/core/Enumerable.html
3281
+ #
3282
+ # @example
3283
+ # # bad
3284
+ # [1, 2, 3].map { |id| [id] }
3285
+ #
3286
+ # # good
3287
+ # [1, 2, 3].zip
3288
+ #
3289
+ # pkg:gem/rubocop-performance#lib/rubocop/cop/performance/zip_without_block.rb:20
3290
+ class RuboCop::Cop::Performance::ZipWithoutBlock < ::RuboCop::Cop::Base
3291
+ extend ::RuboCop::Cop::AutoCorrector
3292
+
3293
+ # pkg:gem/rubocop-performance#lib/rubocop/cop/performance/zip_without_block.rb:27
3294
+ def map_with_array?(param0 = T.unsafe(nil)); end
3295
+
3296
+ # pkg:gem/rubocop-performance#lib/rubocop/cop/performance/zip_without_block.rb:40
3297
+ def on_csend(node); end
3298
+
3299
+ # pkg:gem/rubocop-performance#lib/rubocop/cop/performance/zip_without_block.rb:35
3300
+ def on_send(node); end
3301
+
3302
+ private
3303
+
3304
+ # pkg:gem/rubocop-performance#lib/rubocop/cop/performance/zip_without_block.rb:51
3305
+ def offense_range(node); end
3306
+
3307
+ # pkg:gem/rubocop-performance#lib/rubocop/cop/performance/zip_without_block.rb:44
3308
+ def register_offense(node); end
3309
+ end
3310
+
3311
+ # pkg:gem/rubocop-performance#lib/rubocop/cop/performance/zip_without_block.rb:23
3312
+ RuboCop::Cop::Performance::ZipWithoutBlock::MSG = T.let(T.unsafe(nil), String)
3313
+
3314
+ # pkg:gem/rubocop-performance#lib/rubocop/cop/performance/zip_without_block.rb:24
3315
+ RuboCop::Cop::Performance::ZipWithoutBlock::RESTRICT_ON_SEND = T.let(T.unsafe(nil), Set)
3316
+
3317
+ # Common functionality for handling regexp metacharacters.
3318
+ #
3319
+ # pkg:gem/rubocop-performance#lib/rubocop/cop/mixin/regexp_metacharacter.rb:6
3320
+ module RuboCop::Cop::RegexpMetacharacter
3321
+ private
3322
+
3323
+ # pkg:gem/rubocop-performance#lib/rubocop/cop/mixin/regexp_metacharacter.rb:63
3324
+ def drop_end_metacharacter(regexp_string); end
3325
+
3326
+ # pkg:gem/rubocop-performance#lib/rubocop/cop/mixin/regexp_metacharacter.rb:55
3327
+ def drop_start_metacharacter(regexp_string); end
3328
+
3329
+ # pkg:gem/rubocop-performance#lib/rubocop/cop/mixin/regexp_metacharacter.rb:15
3330
+ def literal_at_end?(regexp); end
3331
+
3332
+ # pkg:gem/rubocop-performance#lib/rubocop/cop/mixin/regexp_metacharacter.rb:41
3333
+ def literal_at_end_with_backslash_z?(regex_str); end
3334
+
3335
+ # pkg:gem/rubocop-performance#lib/rubocop/cop/mixin/regexp_metacharacter.rb:48
3336
+ def literal_at_end_with_dollar?(regex_str); end
3337
+
3338
+ # pkg:gem/rubocop-performance#lib/rubocop/cop/mixin/regexp_metacharacter.rb:9
3339
+ def literal_at_start?(regexp); end
3340
+
3341
+ # pkg:gem/rubocop-performance#lib/rubocop/cop/mixin/regexp_metacharacter.rb:21
3342
+ def literal_at_start_with_backslash_a?(regex_str); end
3343
+
3344
+ # pkg:gem/rubocop-performance#lib/rubocop/cop/mixin/regexp_metacharacter.rb:31
3345
+ def literal_at_start_with_caret?(regex_str); end
3346
+
3347
+ # pkg:gem/rubocop-performance#lib/rubocop/cop/mixin/regexp_metacharacter.rb:71
3348
+ def safe_multiline?; end
3349
+ end
3350
+
3351
+ # Common functionality for cops checking `Enumerable#sort` blocks.
3352
+ #
3353
+ # pkg:gem/rubocop-performance#lib/rubocop/cop/mixin/sort_block.rb:6
3354
+ module RuboCop::Cop::SortBlock
3355
+ include ::RuboCop::Cop::RangeHelp
3356
+ extend ::RuboCop::AST::NodePattern::Macros
3357
+
3358
+ # pkg:gem/rubocop-performance#lib/rubocop/cop/mixin/sort_block.rb:24
3359
+ def replaceable_body?(param0 = T.unsafe(nil), param1, param2); end
3360
+
3361
+ # pkg:gem/rubocop-performance#lib/rubocop/cop/mixin/sort_block.rb:10
3362
+ def sort_with_block?(param0 = T.unsafe(nil)); end
3363
+
3364
+ # pkg:gem/rubocop-performance#lib/rubocop/cop/mixin/sort_block.rb:17
3365
+ def sort_with_numblock?(param0 = T.unsafe(nil)); end
3366
+
3367
+ private
3368
+
3369
+ # pkg:gem/rubocop-performance#lib/rubocop/cop/mixin/sort_block.rb:30
3370
+ def sort_range(send, node); end
3371
+ end
3372
+
3373
+ # RuboCop Performance project namespace.
3374
+ #
3375
+ # pkg:gem/rubocop-performance#lib/rubocop/performance.rb:5
3376
+ module RuboCop::Performance; end
3377
+
3378
+ # A plugin that integrates RuboCop Performance with RuboCop's plugin system.
3379
+ #
3380
+ # pkg:gem/rubocop-performance#lib/rubocop/performance/plugin.rb:8
3381
+ class RuboCop::Performance::Plugin < ::LintRoller::Plugin
3382
+ # pkg:gem/rubocop-performance#lib/rubocop/performance/plugin.rb:9
3383
+ def about; end
3384
+
3385
+ # pkg:gem/rubocop-performance#lib/rubocop/performance/plugin.rb:22
3386
+ def rules(_context); end
3387
+
3388
+ # pkg:gem/rubocop-performance#lib/rubocop/performance/plugin.rb:18
3389
+ def supported?(context); end
3390
+ end
3391
+
3392
+ # This module holds the RuboCop Performance version information.
3393
+ #
3394
+ # pkg:gem/rubocop-performance#lib/rubocop/performance/version.rb:6
3395
+ module RuboCop::Performance::Version
3396
+ class << self
3397
+ # pkg:gem/rubocop-performance#lib/rubocop/performance/version.rb:9
3398
+ def document_version; end
3399
+ end
3400
+ end
3401
+
3402
+ # pkg:gem/rubocop-performance#lib/rubocop/performance/version.rb:7
3403
+ RuboCop::Performance::Version::STRING = T.let(T.unsafe(nil), String)