rubocop-expert 0.1.0 → 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +3 -6
- data/lib/rubocop/cop/expert/redundant_parentheses_for_method_call.rb +82 -28
- data/lib/rubocop/expert/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: fe20794a04bdfc3cbc23a95d0ca85fbd3ef6f767049647a132f8ed47cf26c033
|
4
|
+
data.tar.gz: cf4f4e5aaecbc5ca138d7a0ca6fdf2df7db1b804b201c3a12f6efe0082e9a28d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5963fdad27ed7ed602f0b92b825f28943097b4323e41b38821a84c8eac5eab34176f439a72f938bbc0b69354c885ae207819a445b84b4c34b3fb7ff2b1ce06c8
|
7
|
+
data.tar.gz: bf452bcc544e79fd1d4b5e2993454919188a7eac3153b4393f288251ccc811fef2f0637a25b153554138ddfb20ac03494edb59678ce7651026de99769c454d44
|
data/README.md
CHANGED
@@ -1,5 +1,8 @@
|
|
1
1
|
# Rubocop::Expert
|
2
2
|
|
3
|
+
[](https://badge.fury.io/rb/rubocop-expert)
|
4
|
+
[](LICENSE.txt)
|
5
|
+
|
3
6
|
[RuboCop](https://github.com/rubocop-hq/rubocop/) custom cops for elegance.
|
4
7
|
|
5
8
|
## Installation
|
@@ -10,12 +13,6 @@ Add this line to Gemfile:
|
|
10
13
|
gem 'rubocop-akouryy'
|
11
14
|
```
|
12
15
|
|
13
|
-
Or install it yourself as:
|
14
|
-
|
15
|
-
```
|
16
|
-
gem install rubocop rubocop-rspec rubocop-akouryy
|
17
|
-
```
|
18
|
-
|
19
16
|
## Usage
|
20
17
|
|
21
18
|
Require this gem in .rubocop.yml:
|
@@ -47,6 +47,7 @@ module RuboCop
|
|
47
47
|
# # Parentheses are required.
|
48
48
|
# -foo(0)
|
49
49
|
# foo(0) + 1
|
50
|
+
# foo(0) ? bar(1) : baz(2)
|
50
51
|
# foo(0).bar
|
51
52
|
# foo(0){}
|
52
53
|
# foo 0, bar(1)
|
@@ -150,6 +151,23 @@ module RuboCop
|
|
150
151
|
add_offense node, location: :begin
|
151
152
|
end
|
152
153
|
|
154
|
+
PARENS_ALLOW_CHECKERS = %i[
|
155
|
+
among_multiple_args?
|
156
|
+
among_multiple_args_like?
|
157
|
+
array_element?
|
158
|
+
assoc_bracket_multiple_element?
|
159
|
+
default_of_optarg?
|
160
|
+
explicit_receiver?
|
161
|
+
hash_key_or_value?
|
162
|
+
high_operand?
|
163
|
+
implicit_call?
|
164
|
+
rescue_error_type?
|
165
|
+
splat_like?
|
166
|
+
when_cond?
|
167
|
+
with_arg_s_and_brace_block?
|
168
|
+
].freeze
|
169
|
+
private_constant :PARENS_ALLOW_CHECKERS
|
170
|
+
|
153
171
|
private def allowed_by_multiline_config? node
|
154
172
|
fn_ln = node.loc.selector&.line
|
155
173
|
first_arg_ln = node.arguments[0]&.loc&.line
|
@@ -167,25 +185,46 @@ module RuboCop
|
|
167
185
|
end
|
168
186
|
|
169
187
|
private def_node_matcher :among_multiple_args?, <<~PAT
|
170
|
-
^
|
171
|
-
|
172
|
-
|
173
|
-
|
188
|
+
^[
|
189
|
+
(send
|
190
|
+
!equal?(%0)
|
191
|
+
_
|
192
|
+
_ _ ...) #{'>=2 args; %0 is here' * 0}
|
193
|
+
#fn_style?]
|
174
194
|
PAT
|
175
195
|
|
176
|
-
private def_node_matcher :
|
177
|
-
^(
|
196
|
+
private def_node_matcher :among_multiple_args_like?, <<~PAT
|
197
|
+
^(
|
198
|
+
{return break next super}
|
199
|
+
_ _ ...) #{'>=1 values' * 0}
|
178
200
|
PAT
|
179
201
|
|
202
|
+
private def_node_matcher :arg_s?, '(send _ _ _ ...)' # >=1 args
|
203
|
+
|
180
204
|
private def_node_matcher :array_element?, '^(array ...)'
|
181
205
|
|
206
|
+
private def_node_matcher :assoc_bracket_multiple_element?, <<~PAT
|
207
|
+
^[
|
208
|
+
{
|
209
|
+
(send
|
210
|
+
!equal?(%0)
|
211
|
+
:[]
|
212
|
+
_ _ ...) #{'>=2 elements; %0 is here' * 0}
|
213
|
+
(send
|
214
|
+
!equal?(%0)
|
215
|
+
:[]=
|
216
|
+
_ _ ... #{'>=2 elements; %0 is here' * 0}
|
217
|
+
_)} #{': expr after "="' * 0}
|
218
|
+
!#fn_style?]
|
219
|
+
PAT
|
220
|
+
|
182
221
|
private def_node_matcher :bracket_receiver?, <<~PAT
|
183
222
|
^[
|
184
223
|
(send
|
185
224
|
equal?(%0)
|
186
225
|
{ :[] :[]= }
|
187
226
|
...)
|
188
|
-
|
227
|
+
!#fn_style?
|
189
228
|
]
|
190
229
|
PAT
|
191
230
|
|
@@ -211,10 +250,17 @@ module RuboCop
|
|
211
250
|
bracket_receiver?(node) || dot_receiver?(node)
|
212
251
|
end
|
213
252
|
|
214
|
-
private def_node_matcher :
|
253
|
+
private def_node_matcher :fn_style?, <<~PAT
|
254
|
+
{
|
255
|
+
(send nil? ...)
|
256
|
+
[
|
257
|
+
(send ...)
|
258
|
+
dot?]}
|
259
|
+
PAT
|
260
|
+
|
261
|
+
private def_node_matcher :hash_key_or_value?, <<~PAT
|
215
262
|
[
|
216
263
|
^^(hash ...)
|
217
|
-
^(pair _ equal?(%0))
|
218
264
|
]
|
219
265
|
PAT
|
220
266
|
|
@@ -225,10 +271,10 @@ module RuboCop
|
|
225
271
|
private def_node_matcher :high_method_operator_arg?, <<~PAT
|
226
272
|
^[
|
227
273
|
(send
|
228
|
-
|
274
|
+
_
|
229
275
|
#high_operator?
|
230
276
|
equal?(%0))
|
231
|
-
|
277
|
+
!#fn_style?
|
232
278
|
]
|
233
279
|
PAT
|
234
280
|
|
@@ -238,12 +284,14 @@ module RuboCop
|
|
238
284
|
equal?(%0)
|
239
285
|
#high_operator?
|
240
286
|
...)
|
241
|
-
|
287
|
+
!#fn_style?
|
288
|
+
!keyword_not?
|
242
289
|
]
|
243
290
|
PAT
|
244
291
|
|
245
292
|
private def high_operand? node
|
246
|
-
high_method_operand?(node) || high_special_operand?(node)
|
293
|
+
high_method_operand?(node) || high_special_operand?(node) ||
|
294
|
+
ternary_operand?(node)
|
247
295
|
end
|
248
296
|
|
249
297
|
private def high_operator? op
|
@@ -274,27 +322,33 @@ module RuboCop
|
|
274
322
|
end
|
275
323
|
|
276
324
|
private def parens_allowed? node
|
277
|
-
|
278
|
-
|
279
|
-
|
280
|
-
|
281
|
-
default_of_optarg?
|
282
|
-
explicit_receiver?
|
283
|
-
hash_element?
|
284
|
-
high_operand?
|
285
|
-
implicit_call?
|
286
|
-
splat_like?
|
287
|
-
when_cond?
|
288
|
-
with_arg_s_and_brace_block?
|
289
|
-
].any? do |sym|
|
290
|
-
__send__ sym, node
|
291
|
-
end
|
325
|
+
arg_s?(node) &&
|
326
|
+
PARENS_ALLOW_CHECKERS.any? do |sym|
|
327
|
+
__send__ sym, node
|
328
|
+
end
|
292
329
|
end
|
293
330
|
|
331
|
+
# covered by array_element?, but check again to ensure
|
332
|
+
private def_node_matcher :rescue_error_type?, <<~PAT
|
333
|
+
[
|
334
|
+
^^(resbody ...)
|
335
|
+
^(array ...)]
|
336
|
+
PAT
|
337
|
+
|
294
338
|
private def_node_matcher :special_operand?, '^({and or} ...)'
|
295
339
|
|
296
340
|
private def_node_matcher :splat_like?, '^({splat kwsplat block_pass} equal?(%0))'
|
297
341
|
|
342
|
+
private def_node_matcher :ternary_operand?, <<~PAT
|
343
|
+
{
|
344
|
+
^[(if ...) ternary?]
|
345
|
+
[
|
346
|
+
^^[(if ...) ternary?]
|
347
|
+
^{
|
348
|
+
(lvasgn _ equal?(%0))
|
349
|
+
(op_asgn _ _ equal?(%0))}]}
|
350
|
+
PAT
|
351
|
+
|
298
352
|
private def_node_matcher :when_cond?, '^(when equal?(%0) _)'
|
299
353
|
|
300
354
|
private def_node_matcher :with_arg_s_and_brace_block?, <<~PAT
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rubocop-expert
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- akouryy
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-08-
|
11
|
+
date: 2018-08-31 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rubocop
|