rubocop 1.57.2 → 1.59.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 +2 -2
- data/config/default.yml +43 -2
- data/lib/rubocop/config_obsoletion.rb +11 -8
- data/lib/rubocop/cop/bundler/gem_comment.rb +2 -2
- data/lib/rubocop/cop/gemspec/deprecated_attribute_assignment.rb +2 -2
- data/lib/rubocop/cop/internal_affairs/method_name_equal.rb +19 -20
- data/lib/rubocop/cop/internal_affairs/node_first_or_last_argument.rb +53 -0
- data/lib/rubocop/cop/internal_affairs/node_matcher_directive.rb +2 -2
- data/lib/rubocop/cop/internal_affairs.rb +1 -0
- data/lib/rubocop/cop/layout/argument_alignment.rb +1 -1
- data/lib/rubocop/cop/layout/extra_spacing.rb +4 -10
- data/lib/rubocop/cop/layout/first_array_element_indentation.rb +6 -6
- data/lib/rubocop/cop/layout/first_parameter_indentation.rb +1 -1
- data/lib/rubocop/cop/layout/heredoc_argument_closing_parenthesis.rb +2 -2
- data/lib/rubocop/cop/layout/heredoc_indentation.rb +1 -1
- data/lib/rubocop/cop/layout/redundant_line_break.rb +2 -1
- data/lib/rubocop/cop/layout/rescue_ensure_alignment.rb +4 -4
- data/lib/rubocop/cop/layout/single_line_block_chain.rb +5 -0
- data/lib/rubocop/cop/layout/space_around_operators.rb +50 -20
- data/lib/rubocop/cop/lint/assignment_in_condition.rb +4 -4
- data/lib/rubocop/cop/lint/binary_operator_with_identical_operands.rb +2 -2
- data/lib/rubocop/cop/lint/constant_overwritten_in_rescue.rb +1 -1
- data/lib/rubocop/cop/lint/debugger.rb +2 -1
- data/lib/rubocop/cop/lint/duplicate_methods.rb +1 -1
- data/lib/rubocop/cop/lint/erb_new_arguments.rb +3 -3
- data/lib/rubocop/cop/lint/float_comparison.rb +10 -0
- data/lib/rubocop/cop/lint/hash_compare_by_identity.rb +2 -1
- data/lib/rubocop/cop/lint/it_without_arguments_in_block.rb +56 -0
- data/lib/rubocop/cop/lint/literal_assignment_in_condition.rb +78 -0
- data/lib/rubocop/cop/lint/next_without_accumulator.rb +6 -21
- data/lib/rubocop/cop/lint/non_deterministic_require_order.rb +3 -5
- data/lib/rubocop/cop/lint/number_conversion.rb +9 -4
- data/lib/rubocop/cop/lint/redundant_safe_navigation.rb +43 -0
- data/lib/rubocop/cop/lint/redundant_with_index.rb +2 -2
- data/lib/rubocop/cop/lint/redundant_with_object.rb +2 -2
- data/lib/rubocop/cop/lint/safe_navigation_chain.rb +3 -4
- data/lib/rubocop/cop/lint/self_assignment.rb +38 -0
- data/lib/rubocop/cop/lint/symbol_conversion.rb +7 -2
- data/lib/rubocop/cop/lint/trailing_comma_in_attribute_declaration.rb +1 -1
- data/lib/rubocop/cop/lint/unmodified_reduce_accumulator.rb +2 -2
- data/lib/rubocop/cop/lint/useless_access_modifier.rb +2 -2
- data/lib/rubocop/cop/lint/useless_times.rb +1 -1
- data/lib/rubocop/cop/lint/void.rb +14 -1
- data/lib/rubocop/cop/metrics/abc_size.rb +3 -3
- data/lib/rubocop/cop/mixin/check_line_breakable.rb +1 -1
- data/lib/rubocop/cop/mixin/preceding_following_alignment.rb +1 -1
- data/lib/rubocop/cop/mixin/space_before_punctuation.rb +1 -1
- data/lib/rubocop/cop/naming/block_forwarding.rb +2 -2
- data/lib/rubocop/cop/naming/constant_name.rb +1 -2
- data/lib/rubocop/cop/naming/memoized_instance_variable_name.rb +1 -1
- data/lib/rubocop/cop/style/access_modifier_declarations.rb +2 -2
- data/lib/rubocop/cop/style/accessor_grouping.rb +1 -1
- data/lib/rubocop/cop/style/arguments_forwarding.rb +68 -6
- data/lib/rubocop/cop/style/array_first_last.rb +64 -0
- data/lib/rubocop/cop/style/auto_resource_cleanup.rb +21 -14
- data/lib/rubocop/cop/style/bisected_attr_accessor.rb +2 -2
- data/lib/rubocop/cop/style/case_like_if.rb +4 -4
- data/lib/rubocop/cop/style/class_check.rb +1 -0
- data/lib/rubocop/cop/style/collection_compact.rb +7 -6
- data/lib/rubocop/cop/style/combinable_loops.rb +13 -7
- data/lib/rubocop/cop/style/concat_array_literals.rb +1 -0
- data/lib/rubocop/cop/style/conditional_assignment.rb +1 -1
- data/lib/rubocop/cop/style/date_time.rb +5 -4
- data/lib/rubocop/cop/style/each_with_object.rb +2 -2
- data/lib/rubocop/cop/style/empty_literal.rb +1 -1
- data/lib/rubocop/cop/style/eval_with_location.rb +3 -3
- data/lib/rubocop/cop/style/exact_regexp_match.rb +2 -1
- data/lib/rubocop/cop/style/explicit_block_argument.rb +2 -2
- data/lib/rubocop/cop/style/hash_each_methods.rb +83 -10
- data/lib/rubocop/cop/style/hash_except.rb +2 -1
- data/lib/rubocop/cop/style/inverse_methods.rb +6 -5
- data/lib/rubocop/cop/style/map_compact_with_conditional_block.rb +3 -2
- data/lib/rubocop/cop/style/map_to_hash.rb +10 -4
- data/lib/rubocop/cop/style/method_call_with_args_parentheses/omit_parentheses.rb +1 -0
- data/lib/rubocop/cop/style/method_call_with_args_parentheses.rb +1 -1
- data/lib/rubocop/cop/style/method_call_without_args_parentheses.rb +20 -0
- data/lib/rubocop/cop/style/method_def_parentheses.rb +1 -1
- data/lib/rubocop/cop/style/missing_respond_to_missing.rb +2 -2
- data/lib/rubocop/cop/style/next.rb +1 -1
- data/lib/rubocop/cop/style/operator_method_call.rb +2 -2
- data/lib/rubocop/cop/style/redundant_argument.rb +3 -2
- data/lib/rubocop/cop/style/redundant_double_splat_hash_braces.rb +3 -3
- data/lib/rubocop/cop/style/redundant_fetch_block.rb +3 -3
- data/lib/rubocop/cop/style/redundant_line_continuation.rb +2 -0
- data/lib/rubocop/cop/style/redundant_parentheses.rb +15 -8
- data/lib/rubocop/cop/style/redundant_return.rb +1 -1
- data/lib/rubocop/cop/style/redundant_self.rb +17 -2
- data/lib/rubocop/cop/style/redundant_sort.rb +9 -8
- data/lib/rubocop/cop/style/redundant_sort_by.rb +2 -2
- data/lib/rubocop/cop/style/redundant_string_escape.rb +1 -1
- data/lib/rubocop/cop/style/sample.rb +2 -1
- data/lib/rubocop/cop/style/select_by_regexp.rb +7 -6
- data/lib/rubocop/cop/style/self_assignment.rb +1 -1
- data/lib/rubocop/cop/style/semicolon.rb +8 -0
- data/lib/rubocop/cop/style/single_argument_dig.rb +5 -2
- data/lib/rubocop/cop/style/slicing_with_range.rb +1 -1
- data/lib/rubocop/cop/style/string_chars.rb +1 -0
- data/lib/rubocop/cop/style/strip.rb +7 -4
- data/lib/rubocop/cop/style/super_with_args_parentheses.rb +35 -0
- data/lib/rubocop/cop/style/unpack_first.rb +11 -14
- data/lib/rubocop/formatter/html_formatter.rb +1 -2
- data/lib/rubocop/result_cache.rb +0 -1
- data/lib/rubocop/runner.rb +1 -1
- data/lib/rubocop/version.rb +1 -1
- data/lib/rubocop.rb +4 -0
- metadata +14 -9
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 236fd46f4a118eb34ff38fce1a147a116b2d30a7bf849ca809ece40aecabc694
|
4
|
+
data.tar.gz: 550ecc4682d191a6a429a6af299212a42aa459e0aee04d5f7cb6a20ded419ff4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5c7cfaa0f6573e566bbbac89a993889cd0f0944ab5c012e0286da61021e2d3da6ed51f68fbbf6c71afd4b6d81c577d15228b7a6a2d93aed59d2dfcba61a9be63
|
7
|
+
data.tar.gz: 5cbb4256ff218ab5744fc3065f56061e5b0eab787d21dc30f3ded5972b789ffc2c24cd977fbaf3acbcc84abf36c5e3537a2eeb328dabb3becf29268eccaa81f8
|
data/README.md
CHANGED
@@ -53,7 +53,7 @@ To prevent an unwanted RuboCop update you might want to use a conservative versi
|
|
53
53
|
in your `Gemfile`:
|
54
54
|
|
55
55
|
```rb
|
56
|
-
gem 'rubocop', '~> 1.
|
56
|
+
gem 'rubocop', '~> 1.59', require: false
|
57
57
|
```
|
58
58
|
|
59
59
|
See [our versioning policy](https://docs.rubocop.org/rubocop/versioning.html) for further details.
|
@@ -67,7 +67,7 @@ $ cd my/cool/ruby/project
|
|
67
67
|
$ rubocop
|
68
68
|
```
|
69
69
|
|
70
|
-
You can also use this magic in your favorite editor with RuboCop's [built-in LSP](https://docs.rubocop.org/rubocop/usage/lsp.html).
|
70
|
+
You can also use this magic in your favorite editor with RuboCop's [built-in LSP server](https://docs.rubocop.org/rubocop/usage/lsp.html).
|
71
71
|
|
72
72
|
## Documentation
|
73
73
|
|
data/config/default.yml
CHANGED
@@ -1351,6 +1351,10 @@ Layout/SpaceAroundOperators:
|
|
1351
1351
|
SupportedStylesForExponentOperator:
|
1352
1352
|
- space
|
1353
1353
|
- no_space
|
1354
|
+
EnforcedStyleForRationalLiterals: no_space
|
1355
|
+
SupportedStylesForRationalLiterals:
|
1356
|
+
- space
|
1357
|
+
- no_space
|
1354
1358
|
|
1355
1359
|
Layout/SpaceBeforeBlockBraces:
|
1356
1360
|
Description: >-
|
@@ -1959,6 +1963,12 @@ Lint/InterpolationCheck:
|
|
1959
1963
|
VersionAdded: '0.50'
|
1960
1964
|
VersionChanged: '1.40'
|
1961
1965
|
|
1966
|
+
Lint/ItWithoutArgumentsInBlock:
|
1967
|
+
Description: 'Checks uses of `it` calls without arguments in block.'
|
1968
|
+
Reference: 'https://bugs.ruby-lang.org/issues/18980'
|
1969
|
+
Enabled: pending
|
1970
|
+
VersionAdded: '1.59'
|
1971
|
+
|
1962
1972
|
Lint/LambdaWithoutLiteralBlock:
|
1963
1973
|
Description: 'Checks uses of lambda without a literal block.'
|
1964
1974
|
Enabled: pending
|
@@ -1969,6 +1979,11 @@ Lint/LiteralAsCondition:
|
|
1969
1979
|
Enabled: true
|
1970
1980
|
VersionAdded: '0.51'
|
1971
1981
|
|
1982
|
+
Lint/LiteralAssignmentInCondition:
|
1983
|
+
Description: 'Checks for literal assignments in the conditions.'
|
1984
|
+
Enabled: pending
|
1985
|
+
VersionAdded: '1.58'
|
1986
|
+
|
1972
1987
|
Lint/LiteralInInterpolation:
|
1973
1988
|
Description: 'Checks for literals used in interpolation.'
|
1974
1989
|
Enabled: true
|
@@ -3085,7 +3100,19 @@ Style/ArgumentsForwarding:
|
|
3085
3100
|
Enabled: pending
|
3086
3101
|
AllowOnlyRestArgument: true
|
3087
3102
|
UseAnonymousForwarding: true
|
3103
|
+
RedundantRestArgumentNames:
|
3104
|
+
- args
|
3105
|
+
- arguments
|
3106
|
+
RedundantKeywordRestArgumentNames:
|
3107
|
+
- kwargs
|
3108
|
+
- options
|
3109
|
+
- opts
|
3110
|
+
RedundantBlockArgumentNames:
|
3111
|
+
- blk
|
3112
|
+
- block
|
3113
|
+
- proc
|
3088
3114
|
VersionAdded: '1.1'
|
3115
|
+
VersionChanged: '1.58'
|
3089
3116
|
|
3090
3117
|
Style/ArrayCoercion:
|
3091
3118
|
Description: >-
|
@@ -3096,6 +3123,13 @@ Style/ArrayCoercion:
|
|
3096
3123
|
Enabled: false
|
3097
3124
|
VersionAdded: '0.88'
|
3098
3125
|
|
3126
|
+
Style/ArrayFirstLast:
|
3127
|
+
Description: 'Use `arr.first` and `arr.last` instead of `arr[0]` and `arr[-1]`.'
|
3128
|
+
Reference: '#first-and-last'
|
3129
|
+
Enabled: false
|
3130
|
+
VersionAdded: '1.58'
|
3131
|
+
Safe: false
|
3132
|
+
|
3099
3133
|
Style/ArrayIntersect:
|
3100
3134
|
Description: 'Use `array1.intersect?(array2)` instead of `(array1 & array2).any?`.'
|
3101
3135
|
Enabled: 'pending'
|
@@ -4902,7 +4936,7 @@ Style/RedundantFetchBlock:
|
|
4902
4936
|
Description: >-
|
4903
4937
|
Use `fetch(key, value)` instead of `fetch(key) { value }`
|
4904
4938
|
when value has Numeric, Rational, Complex, Symbol or String type, `false`, `true`, `nil` or is a constant.
|
4905
|
-
Reference: 'https://github.com/
|
4939
|
+
Reference: 'https://github.com/fastruby/fast-ruby#hashfetch-with-argument-vs-hashfetch--block-code'
|
4906
4940
|
Enabled: true
|
4907
4941
|
Safe: false
|
4908
4942
|
# If enabled, this cop will autocorrect usages of
|
@@ -5123,7 +5157,7 @@ Style/Sample:
|
|
5123
5157
|
Description: >-
|
5124
5158
|
Use `sample` instead of `shuffle.first`,
|
5125
5159
|
`shuffle.last`, and `shuffle[Integer]`.
|
5126
|
-
Reference: 'https://github.com/
|
5160
|
+
Reference: 'https://github.com/fastruby/fast-ruby#arrayshufflefirst-vs-arraysample-code'
|
5127
5161
|
Enabled: true
|
5128
5162
|
VersionAdded: '0.30'
|
5129
5163
|
|
@@ -5190,6 +5224,7 @@ Style/SingleLineBlockParams:
|
|
5190
5224
|
|
5191
5225
|
Style/SingleLineDoEndBlock:
|
5192
5226
|
Description: 'Checks for single-line `do`...`end` blocks.'
|
5227
|
+
StyleGuide: '#single-line-do-end-block'
|
5193
5228
|
Enabled: pending
|
5194
5229
|
VersionAdded: '1.57'
|
5195
5230
|
|
@@ -5329,6 +5364,12 @@ Style/StructInheritance:
|
|
5329
5364
|
VersionAdded: '0.29'
|
5330
5365
|
VersionChanged: '1.20'
|
5331
5366
|
|
5367
|
+
Style/SuperWithArgsParentheses:
|
5368
|
+
Description: 'Use parentheses for `super` with arguments.'
|
5369
|
+
StyleGuide: '#super-with-args'
|
5370
|
+
Enabled: pending
|
5371
|
+
VersionAdded: '1.58'
|
5372
|
+
|
5332
5373
|
Style/SwapValues:
|
5333
5374
|
Description: 'Enforces the use of shorthand-style swapping of 2 variables.'
|
5334
5375
|
StyleGuide: '#values-swapping'
|
@@ -15,6 +15,8 @@ module RuboCop
|
|
15
15
|
'changed_parameters' => ChangedParameter,
|
16
16
|
'changed_enforced_styles' => ChangedEnforcedStyles
|
17
17
|
}.freeze
|
18
|
+
LOAD_RULES_CACHE = {} # rubocop:disable Style/MutableConstant
|
19
|
+
private_constant :LOAD_RULES_CACHE
|
18
20
|
|
19
21
|
attr_reader :rules, :warnings
|
20
22
|
|
@@ -48,16 +50,17 @@ module RuboCop
|
|
48
50
|
# Default rules for obsoletions are in config/obsoletion.yml
|
49
51
|
# Additional rules files can be added with `RuboCop::ConfigObsoletion.files << filename`
|
50
52
|
def load_rules # rubocop:disable Metrics/AbcSize
|
51
|
-
rules = self.class.files
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
53
|
+
rules = LOAD_RULES_CACHE[self.class.files] ||=
|
54
|
+
self.class.files.each_with_object({}) do |filename, hash|
|
55
|
+
hash.merge!(YAML.safe_load(File.read(filename))) do |_key, first, second|
|
56
|
+
case first
|
57
|
+
when Hash
|
58
|
+
first.merge(second)
|
59
|
+
when Array
|
60
|
+
first.concat(second)
|
61
|
+
end
|
58
62
|
end
|
59
63
|
end
|
60
|
-
end
|
61
64
|
|
62
65
|
cop_rules = rules.slice(*COP_RULE_CLASSES.keys)
|
63
66
|
parameter_rules = rules.slice(*PARAMETER_RULE_CLASSES.keys)
|
@@ -161,9 +161,9 @@ module RuboCop
|
|
161
161
|
end
|
162
162
|
|
163
163
|
def gem_options(node)
|
164
|
-
return [] unless node.
|
164
|
+
return [] unless node.last_argument&.type == :hash
|
165
165
|
|
166
|
-
node.
|
166
|
+
node.last_argument.keys.map(&:value)
|
167
167
|
end
|
168
168
|
end
|
169
169
|
end
|
@@ -43,7 +43,7 @@ module RuboCop
|
|
43
43
|
def on_block(block_node)
|
44
44
|
return unless gem_specification(block_node)
|
45
45
|
|
46
|
-
block_parameter = block_node.
|
46
|
+
block_parameter = block_node.first_argument.source
|
47
47
|
|
48
48
|
assignment = block_node.descendants.detect do |node|
|
49
49
|
use_deprecated_attributes?(node, block_parameter)
|
@@ -65,7 +65,7 @@ module RuboCop
|
|
65
65
|
lhs, _op, _rhs = *node
|
66
66
|
[lhs, attribute]
|
67
67
|
else
|
68
|
-
[node, "#{attribute}="
|
68
|
+
[node, :"#{attribute}="]
|
69
69
|
end
|
70
70
|
end
|
71
71
|
|
@@ -12,38 +12,37 @@ module RuboCop
|
|
12
12
|
# # good
|
13
13
|
# node.method?(:do_something)
|
14
14
|
#
|
15
|
+
# # bad
|
16
|
+
# node.method_name != :do_something
|
17
|
+
#
|
18
|
+
# # good
|
19
|
+
# !node.method?(:do_something)
|
20
|
+
#
|
15
21
|
class MethodNameEqual < Base
|
16
|
-
include RangeHelp
|
17
22
|
extend AutoCorrector
|
18
23
|
|
19
|
-
MSG = 'Use
|
20
|
-
RESTRICT_ON_SEND = %i[==].freeze
|
24
|
+
MSG = 'Use `%<prefer>s` instead.'
|
25
|
+
RESTRICT_ON_SEND = %i[== !=].freeze
|
21
26
|
|
22
|
-
# @!method method_name
|
23
|
-
def_node_matcher :method_name
|
27
|
+
# @!method method_name(node)
|
28
|
+
def_node_matcher :method_name, <<~PATTERN
|
24
29
|
(send
|
25
|
-
|
26
|
-
(...) :method_name) :==
|
27
|
-
|
30
|
+
(send
|
31
|
+
(...) :method_name) {:== :!=}
|
32
|
+
$_)
|
28
33
|
PATTERN
|
29
34
|
|
30
35
|
def on_send(node)
|
31
|
-
method_name
|
32
|
-
|
36
|
+
method_name(node) do |method_name_arg|
|
37
|
+
bang = node.method?(:!=) ? '!' : ''
|
38
|
+
prefer = "#{bang}#{node.receiver.receiver.source}.method?(#{method_name_arg.source})"
|
39
|
+
message = format(MSG, prefer: prefer)
|
33
40
|
|
34
|
-
|
35
|
-
|
36
|
-
add_offense(range, message: message) do |corrector|
|
37
|
-
corrector.replace(range, "method?(#{method_name_arg.first.source})")
|
41
|
+
add_offense(node, message: message) do |corrector|
|
42
|
+
corrector.replace(node, prefer)
|
38
43
|
end
|
39
44
|
end
|
40
45
|
end
|
41
|
-
|
42
|
-
private
|
43
|
-
|
44
|
-
def range(method_name_node, node)
|
45
|
-
range_between(method_name_node.loc.selector.begin_pos, node.source_range.end_pos)
|
46
|
-
end
|
47
46
|
end
|
48
47
|
end
|
49
48
|
end
|
@@ -0,0 +1,53 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module RuboCop
|
4
|
+
module Cop
|
5
|
+
module InternalAffairs
|
6
|
+
# Checks for the use of `node.arguments.first` or `node.arguments.last` and
|
7
|
+
# suggests the use of `node.first_argument` or `node.last_argument` instead.
|
8
|
+
#
|
9
|
+
# @example
|
10
|
+
# # bad
|
11
|
+
# node.arguments.first
|
12
|
+
# node.arguments[0]
|
13
|
+
# node.arguments.last
|
14
|
+
# node.arguments[-1]
|
15
|
+
#
|
16
|
+
# # good
|
17
|
+
# node.first_argument
|
18
|
+
# node.last_argument
|
19
|
+
#
|
20
|
+
class NodeFirstOrLastArgument < Base
|
21
|
+
extend AutoCorrector
|
22
|
+
include RangeHelp
|
23
|
+
|
24
|
+
MSG = 'Use `#%<correct>s` instead of `#%<incorrect>s`.'
|
25
|
+
RESTRICT_ON_SEND = %i[arguments].freeze
|
26
|
+
|
27
|
+
# @!method arguments_first_or_last?(node)
|
28
|
+
def_node_matcher :arguments_first_or_last?, <<~PATTERN
|
29
|
+
{
|
30
|
+
(send (send !nil? :arguments) ${:first :last})
|
31
|
+
(send (send !nil? :arguments) :[] (int ${0 -1}))
|
32
|
+
}
|
33
|
+
PATTERN
|
34
|
+
|
35
|
+
def on_send(node)
|
36
|
+
arguments_first_or_last?(node.parent) do |end_or_index|
|
37
|
+
range = range_between(node.loc.selector.begin_pos, node.parent.source_range.end_pos)
|
38
|
+
correct = case end_or_index
|
39
|
+
when :first, 0 then 'first_argument'
|
40
|
+
when :last, -1 then 'last_argument'
|
41
|
+
else raise "Unknown end_or_index: #{end_or_index}"
|
42
|
+
end
|
43
|
+
message = format(MSG, correct: correct, incorrect: range.source)
|
44
|
+
|
45
|
+
add_offense(range, message: message) do |corrector|
|
46
|
+
corrector.replace(range, correct)
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
@@ -40,7 +40,7 @@ module RuboCop
|
|
40
40
|
return if node.arguments.none?
|
41
41
|
return unless valid_method_name?(node)
|
42
42
|
|
43
|
-
actual_name = node.
|
43
|
+
actual_name = node.first_argument.value
|
44
44
|
directives = method_directives(node)
|
45
45
|
return too_many_directives(node) if directives.size > 1
|
46
46
|
|
@@ -53,7 +53,7 @@ module RuboCop
|
|
53
53
|
private
|
54
54
|
|
55
55
|
def valid_method_name?(node)
|
56
|
-
node.
|
56
|
+
node.first_argument.str_type? || node.first_argument.sym_type?
|
57
57
|
end
|
58
58
|
|
59
59
|
def method_directives(node)
|
@@ -12,6 +12,7 @@ require_relative 'internal_affairs/location_line_equality_comparison'
|
|
12
12
|
require_relative 'internal_affairs/method_name_end_with'
|
13
13
|
require_relative 'internal_affairs/method_name_equal'
|
14
14
|
require_relative 'internal_affairs/node_destructuring'
|
15
|
+
require_relative 'internal_affairs/node_first_or_last_argument'
|
15
16
|
require_relative 'internal_affairs/node_matcher_directive'
|
16
17
|
require_relative 'internal_affairs/node_type_predicate'
|
17
18
|
require_relative 'internal_affairs/numblock_handler'
|
@@ -49,19 +49,13 @@ module RuboCop
|
|
49
49
|
|
50
50
|
private
|
51
51
|
|
52
|
-
def aligned_locations(locs)
|
52
|
+
def aligned_locations(locs)
|
53
53
|
return [] if locs.empty?
|
54
54
|
|
55
|
-
aligned = Set
|
56
|
-
locs.each_cons(
|
57
|
-
|
58
|
-
aligned << loc.line if col == before.column || col == after.column
|
55
|
+
aligned = Set.new
|
56
|
+
locs.each_cons(2) do |loc1, loc2|
|
57
|
+
aligned << loc1.line << loc2.line if loc1.column == loc2.column
|
59
58
|
end
|
60
|
-
|
61
|
-
# if locs.size > 2 and the size of variable `aligned`
|
62
|
-
# has not increased from its initial value, there are not aligned lines.
|
63
|
-
return [] if locs.size > 2 && aligned.size == 2
|
64
|
-
|
65
59
|
aligned
|
66
60
|
end
|
67
61
|
|
@@ -25,7 +25,7 @@ module RuboCop
|
|
25
25
|
# # element are on separate lines is indented one step (two spaces) more
|
26
26
|
# # than the position inside the opening parenthesis.
|
27
27
|
#
|
28
|
-
# #bad
|
28
|
+
# # bad
|
29
29
|
# array = [
|
30
30
|
# :value
|
31
31
|
# ]
|
@@ -33,7 +33,7 @@ module RuboCop
|
|
33
33
|
# :no_difference
|
34
34
|
# ])
|
35
35
|
#
|
36
|
-
# #good
|
36
|
+
# # good
|
37
37
|
# array = [
|
38
38
|
# :value
|
39
39
|
# ]
|
@@ -47,7 +47,7 @@ module RuboCop
|
|
47
47
|
# # separate lines is indented the same as an array literal which is not
|
48
48
|
# # defined inside a method call.
|
49
49
|
#
|
50
|
-
# #bad
|
50
|
+
# # bad
|
51
51
|
# # consistent
|
52
52
|
# array = [
|
53
53
|
# :value
|
@@ -56,7 +56,7 @@ module RuboCop
|
|
56
56
|
# :its_like_this
|
57
57
|
# ])
|
58
58
|
#
|
59
|
-
# #good
|
59
|
+
# # good
|
60
60
|
# array = [
|
61
61
|
# :value
|
62
62
|
# ]
|
@@ -68,13 +68,13 @@ module RuboCop
|
|
68
68
|
# # The `align_brackets` style enforces that the opening and closing
|
69
69
|
# # brackets are indented to the same position.
|
70
70
|
#
|
71
|
-
# #bad
|
71
|
+
# # bad
|
72
72
|
# # align_brackets
|
73
73
|
# and_now_for_something = [
|
74
74
|
# :completely_different
|
75
75
|
# ]
|
76
76
|
#
|
77
|
-
# #good
|
77
|
+
# # good
|
78
78
|
# # align_brackets
|
79
79
|
# and_now_for_something = [
|
80
80
|
# :completely_different
|
@@ -72,7 +72,7 @@ module RuboCop
|
|
72
72
|
return if ignored_node?(def_node)
|
73
73
|
|
74
74
|
left_parenthesis = def_node.arguments.loc.begin
|
75
|
-
first_elem = def_node.
|
75
|
+
first_elem = def_node.first_argument
|
76
76
|
return unless first_elem
|
77
77
|
return if same_line?(first_elem, left_parenthesis)
|
78
78
|
|
@@ -182,7 +182,7 @@ module RuboCop
|
|
182
182
|
end
|
183
183
|
|
184
184
|
def add_correct_closing_paren(node, corrector)
|
185
|
-
corrector.insert_after(node.
|
185
|
+
corrector.insert_after(node.last_argument, ')')
|
186
186
|
end
|
187
187
|
|
188
188
|
def remove_incorrect_closing_paren(node, corrector)
|
@@ -271,7 +271,7 @@ module RuboCop
|
|
271
271
|
def add_correct_external_trailing_comma(node, corrector)
|
272
272
|
return unless external_trailing_comma?(node)
|
273
273
|
|
274
|
-
corrector.insert_after(node.
|
274
|
+
corrector.insert_after(node.last_argument, ',')
|
275
275
|
end
|
276
276
|
|
277
277
|
def remove_incorrect_external_trailing_comma(node, corrector)
|
@@ -8,7 +8,7 @@ module RuboCop
|
|
8
8
|
#
|
9
9
|
# Note: When ``Layout/LineLength``'s `AllowHeredoc` is false (not default),
|
10
10
|
# this cop does not add any offenses for long here documents to
|
11
|
-
# avoid
|
11
|
+
# avoid ``Layout/LineLength``'s offenses.
|
12
12
|
#
|
13
13
|
# @example
|
14
14
|
# # bad
|
@@ -62,6 +62,7 @@ module RuboCop
|
|
62
62
|
|
63
63
|
register_offense(node)
|
64
64
|
end
|
65
|
+
alias on_csend on_send
|
65
66
|
|
66
67
|
private
|
67
68
|
|
@@ -135,7 +136,7 @@ module RuboCop
|
|
135
136
|
.gsub(/" *\\\n\s*'/, %q(" + ')) # Double quote, backslash, and then single quote
|
136
137
|
.gsub(/' *\\\n\s*"/, %q(' + ")) # Single quote, backslash, and then double quote
|
137
138
|
.gsub(/(["']) *\\\n\s*\1/, '') # Double or single quote, backslash, then same quote
|
138
|
-
.gsub(/\n\s*(
|
139
|
+
.gsub(/\n\s*(?=(&)?\.\w)/, '') # Extra space within method chaining which includes `&.`
|
139
140
|
.gsub(/\s*\\?\n\s*/, ' ') # Any other line break, with or without backslash
|
140
141
|
end
|
141
142
|
|
@@ -29,7 +29,7 @@ module RuboCop
|
|
29
29
|
MSG = '`%<kw_loc>s` at %<kw_loc_line>d, %<kw_loc_column>d is not ' \
|
30
30
|
'aligned with `%<beginning>s` at ' \
|
31
31
|
'%<begin_loc_line>d, %<begin_loc_column>d.'
|
32
|
-
ANCESTOR_TYPES = %i[kwbegin def defs class module block].freeze
|
32
|
+
ANCESTOR_TYPES = %i[kwbegin def defs class module block numblock].freeze
|
33
33
|
ANCESTOR_TYPES_WITH_ACCESS_MODIFIERS = %i[def defs].freeze
|
34
34
|
ALTERNATIVE_ACCESS_MODIFIERS = %i[public_class_method private_class_method].freeze
|
35
35
|
|
@@ -95,7 +95,7 @@ module RuboCop
|
|
95
95
|
def alignment_source(node, starting_loc)
|
96
96
|
ending_loc =
|
97
97
|
case node.type
|
98
|
-
when :block, :kwbegin
|
98
|
+
when :block, :numblock, :kwbegin
|
99
99
|
node.loc.begin
|
100
100
|
when :def, :defs, :class, :module,
|
101
101
|
:lvasgn, :ivasgn, :cvasgn, :gvasgn, :casgn
|
@@ -104,8 +104,8 @@ module RuboCop
|
|
104
104
|
mlhs_node, = *node
|
105
105
|
mlhs_node.source_range
|
106
106
|
else
|
107
|
-
# It is a wrapper with access modifier.
|
108
|
-
node.child_nodes.first.loc.name
|
107
|
+
# It is a wrapper with receiver of object attribute or access modifier.
|
108
|
+
node.receiver&.source_range || node.child_nodes.first.loc.name
|
109
109
|
end
|
110
110
|
|
111
111
|
range_between(starting_loc.begin_pos, ending_loc.end_pos).source
|
@@ -25,10 +25,15 @@ module RuboCop
|
|
25
25
|
|
26
26
|
MSG = 'Put method call on a separate line if chained to a single line block.'
|
27
27
|
|
28
|
+
def self.autocorrect_incompatible_with
|
29
|
+
[Style::MapToHash]
|
30
|
+
end
|
31
|
+
|
28
32
|
def on_send(node)
|
29
33
|
range = offending_range(node)
|
30
34
|
add_offense(range) { |corrector| corrector.insert_before(range, "\n") } if range
|
31
35
|
end
|
36
|
+
alias on_csend on_send
|
32
37
|
|
33
38
|
private
|
34
39
|
|