rubocop 1.1.0 → 1.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +14 -3
- data/config/default.yml +31 -5
- data/exe/rubocop +1 -1
- data/lib/rubocop.rb +4 -0
- data/lib/rubocop/cop/layout/else_alignment.rb +15 -2
- data/lib/rubocop/cop/layout/end_alignment.rb +3 -3
- data/lib/rubocop/cop/layout/hash_alignment.rb +4 -4
- data/lib/rubocop/cop/layout/space_around_block_parameters.rb +24 -18
- data/lib/rubocop/cop/layout/space_inside_parens.rb +35 -13
- data/lib/rubocop/cop/lint/else_layout.rb +29 -3
- data/lib/rubocop/cop/lint/empty_block.rb +15 -2
- data/lib/rubocop/cop/lint/loop.rb +0 -4
- data/lib/rubocop/cop/lint/nested_percent_literal.rb +14 -0
- data/lib/rubocop/cop/lint/no_return_in_begin_end_blocks.rb +58 -0
- data/lib/rubocop/cop/lint/useless_setter_call.rb +6 -1
- data/lib/rubocop/cop/mixin/configurable_numbering.rb +3 -3
- data/lib/rubocop/cop/naming/binary_operator_parameter_name.rb +11 -1
- data/lib/rubocop/cop/naming/heredoc_delimiter_case.rb +11 -5
- data/lib/rubocop/cop/naming/memoized_instance_variable_name.rb +67 -18
- data/lib/rubocop/cop/naming/variable_number.rb +82 -8
- data/lib/rubocop/cop/style/bisected_attr_accessor.rb +0 -4
- data/lib/rubocop/cop/style/case_like_if.rb +0 -4
- data/lib/rubocop/cop/style/collection_compact.rb +85 -0
- data/lib/rubocop/cop/style/double_negation.rb +6 -1
- data/lib/rubocop/cop/style/hash_syntax.rb +3 -3
- data/lib/rubocop/cop/style/keyword_parameters_order.rb +12 -0
- data/lib/rubocop/cop/style/mixin_grouping.rb +0 -4
- data/lib/rubocop/cop/style/negated_if_else_condition.rb +99 -0
- data/lib/rubocop/cop/style/raise_args.rb +21 -6
- data/lib/rubocop/cop/style/redundant_regexp_escape.rb +1 -1
- data/lib/rubocop/cop/util.rb +4 -0
- data/lib/rubocop/ext/regexp_node.rb +10 -5
- data/lib/rubocop/ext/regexp_parser.rb +9 -2
- data/lib/rubocop/formatter/formatter_set.rb +1 -0
- data/lib/rubocop/formatter/git_hub_actions_formatter.rb +47 -0
- data/lib/rubocop/options.rb +2 -0
- data/lib/rubocop/version.rb +1 -1
- metadata +7 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9139e9c7213e73e6f44db7e88265254dc4b4e11ab0fa38b0fa88268070ff0a6a
|
4
|
+
data.tar.gz: 5590d626e845237529e7e21dbc162b2704fdbe5f37a39f0e29d3e164b550a03e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 04ce9f16ffe193e6a048a2fe2b5c0015a148becdfc25bcd67efdd5cf207727eed3ab3440bbf5f8f2473868d9f697fb88b2c2f810bfe217fb23153d010318bde8
|
7
|
+
data.tar.gz: bd33137303ca551db1a8e67ad96bb14b376207caf88ba0c82efb3202c2373b94f22bd9e19f3a8b9cfd475bc6955078c13a87b8236e6703e8ad48c2b14a2cb271
|
data/README.md
CHANGED
@@ -50,7 +50,7 @@ To prevent an unwanted RuboCop update you might want to use a conservative versi
|
|
50
50
|
in your `Gemfile`:
|
51
51
|
|
52
52
|
```rb
|
53
|
-
gem 'rubocop', '~> 1.
|
53
|
+
gem 'rubocop', '~> 1.2', require: false
|
54
54
|
```
|
55
55
|
|
56
56
|
See [versioning](https://docs.rubocop.org/rubocop/1.0/versioning.html) for further details.
|
@@ -70,12 +70,12 @@ You can read a lot more about RuboCop in its [official docs](https://docs.ruboco
|
|
70
70
|
|
71
71
|
## Compatibility
|
72
72
|
|
73
|
-
RuboCop supports the following Ruby implementations:
|
73
|
+
RuboCop officially supports the following Ruby implementations:
|
74
74
|
|
75
75
|
* MRI 2.4+
|
76
76
|
* JRuby 9.2+
|
77
77
|
|
78
|
-
See [compatibility](https://docs.rubocop.org/rubocop/compatibility.html) for further details.
|
78
|
+
See the [compatibility documentation](https://docs.rubocop.org/rubocop/compatibility.html) for further details.
|
79
79
|
|
80
80
|
## Readme Badge
|
81
81
|
|
@@ -85,6 +85,15 @@ If you use RuboCop in your project, you can include one of these badges in your
|
|
85
85
|
|
86
86
|
[![Ruby Style Guide](https://img.shields.io/badge/code_style-community-brightgreen.svg)](https://rubystyle.guide)
|
87
87
|
|
88
|
+
|
89
|
+
Here are the Markdown snippets for the two badges:
|
90
|
+
|
91
|
+
``` markdown
|
92
|
+
[![Ruby Style Guide](https://img.shields.io/badge/code_style-rubocop-brightgreen.svg)](https://github.com/rubocop-hq/rubocop)
|
93
|
+
|
94
|
+
[![Ruby Style Guide](https://img.shields.io/badge/code_style-community-brightgreen.svg)](https://rubystyle.guide)
|
95
|
+
```
|
96
|
+
|
88
97
|
## Team
|
89
98
|
|
90
99
|
Here's a list of RuboCop's core developers:
|
@@ -100,6 +109,8 @@ Here's a list of RuboCop's core developers:
|
|
100
109
|
* [Benjamin Quorning](https://github.com/bquorning)
|
101
110
|
* [Marc-André Lafortune](https://github.com/marcandre)
|
102
111
|
|
112
|
+
See the [team page](https://docs.rubocop.org/rubocop/about/team.html) for more details.
|
113
|
+
|
103
114
|
## Logo
|
104
115
|
|
105
116
|
RuboCop's logo was created by [Dimiter Petrov](https://www.chadomoto.com/). You can find the logo in various
|
data/config/default.yml
CHANGED
@@ -1478,6 +1478,7 @@ Lint/ElseLayout:
|
|
1478
1478
|
Description: 'Check for odd code arrangement in an else block.'
|
1479
1479
|
Enabled: true
|
1480
1480
|
VersionAdded: '0.17'
|
1481
|
+
VersionChanged: '1.2'
|
1481
1482
|
|
1482
1483
|
Lint/EmptyBlock:
|
1483
1484
|
Description: 'This cop checks for blocks without a body.'
|
@@ -1679,6 +1680,11 @@ Lint/NextWithoutAccumulator:
|
|
1679
1680
|
Enabled: true
|
1680
1681
|
VersionAdded: '0.36'
|
1681
1682
|
|
1683
|
+
Lint/NoReturnInBeginEndBlocks:
|
1684
|
+
Description: 'Do not `return` inside `begin..end` blocks in assignment contexts.'
|
1685
|
+
Enabled: pending
|
1686
|
+
VersionAdded: '1.2'
|
1687
|
+
|
1682
1688
|
Lint/NonDeterministicRequireOrder:
|
1683
1689
|
Description: 'Always sort arrays returned by Dir.glob when requiring files.'
|
1684
1690
|
Enabled: true
|
@@ -2036,8 +2042,9 @@ Lint/UselessMethodDefinition:
|
|
2036
2042
|
Lint/UselessSetterCall:
|
2037
2043
|
Description: 'Checks for useless setter call to a local variable.'
|
2038
2044
|
Enabled: true
|
2045
|
+
SafeAutoCorrect: false
|
2039
2046
|
VersionAdded: '0.13'
|
2040
|
-
VersionChanged: '
|
2047
|
+
VersionChanged: '1.2'
|
2041
2048
|
Safe: false
|
2042
2049
|
|
2043
2050
|
Lint/UselessTimes:
|
@@ -2181,6 +2188,7 @@ Naming/BinaryOperatorParameterName:
|
|
2181
2188
|
StyleGuide: '#other-arg'
|
2182
2189
|
Enabled: true
|
2183
2190
|
VersionAdded: '0.50'
|
2191
|
+
VersionChanged: '1.2'
|
2184
2192
|
|
2185
2193
|
Naming/BlockParameterName:
|
2186
2194
|
Description: >-
|
@@ -2287,6 +2295,7 @@ Naming/HeredocDelimiterCase:
|
|
2287
2295
|
StyleGuide: '#heredoc-delimiters'
|
2288
2296
|
Enabled: true
|
2289
2297
|
VersionAdded: '0.50'
|
2298
|
+
VersionChanged: '1.2'
|
2290
2299
|
EnforcedStyle: uppercase
|
2291
2300
|
SupportedStyles:
|
2292
2301
|
- lowercase
|
@@ -2305,7 +2314,7 @@ Naming/MemoizedInstanceVariableName:
|
|
2305
2314
|
Memoized method name should match memo instance variable name.
|
2306
2315
|
Enabled: true
|
2307
2316
|
VersionAdded: '0.53'
|
2308
|
-
VersionChanged: '
|
2317
|
+
VersionChanged: '1.2'
|
2309
2318
|
EnforcedStyleForLeadingUnderscores: disallowed
|
2310
2319
|
SupportedStylesForLeadingUnderscores:
|
2311
2320
|
- disallowed
|
@@ -2403,14 +2412,18 @@ Naming/VariableName:
|
|
2403
2412
|
- camelCase
|
2404
2413
|
|
2405
2414
|
Naming/VariableNumber:
|
2406
|
-
Description: 'Use the configured style when numbering variables.'
|
2415
|
+
Description: 'Use the configured style when numbering symbols, methods and variables.'
|
2416
|
+
StyleGuide: '#snake-case-symbols-methods-vars-with-numbers'
|
2407
2417
|
Enabled: true
|
2408
2418
|
VersionAdded: '0.50'
|
2419
|
+
VersionChanged: '1.2'
|
2409
2420
|
EnforcedStyle: normalcase
|
2410
2421
|
SupportedStyles:
|
2411
2422
|
- snake_case
|
2412
2423
|
- normalcase
|
2413
2424
|
- non_integer
|
2425
|
+
CheckMethodNames: true
|
2426
|
+
CheckSymbols: true
|
2414
2427
|
|
2415
2428
|
#################### Security ##############################
|
2416
2429
|
|
@@ -2789,6 +2802,11 @@ Style/ClassVars:
|
|
2789
2802
|
Enabled: true
|
2790
2803
|
VersionAdded: '0.13'
|
2791
2804
|
|
2805
|
+
Style/CollectionCompact:
|
2806
|
+
Description: 'Use `{Array,Hash}#{compact,compact!}` instead of custom logic to reject nils.'
|
2807
|
+
Enabled: pending
|
2808
|
+
VersionAdded: '1.2'
|
2809
|
+
|
2792
2810
|
# Align with the style guide.
|
2793
2811
|
Style/CollectionMethods:
|
2794
2812
|
Description: 'Preferred collection methods.'
|
@@ -2986,7 +3004,7 @@ Style/DoubleNegation:
|
|
2986
3004
|
StyleGuide: '#no-bang-bang'
|
2987
3005
|
Enabled: true
|
2988
3006
|
VersionAdded: '0.19'
|
2989
|
-
VersionChanged: '
|
3007
|
+
VersionChanged: '1.2'
|
2990
3008
|
EnforcedStyle: allowed_in_returns
|
2991
3009
|
SafeAutoCorrect: false
|
2992
3010
|
SupportedStyles:
|
@@ -3611,6 +3629,13 @@ Style/NegatedIf:
|
|
3611
3629
|
- prefix
|
3612
3630
|
- postfix
|
3613
3631
|
|
3632
|
+
Style/NegatedIfElseCondition:
|
3633
|
+
Description: >-
|
3634
|
+
This cop checks for uses of `if-else` and ternary operators with a negated condition
|
3635
|
+
which can be simplified by inverting condition and swapping branches.
|
3636
|
+
Enabled: pending
|
3637
|
+
VersionAdded: '1.2'
|
3638
|
+
|
3614
3639
|
Style/NegatedUnless:
|
3615
3640
|
Description: 'Favor if over unless for negative conditions.'
|
3616
3641
|
StyleGuide: '#if-for-negatives'
|
@@ -3888,11 +3913,12 @@ Style/RaiseArgs:
|
|
3888
3913
|
StyleGuide: '#exception-class-messages'
|
3889
3914
|
Enabled: true
|
3890
3915
|
VersionAdded: '0.14'
|
3891
|
-
VersionChanged: '
|
3916
|
+
VersionChanged: '1.2'
|
3892
3917
|
EnforcedStyle: exploded
|
3893
3918
|
SupportedStyles:
|
3894
3919
|
- compact # raise Exception.new(msg)
|
3895
3920
|
- exploded # raise Exception, msg
|
3921
|
+
AllowedCompactTypes: []
|
3896
3922
|
|
3897
3923
|
Style/RandomWithOffset:
|
3898
3924
|
Description: >-
|
data/exe/rubocop
CHANGED
data/lib/rubocop.rb
CHANGED
@@ -298,6 +298,7 @@ require_relative 'rubocop/cop/lint/multiple_comparison'
|
|
298
298
|
require_relative 'rubocop/cop/lint/nested_method_definition'
|
299
299
|
require_relative 'rubocop/cop/lint/nested_percent_literal'
|
300
300
|
require_relative 'rubocop/cop/lint/next_without_accumulator'
|
301
|
+
require_relative 'rubocop/cop/lint/no_return_in_begin_end_blocks'
|
301
302
|
require_relative 'rubocop/cop/lint/non_deterministic_require_order'
|
302
303
|
require_relative 'rubocop/cop/lint/non_local_exit_from_iterator'
|
303
304
|
require_relative 'rubocop/cop/lint/number_conversion'
|
@@ -409,6 +410,7 @@ require_relative 'rubocop/cop/style/class_equality_comparison'
|
|
409
410
|
require_relative 'rubocop/cop/style/class_methods'
|
410
411
|
require_relative 'rubocop/cop/style/class_methods_definitions'
|
411
412
|
require_relative 'rubocop/cop/style/class_vars'
|
413
|
+
require_relative 'rubocop/cop/style/collection_compact'
|
412
414
|
require_relative 'rubocop/cop/style/collection_methods'
|
413
415
|
require_relative 'rubocop/cop/style/colon_method_call'
|
414
416
|
require_relative 'rubocop/cop/style/colon_method_definition'
|
@@ -496,6 +498,7 @@ require_relative 'rubocop/cop/style/multiline_when_then'
|
|
496
498
|
require_relative 'rubocop/cop/style/multiple_comparison'
|
497
499
|
require_relative 'rubocop/cop/style/mutable_constant'
|
498
500
|
require_relative 'rubocop/cop/style/negated_if'
|
501
|
+
require_relative 'rubocop/cop/style/negated_if_else_condition'
|
499
502
|
require_relative 'rubocop/cop/style/negated_unless'
|
500
503
|
require_relative 'rubocop/cop/style/negated_while'
|
501
504
|
require_relative 'rubocop/cop/style/nested_modifier'
|
@@ -602,6 +605,7 @@ require_relative 'rubocop/formatter/disabled_config_formatter'
|
|
602
605
|
require_relative 'rubocop/formatter/emacs_style_formatter'
|
603
606
|
require_relative 'rubocop/formatter/file_list_formatter'
|
604
607
|
require_relative 'rubocop/formatter/fuubar_style_formatter'
|
608
|
+
require_relative 'rubocop/formatter/git_hub_actions_formatter'
|
605
609
|
require_relative 'rubocop/formatter/html_formatter'
|
606
610
|
require_relative 'rubocop/formatter/json_formatter'
|
607
611
|
require_relative 'rubocop/formatter/junit_formatter'
|
@@ -4,7 +4,7 @@ module RuboCop
|
|
4
4
|
module Cop
|
5
5
|
module Layout
|
6
6
|
# This cop checks the alignment of else keywords. Normally they should
|
7
|
-
# be aligned with an if/unless/while/until/begin/def keyword, but there
|
7
|
+
# be aligned with an if/unless/while/until/begin/def/rescue keyword, but there
|
8
8
|
# are special cases when they should follow the same rules as the
|
9
9
|
# alignment of end.
|
10
10
|
#
|
@@ -93,7 +93,13 @@ module RuboCop
|
|
93
93
|
case parent.type
|
94
94
|
when :def, :defs then base_for_method_definition(parent)
|
95
95
|
when :kwbegin then parent.loc.begin
|
96
|
-
when :block
|
96
|
+
when :block
|
97
|
+
assignment_node = assignment_node(parent)
|
98
|
+
if same_line?(parent, assignment_node)
|
99
|
+
assignment_node.source_range
|
100
|
+
else
|
101
|
+
parent.send_node.source_range
|
102
|
+
end
|
97
103
|
else node.loc.keyword
|
98
104
|
end
|
99
105
|
end
|
@@ -136,6 +142,13 @@ module RuboCop
|
|
136
142
|
)
|
137
143
|
add_offense(else_range, location: else_range, message: message)
|
138
144
|
end
|
145
|
+
|
146
|
+
def assignment_node(node)
|
147
|
+
assignment_node = node.ancestors.first
|
148
|
+
return unless assignment_node&.assignment?
|
149
|
+
|
150
|
+
assignment_node
|
151
|
+
end
|
139
152
|
end
|
140
153
|
end
|
141
154
|
end
|
@@ -137,10 +137,10 @@ module RuboCop
|
|
137
137
|
def asgn_variable_align_with(outer_node, inner_node)
|
138
138
|
expr = outer_node.source_range
|
139
139
|
|
140
|
-
if
|
141
|
-
range_between(expr.begin_pos, inner_node.loc.keyword.end_pos)
|
142
|
-
else
|
140
|
+
if line_break_before_keyword?(expr, inner_node)
|
143
141
|
inner_node.loc.keyword
|
142
|
+
else
|
143
|
+
range_between(expr.begin_pos, inner_node.loc.keyword.end_pos)
|
144
144
|
end
|
145
145
|
end
|
146
146
|
|
@@ -296,13 +296,13 @@ module RuboCop
|
|
296
296
|
# just give each lambda the same reference and they would all get the
|
297
297
|
# last value of each. A local variable fixes the problem.
|
298
298
|
|
299
|
-
if
|
300
|
-
delta_value = delta[:key] || 0
|
301
|
-
correct_no_value(corrector, delta_value, node.source_range)
|
302
|
-
else
|
299
|
+
if node.value
|
303
300
|
correct_key_value(corrector, delta, node.key.source_range,
|
304
301
|
node.value.source_range,
|
305
302
|
node.loc.operator)
|
303
|
+
else
|
304
|
+
delta_value = delta[:key] || 0
|
305
|
+
correct_no_value(corrector, delta_value, node.source_range)
|
306
306
|
end
|
307
307
|
end
|
308
308
|
|
@@ -54,17 +54,11 @@ module RuboCop
|
|
54
54
|
end
|
55
55
|
|
56
56
|
def check_inside_pipes(arguments)
|
57
|
-
opening_pipe, closing_pipe = pipes(arguments)
|
58
|
-
|
59
57
|
case style
|
60
58
|
when :no_space
|
61
|
-
check_no_space_style_inside_pipes(arguments
|
62
|
-
opening_pipe,
|
63
|
-
closing_pipe)
|
59
|
+
check_no_space_style_inside_pipes(arguments)
|
64
60
|
when :space
|
65
|
-
check_space_style_inside_pipes(arguments
|
66
|
-
opening_pipe,
|
67
|
-
closing_pipe)
|
61
|
+
check_space_style_inside_pipes(arguments)
|
68
62
|
end
|
69
63
|
end
|
70
64
|
|
@@ -76,22 +70,29 @@ module RuboCop
|
|
76
70
|
closing_pipe, 'after closing `|`')
|
77
71
|
end
|
78
72
|
|
79
|
-
def check_no_space_style_inside_pipes(
|
73
|
+
def check_no_space_style_inside_pipes(arguments)
|
74
|
+
args = arguments.children
|
75
|
+
opening_pipe, closing_pipe = pipes(arguments)
|
76
|
+
|
80
77
|
first = args.first.source_range
|
81
78
|
last = args.last.source_range
|
82
79
|
|
83
80
|
check_no_space(opening_pipe.end_pos, first.begin_pos,
|
84
81
|
'Space before first')
|
85
|
-
check_no_space(last_end_pos_inside_pipes(last),
|
82
|
+
check_no_space(last_end_pos_inside_pipes(arguments, last),
|
86
83
|
closing_pipe.begin_pos, 'Space after last')
|
87
84
|
end
|
88
85
|
|
89
|
-
def check_space_style_inside_pipes(
|
90
|
-
|
91
|
-
|
86
|
+
def check_space_style_inside_pipes(arguments)
|
87
|
+
opening_pipe, closing_pipe = pipes(arguments)
|
88
|
+
|
89
|
+
check_opening_pipe_space(arguments, opening_pipe)
|
90
|
+
check_closing_pipe_space(arguments, closing_pipe)
|
92
91
|
end
|
93
92
|
|
94
|
-
def check_opening_pipe_space(
|
93
|
+
def check_opening_pipe_space(arguments, opening_pipe)
|
94
|
+
args = arguments.children
|
95
|
+
|
95
96
|
first_arg = args.first
|
96
97
|
range = first_arg.source_range
|
97
98
|
|
@@ -101,9 +102,11 @@ module RuboCop
|
|
101
102
|
'Extra space before first')
|
102
103
|
end
|
103
104
|
|
104
|
-
def check_closing_pipe_space(
|
105
|
+
def check_closing_pipe_space(arguments, closing_pipe)
|
106
|
+
args = arguments.children
|
107
|
+
|
105
108
|
last = args.last.source_range
|
106
|
-
last_end_pos = last_end_pos_inside_pipes(last)
|
109
|
+
last_end_pos = last_end_pos_inside_pipes(arguments, last)
|
107
110
|
|
108
111
|
check_space(last_end_pos, closing_pipe.begin_pos, last,
|
109
112
|
'after last block parameter')
|
@@ -111,9 +114,12 @@ module RuboCop
|
|
111
114
|
'Extra space after last')
|
112
115
|
end
|
113
116
|
|
114
|
-
def last_end_pos_inside_pipes(range)
|
117
|
+
def last_end_pos_inside_pipes(arguments, range)
|
115
118
|
pos = range.end_pos
|
116
|
-
|
119
|
+
num = pos - arguments.source_range.begin_pos
|
120
|
+
trailing_comma_index = arguments.source[num..-1].index(',')
|
121
|
+
|
122
|
+
trailing_comma_index ? pos + trailing_comma_index + 1 : pos
|
117
123
|
end
|
118
124
|
|
119
125
|
def check_each_arg(args)
|
@@ -11,10 +11,12 @@ module RuboCop
|
|
11
11
|
# # bad
|
12
12
|
# f( 3)
|
13
13
|
# g = (a + 3 )
|
14
|
+
# f( )
|
14
15
|
#
|
15
16
|
# # good
|
16
17
|
# f(3)
|
17
18
|
# g = (a + 3)
|
19
|
+
# f()
|
18
20
|
#
|
19
21
|
# @example EnforcedStyle: space
|
20
22
|
# # The `space` style enforces that parentheses have a space at the
|
@@ -44,11 +46,7 @@ module RuboCop
|
|
44
46
|
@processed_source = processed_source
|
45
47
|
|
46
48
|
if style == :space
|
47
|
-
|
48
|
-
add_offense(range, message: MSG_SPACE) do |corrector|
|
49
|
-
corrector.insert_before(range, ' ')
|
50
|
-
end
|
51
|
-
end
|
49
|
+
process_with_space_style(processed_source)
|
52
50
|
else
|
53
51
|
each_extraneous_space(processed_source.tokens) do |range|
|
54
52
|
add_offense(range) do |corrector|
|
@@ -60,6 +58,21 @@ module RuboCop
|
|
60
58
|
|
61
59
|
private
|
62
60
|
|
61
|
+
def process_with_space_style(processed_source)
|
62
|
+
processed_source.tokens.each_cons(2) do |token1, token2|
|
63
|
+
each_extraneous_space_in_empty_parens(token1, token2) do |range|
|
64
|
+
add_offense(range) do |corrector|
|
65
|
+
corrector.remove(range)
|
66
|
+
end
|
67
|
+
end
|
68
|
+
each_missing_space(token1, token2) do |range|
|
69
|
+
add_offense(range, message: MSG_SPACE) do |corrector|
|
70
|
+
corrector.insert_before(range, ' ')
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
63
76
|
def each_extraneous_space(tokens)
|
64
77
|
tokens.each_cons(2) do |token1, token2|
|
65
78
|
next unless parens?(token1, token2)
|
@@ -73,15 +86,21 @@ module RuboCop
|
|
73
86
|
end
|
74
87
|
end
|
75
88
|
|
76
|
-
def
|
77
|
-
|
78
|
-
next if can_be_ignored?(token1, token2)
|
89
|
+
def each_extraneous_space_in_empty_parens(token1, token2)
|
90
|
+
return unless token1.left_parens? && token2.right_parens?
|
79
91
|
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
92
|
+
return if range_between(token1.begin_pos, token2.end_pos).source == '()'
|
93
|
+
|
94
|
+
yield range_between(token1.end_pos, token2.begin_pos)
|
95
|
+
end
|
96
|
+
|
97
|
+
def each_missing_space(token1, token2)
|
98
|
+
return if can_be_ignored?(token1, token2)
|
99
|
+
|
100
|
+
if token1.left_parens?
|
101
|
+
yield range_between(token2.begin_pos, token2.begin_pos + 1)
|
102
|
+
elsif token2.right_parens?
|
103
|
+
yield range_between(token2.begin_pos, token2.end_pos)
|
85
104
|
end
|
86
105
|
end
|
87
106
|
|
@@ -96,6 +115,9 @@ module RuboCop
|
|
96
115
|
def can_be_ignored?(token1, token2)
|
97
116
|
return true unless parens?(token1, token2)
|
98
117
|
|
118
|
+
# Ignore empty parentheses.
|
119
|
+
return true if range_between(token1.begin_pos, token2.end_pos).source == '()'
|
120
|
+
|
99
121
|
# If the second token is a comment, that means that a line break
|
100
122
|
# follows, and that the rules for space inside don't apply.
|
101
123
|
return true if token2.comment?
|