rubocop 1.20.0 → 1.21.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.
- checksums.yaml +4 -4
- data/README.md +1 -1
- data/config/default.yml +19 -6
- data/lib/rubocop/cop/base.rb +2 -2
- data/lib/rubocop/cop/bundler/insecure_protocol_source.rb +12 -11
- data/lib/rubocop/cop/correctors/lambda_literal_to_method_corrector.rb +2 -2
- data/lib/rubocop/cop/correctors/line_break_corrector.rb +1 -1
- data/lib/rubocop/cop/layout/argument_alignment.rb +1 -1
- data/lib/rubocop/cop/layout/class_structure.rb +2 -1
- data/lib/rubocop/cop/layout/end_alignment.rb +1 -1
- data/lib/rubocop/cop/layout/leading_comment_space.rb +1 -1
- data/lib/rubocop/cop/layout/line_length.rb +1 -1
- data/lib/rubocop/cop/layout/multiline_block_layout.rb +1 -1
- data/lib/rubocop/cop/layout/single_line_block_chain.rb +15 -4
- data/lib/rubocop/cop/layout/space_after_not.rb +1 -0
- data/lib/rubocop/cop/layout/space_around_equals_in_parameter_default.rb +2 -1
- data/lib/rubocop/cop/layout/space_around_keyword.rb +2 -2
- data/lib/rubocop/cop/layout/space_before_brackets.rb +1 -0
- data/lib/rubocop/cop/layout/space_inside_reference_brackets.rb +1 -1
- data/lib/rubocop/cop/lint/ambiguous_operator_precedence.rb +107 -0
- data/lib/rubocop/cop/lint/ambiguous_range.rb +1 -1
- data/lib/rubocop/cop/lint/debugger.rb +0 -2
- data/lib/rubocop/cop/lint/empty_in_pattern.rb +1 -1
- data/lib/rubocop/cop/lint/erb_new_arguments.rb +1 -1
- data/lib/rubocop/cop/lint/float_out_of_range.rb +1 -1
- data/lib/rubocop/cop/lint/incompatible_io_select_with_fiber_scheduler.rb +67 -0
- data/lib/rubocop/cop/lint/number_conversion.rb +7 -1
- data/lib/rubocop/cop/lint/unused_method_argument.rb +2 -3
- data/lib/rubocop/cop/lint/useless_times.rb +1 -1
- data/lib/rubocop/cop/metrics/perceived_complexity.rb +1 -1
- data/lib/rubocop/cop/metrics/utils/abc_size_calculator.rb +1 -1
- data/lib/rubocop/cop/metrics/utils/code_length_calculator.rb +1 -1
- data/lib/rubocop/cop/mixin/code_length.rb +1 -1
- data/lib/rubocop/cop/mixin/frozen_string_literal.rb +11 -6
- data/lib/rubocop/cop/mixin/multiline_expression_indentation.rb +2 -2
- data/lib/rubocop/cop/mixin/preceding_following_alignment.rb +9 -1
- data/lib/rubocop/cop/naming/ascii_identifiers.rb +0 -3
- data/lib/rubocop/cop/naming/constant_name.rb +1 -1
- data/lib/rubocop/cop/naming/inclusive_language.rb +9 -9
- data/lib/rubocop/cop/style/accessor_grouping.rb +2 -2
- data/lib/rubocop/cop/style/and_or.rb +4 -0
- data/lib/rubocop/cop/style/ascii_comments.rb +0 -3
- data/lib/rubocop/cop/style/case_equality.rb +6 -9
- data/lib/rubocop/cop/style/collection_methods.rb +2 -1
- data/lib/rubocop/cop/style/document_dynamic_eval_definition.rb +1 -1
- data/lib/rubocop/cop/style/documentation.rb +23 -8
- data/lib/rubocop/cop/style/empty_method.rb +1 -1
- data/lib/rubocop/cop/style/explicit_block_argument.rb +21 -11
- data/lib/rubocop/cop/style/if_with_boolean_literal_branches.rb +3 -2
- data/lib/rubocop/cop/style/lambda_call.rb +1 -1
- data/lib/rubocop/cop/style/method_call_with_args_parentheses/omit_parentheses.rb +6 -6
- data/lib/rubocop/cop/style/mutable_constant.rb +1 -1
- data/lib/rubocop/cop/style/negated_if.rb +1 -1
- data/lib/rubocop/cop/style/negated_unless.rb +1 -1
- data/lib/rubocop/cop/style/non_nil_check.rb +2 -2
- data/lib/rubocop/cop/style/not.rb +2 -2
- data/lib/rubocop/cop/style/parallel_assignment.rb +1 -1
- data/lib/rubocop/cop/style/percent_q_literals.rb +2 -2
- data/lib/rubocop/cop/style/raise_args.rb +1 -1
- data/lib/rubocop/cop/style/redundant_condition.rb +2 -3
- data/lib/rubocop/cop/style/redundant_interpolation.rb +1 -1
- data/lib/rubocop/cop/style/redundant_percent_q.rb +2 -3
- data/lib/rubocop/cop/style/redundant_self_assignment_branch.rb +1 -1
- data/lib/rubocop/cop/style/redundant_sort.rb +17 -2
- data/lib/rubocop/cop/style/regexp_literal.rb +3 -3
- data/lib/rubocop/cop/style/return_nil.rb +2 -1
- data/lib/rubocop/cop/style/static_class.rb +1 -2
- data/lib/rubocop/cop/style/string_concatenation.rb +1 -1
- data/lib/rubocop/cop/style/trivial_accessors.rb +1 -1
- data/lib/rubocop/cop/style/yoda_condition.rb +4 -7
- data/lib/rubocop/result_cache.rb +1 -1
- data/lib/rubocop/runner.rb +1 -2
- data/lib/rubocop/version.rb +1 -1
- data/lib/rubocop.rb +3 -1
- metadata +5 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: dd3bb4ebea9d6db387e52e92a0c9ffac3f6215f0b5b9bcd7d555e979c8fb9fa7
|
4
|
+
data.tar.gz: 208d08bf57f092a0857776924cb529db1324ecdf4696476475f51878f803b6ac
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9d32668f49f495948628017c042cbc292d62c4ba93d905635d47ecba7c12e69ff7cbff3999a6cccba62bbc27ff7b51827e1a00f41769c1dd711f342fe10e8519
|
7
|
+
data.tar.gz: 9798e105b8ea95245d153e9e295a95a593e49464f91ac8c508ce0900f7f2ef0e97759a1144044f32acb726e11d3552de1f5de8d2d477151606bfd39090df3260
|
data/README.md
CHANGED
@@ -54,7 +54,7 @@ To prevent an unwanted RuboCop update you might want to use a conservative versi
|
|
54
54
|
in your `Gemfile`:
|
55
55
|
|
56
56
|
```rb
|
57
|
-
gem 'rubocop', '~> 1.
|
57
|
+
gem 'rubocop', '~> 1.21', require: false
|
58
58
|
```
|
59
59
|
|
60
60
|
See [our versioning policy](https://docs.rubocop.org/rubocop/versioning.html) for further details.
|
data/config/default.yml
CHANGED
@@ -957,7 +957,6 @@ Layout/LineLength:
|
|
957
957
|
Enabled: true
|
958
958
|
VersionAdded: '0.25'
|
959
959
|
VersionChanged: '1.4'
|
960
|
-
AutoCorrect: true
|
961
960
|
Max: 120
|
962
961
|
# To make it possible to copy or click on URIs in the code, we allow lines
|
963
962
|
# containing a URI to be longer than Max.
|
@@ -1448,6 +1447,13 @@ Lint/AmbiguousOperator:
|
|
1448
1447
|
VersionAdded: '0.17'
|
1449
1448
|
VersionChanged: '0.83'
|
1450
1449
|
|
1450
|
+
Lint/AmbiguousOperatorPrecedence:
|
1451
|
+
Description: >-
|
1452
|
+
Checks for expressions containing multiple binary operations with
|
1453
|
+
ambiguous precedence.
|
1454
|
+
Enabled: pending
|
1455
|
+
VersionAdded: '1.21'
|
1456
|
+
|
1451
1457
|
Lint/AmbiguousRange:
|
1452
1458
|
Description: Checks for ranges with ambiguous boundaries.
|
1453
1459
|
Enabled: pending
|
@@ -1771,6 +1777,11 @@ Lint/ImplicitStringConcatenation:
|
|
1771
1777
|
Enabled: true
|
1772
1778
|
VersionAdded: '0.36'
|
1773
1779
|
|
1780
|
+
Lint/IncompatibleIoSelectWithFiberScheduler:
|
1781
|
+
Description: 'Checks for `IO.select` that is incompatible with Fiber Scheduler.'
|
1782
|
+
Enabled: pending
|
1783
|
+
VersionAdded: '1.21'
|
1784
|
+
|
1774
1785
|
Lint/IneffectiveAccessModifier:
|
1775
1786
|
Description: >-
|
1776
1787
|
Checks for attempts to use `private` or `protected` to set
|
@@ -2563,8 +2574,9 @@ Naming/HeredocDelimiterNaming:
|
|
2563
2574
|
|
2564
2575
|
Naming/InclusiveLanguage:
|
2565
2576
|
Description: 'Recommend the use of inclusive language instead of problematic terms.'
|
2566
|
-
Enabled:
|
2577
|
+
Enabled: false
|
2567
2578
|
VersionAdded: '1.18'
|
2579
|
+
VersionChanged: '1.21'
|
2568
2580
|
CheckIdentifiers: true
|
2569
2581
|
CheckConstants: true
|
2570
2582
|
CheckVariables: true
|
@@ -2796,8 +2808,9 @@ Style/AndOr:
|
|
2796
2808
|
Description: 'Use &&/|| instead of and/or.'
|
2797
2809
|
StyleGuide: '#no-and-or-or'
|
2798
2810
|
Enabled: true
|
2811
|
+
SafeAutoCorrect: false
|
2799
2812
|
VersionAdded: '0.9'
|
2800
|
-
VersionChanged: '
|
2813
|
+
VersionChanged: '1.21'
|
2801
2814
|
# Whether `and` and `or` are banned only in conditionals (conditionals)
|
2802
2815
|
# or completely (always).
|
2803
2816
|
EnforcedStyle: conditionals
|
@@ -2831,9 +2844,9 @@ Style/ArrayJoin:
|
|
2831
2844
|
Style/AsciiComments:
|
2832
2845
|
Description: 'Use only ascii symbols in comments.'
|
2833
2846
|
StyleGuide: '#english-comments'
|
2834
|
-
Enabled:
|
2847
|
+
Enabled: false
|
2835
2848
|
VersionAdded: '0.9'
|
2836
|
-
VersionChanged: '
|
2849
|
+
VersionChanged: '1.21'
|
2837
2850
|
AllowedChars:
|
2838
2851
|
- ©
|
2839
2852
|
|
@@ -2995,7 +3008,7 @@ Style/CaseEquality:
|
|
2995
3008
|
Enabled: true
|
2996
3009
|
VersionAdded: '0.9'
|
2997
3010
|
VersionChanged: '0.89'
|
2998
|
-
# If AllowOnConstant is enabled, the cop will ignore violations when the receiver of
|
3011
|
+
# If `AllowOnConstant` option is enabled, the cop will ignore violations when the receiver of
|
2999
3012
|
# the case equality operator is a constant.
|
3000
3013
|
#
|
3001
3014
|
# # bad
|
data/lib/rubocop/cop/base.rb
CHANGED
@@ -222,8 +222,8 @@ module RuboCop
|
|
222
222
|
|
223
223
|
def relevant_file?(file)
|
224
224
|
file == RuboCop::AST::ProcessedSource::STRING_SOURCE_NAME ||
|
225
|
-
file_name_matches_any?(file, 'Include', true) &&
|
226
|
-
!file_name_matches_any?(file, 'Exclude', false)
|
225
|
+
(file_name_matches_any?(file, 'Include', true) &&
|
226
|
+
!file_name_matches_any?(file, 'Exclude', false))
|
227
227
|
end
|
228
228
|
|
229
229
|
def excluded_file?(file)
|
@@ -3,18 +3,18 @@
|
|
3
3
|
module RuboCop
|
4
4
|
module Cop
|
5
5
|
module Bundler
|
6
|
-
#
|
7
|
-
#
|
8
|
-
# 'https://rubygems.org' if possible, or 'http://rubygems.org' if not.
|
6
|
+
# Passing symbol arguments to `source` (e.g. `source :rubygems`) is
|
7
|
+
# deprecated because they default to using HTTP requests. Instead, specify
|
8
|
+
# `'https://rubygems.org'` if possible, or `'http://rubygems.org'` if not.
|
9
9
|
#
|
10
|
-
#
|
11
|
-
#
|
12
|
-
# most use cases HTTPS will be fine.
|
10
|
+
# When autocorrecting, this cop will replace symbol arguments with
|
11
|
+
# `'https://rubygems.org'`.
|
13
12
|
#
|
14
|
-
#
|
15
|
-
#
|
16
|
-
#
|
17
|
-
#
|
13
|
+
# This cop will not replace existing sources that use `http://`. This may
|
14
|
+
# be necessary where HTTPS is not available. For example, where using an
|
15
|
+
# internal gem server via an intranet, or where HTTPS is prohibited.
|
16
|
+
# However, you should strongly prefer `https://` where possible, as it is
|
17
|
+
# more secure.
|
18
18
|
#
|
19
19
|
# @example
|
20
20
|
# # bad
|
@@ -24,7 +24,8 @@ module RuboCop
|
|
24
24
|
#
|
25
25
|
# # good
|
26
26
|
# source 'https://rubygems.org' # strongly recommended
|
27
|
-
# source 'http://rubygems.org'
|
27
|
+
# source 'http://rubygems.org' # use only if HTTPS is unavailable
|
28
|
+
#
|
28
29
|
class InsecureProtocolSource < Base
|
29
30
|
include RangeHelp
|
30
31
|
extend AutoCorrector
|
@@ -87,8 +87,8 @@ module RuboCop
|
|
87
87
|
end
|
88
88
|
|
89
89
|
def needs_separating_space?
|
90
|
-
block_begin.begin_pos == arguments_end_pos &&
|
91
|
-
selector_end.end_pos == arguments_begin_pos ||
|
90
|
+
(block_begin.begin_pos == arguments_end_pos &&
|
91
|
+
selector_end.end_pos == arguments_begin_pos) ||
|
92
92
|
block_begin.begin_pos == selector_end.end_pos
|
93
93
|
end
|
94
94
|
|
@@ -54,7 +54,7 @@ module RuboCop
|
|
54
54
|
|
55
55
|
def on_send(node)
|
56
56
|
first_arg = node.first_argument
|
57
|
-
return if !multiple_arguments?(node, first_arg) || node.send_type? && node.method?(:[]=)
|
57
|
+
return if !multiple_arguments?(node, first_arg) || (node.send_type? && node.method?(:[]=))
|
58
58
|
|
59
59
|
if first_arg.hash_type? && !first_arg.braces?
|
60
60
|
pairs = first_arg.pairs
|
@@ -264,7 +264,8 @@ module RuboCop
|
|
264
264
|
|
265
265
|
def source_range_with_comment(node)
|
266
266
|
begin_pos, end_pos =
|
267
|
-
if node.def_type? && !node.method?(:initialize) ||
|
267
|
+
if (node.def_type? && !node.method?(:initialize)) ||
|
268
|
+
(node.send_type? && node.def_modifier?)
|
268
269
|
start_node = find_visibility_start(node) || node
|
269
270
|
end_node = find_visibility_end(node) || node
|
270
271
|
[begin_pos_with_comment(start_node),
|
@@ -182,7 +182,7 @@ module RuboCop
|
|
182
182
|
|
183
183
|
def assignment_or_operator_method(node)
|
184
184
|
node.ancestors.find do |ancestor|
|
185
|
-
ancestor.assignment_or_similar? || ancestor.send_type? && ancestor.operator_method?
|
185
|
+
ancestor.assignment_or_similar? || (ancestor.send_type? && ancestor.operator_method?)
|
186
186
|
end
|
187
187
|
end
|
188
188
|
end
|
@@ -176,7 +176,7 @@ module RuboCop
|
|
176
176
|
def ignored_line?(line, line_index)
|
177
177
|
matches_ignored_pattern?(line) ||
|
178
178
|
shebang?(line, line_index) ||
|
179
|
-
heredocs && line_in_permitted_heredoc?(line_index.succ)
|
179
|
+
(heredocs && line_in_permitted_heredoc?(line_index.succ))
|
180
180
|
end
|
181
181
|
|
182
182
|
def shebang?(line, line_index)
|
@@ -37,15 +37,26 @@ module RuboCop
|
|
37
37
|
return unless receiver&.block_type?
|
38
38
|
|
39
39
|
receiver_location = receiver.loc
|
40
|
-
|
41
|
-
return if receiver_location.begin.line <
|
40
|
+
closing_block_delimiter_line_num = receiver_location.end.line
|
41
|
+
return if receiver_location.begin.line < closing_block_delimiter_line_num
|
42
42
|
|
43
43
|
node_location = node.loc
|
44
44
|
dot_range = node_location.dot
|
45
45
|
return unless dot_range
|
46
|
-
return
|
46
|
+
return unless call_method_after_block?(node, dot_range, closing_block_delimiter_line_num)
|
47
47
|
|
48
|
-
range_between(dot_range.begin_pos,
|
48
|
+
range_between(dot_range.begin_pos, selector_range(node).end_pos)
|
49
|
+
end
|
50
|
+
|
51
|
+
def call_method_after_block?(node, dot_range, closing_block_delimiter_line_num)
|
52
|
+
return false if dot_range.line > closing_block_delimiter_line_num
|
53
|
+
|
54
|
+
dot_range.column < selector_range(node).column
|
55
|
+
end
|
56
|
+
|
57
|
+
def selector_range(node)
|
58
|
+
# l.(1) has no selector, so we use the opening parenthesis instead
|
59
|
+
node.loc.selector || node.loc.begin
|
49
60
|
end
|
50
61
|
end
|
51
62
|
end
|
@@ -47,7 +47,8 @@ module RuboCop
|
|
47
47
|
space_on_both_sides = space_on_both_sides?(arg, equals)
|
48
48
|
no_surrounding_space = no_surrounding_space?(arg, equals)
|
49
49
|
|
50
|
-
if style == :space && space_on_both_sides ||
|
50
|
+
if (style == :space && space_on_both_sides) ||
|
51
|
+
(style == :no_space && no_surrounding_space)
|
51
52
|
correct_style_detected
|
52
53
|
else
|
53
54
|
incorrect_style_detected(arg, value)
|
@@ -228,8 +228,8 @@ module RuboCop
|
|
228
228
|
def accepted_opening_delimiter?(range, char)
|
229
229
|
return true unless char
|
230
230
|
|
231
|
-
accept_left_square_bracket?(range) && char == '[' ||
|
232
|
-
accept_left_parenthesis?(range) && char == '('
|
231
|
+
(accept_left_square_bracket?(range) && char == '[') ||
|
232
|
+
(accept_left_parenthesis?(range) && char == '(')
|
233
233
|
end
|
234
234
|
|
235
235
|
def accept_left_parenthesis?(range)
|
@@ -107,7 +107,7 @@ module RuboCop
|
|
107
107
|
current_token = tokens.reverse.find(&:left_ref_bracket?)
|
108
108
|
previous_token = previous_token(current_token)
|
109
109
|
|
110
|
-
if node.method?(:[]=) || previous_token && !previous_token.right_bracket?
|
110
|
+
if node.method?(:[]=) || (previous_token && !previous_token.right_bracket?)
|
111
111
|
tokens.find(&:left_ref_bracket?)
|
112
112
|
else
|
113
113
|
current_token
|
@@ -0,0 +1,107 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module RuboCop
|
4
|
+
module Cop
|
5
|
+
module Lint
|
6
|
+
# This cop looks for expressions containing multiple binary operators
|
7
|
+
# where precedence is ambiguous due to lack of parentheses. For example,
|
8
|
+
# in `1 + 2 * 3`, the multiplication will happen before the addition, but
|
9
|
+
# lexically it appears that the addition will happen first.
|
10
|
+
#
|
11
|
+
# The cop does not consider unary operators (ie. `!a` or `-b`) or comparison
|
12
|
+
# operators (ie. `a =~ b`) because those are not ambiguous.
|
13
|
+
#
|
14
|
+
# NOTE: Ranges are handled by `Lint/AmbiguousRange`.
|
15
|
+
#
|
16
|
+
# @example
|
17
|
+
# # bad
|
18
|
+
# a + b * c
|
19
|
+
# a || b && c
|
20
|
+
# a ** b + c
|
21
|
+
#
|
22
|
+
# # good (different precedence)
|
23
|
+
# a + (b * c)
|
24
|
+
# a || (b && c)
|
25
|
+
# (a ** b) + c
|
26
|
+
#
|
27
|
+
# # good (same precedence)
|
28
|
+
# a + b + c
|
29
|
+
# a * b / c % d
|
30
|
+
class AmbiguousOperatorPrecedence < Base
|
31
|
+
extend AutoCorrector
|
32
|
+
|
33
|
+
# See https://ruby-doc.org/core-3.0.2/doc/syntax/precedence_rdoc.html
|
34
|
+
PRECEDENCE = [
|
35
|
+
%i[**],
|
36
|
+
%i[* / %],
|
37
|
+
%i[+ -],
|
38
|
+
%i[<< >>],
|
39
|
+
%i[&],
|
40
|
+
%i[| ^],
|
41
|
+
%i[&&],
|
42
|
+
%i[||]
|
43
|
+
].freeze
|
44
|
+
RESTRICT_ON_SEND = PRECEDENCE.flatten.freeze
|
45
|
+
MSG = 'Wrap expressions with varying precedence with parentheses to avoid ambiguity.'
|
46
|
+
|
47
|
+
def on_new_investigation
|
48
|
+
# Cache the precedence of each node being investigated
|
49
|
+
# so that we only need to calculate it once
|
50
|
+
@node_precedences = {}
|
51
|
+
super
|
52
|
+
end
|
53
|
+
|
54
|
+
def on_and(node)
|
55
|
+
return unless (parent = node.parent)
|
56
|
+
|
57
|
+
return if parent.begin_type? # if the `and` is in a `begin`, it's parenthesized already
|
58
|
+
return unless parent.or_type?
|
59
|
+
|
60
|
+
add_offense(node) do |corrector|
|
61
|
+
autocorrect(corrector, node)
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
def on_send(node)
|
66
|
+
return if node.parenthesized?
|
67
|
+
|
68
|
+
return unless (parent = node.parent)
|
69
|
+
return unless operator?(parent)
|
70
|
+
return unless greater_precedence?(node, parent)
|
71
|
+
|
72
|
+
add_offense(node) do |corrector|
|
73
|
+
autocorrect(corrector, node)
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
private
|
78
|
+
|
79
|
+
def precedence(node)
|
80
|
+
@node_precedences.fetch(node) do
|
81
|
+
PRECEDENCE.index { |operators| operators.include?(operator_name(node)) }
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
def operator?(node)
|
86
|
+
(node.send_type? && RESTRICT_ON_SEND.include?(node.method_name)) || node.operator_keyword?
|
87
|
+
end
|
88
|
+
|
89
|
+
def greater_precedence?(node1, node2)
|
90
|
+
precedence(node2) > precedence(node1)
|
91
|
+
end
|
92
|
+
|
93
|
+
def operator_name(node)
|
94
|
+
if node.send_type?
|
95
|
+
node.method_name
|
96
|
+
else
|
97
|
+
node.operator.to_sym
|
98
|
+
end
|
99
|
+
end
|
100
|
+
|
101
|
+
def autocorrect(corrector, node)
|
102
|
+
corrector.wrap(node, '(', ')')
|
103
|
+
end
|
104
|
+
end
|
105
|
+
end
|
106
|
+
end
|
107
|
+
end
|