rubocop 1.34.0 → 1.35.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 +1 -1
- data/config/default.yml +22 -0
- data/lib/rubocop/cli/command/{auto_genenerate_config.rb → auto_generate_config.rb} +0 -0
- data/lib/rubocop/config.rb +1 -1
- data/lib/rubocop/cop/correctors/parentheses_corrector.rb +32 -2
- data/lib/rubocop/cop/gemspec/require_mfa.rb +1 -1
- data/lib/rubocop/cop/generator/require_file_injector.rb +2 -2
- data/lib/rubocop/cop/internal_affairs/numblock_handler.rb +69 -0
- data/lib/rubocop/cop/internal_affairs/single_line_comparison.rb +5 -4
- data/lib/rubocop/cop/internal_affairs.rb +1 -0
- data/lib/rubocop/cop/layout/block_alignment.rb +2 -0
- data/lib/rubocop/cop/layout/block_end_newline.rb +2 -0
- data/lib/rubocop/cop/layout/empty_lines_around_access_modifier.rb +5 -2
- data/lib/rubocop/cop/layout/empty_lines_around_block_body.rb +2 -0
- data/lib/rubocop/cop/layout/end_of_line.rb +4 -4
- data/lib/rubocop/cop/layout/first_array_element_indentation.rb +2 -2
- data/lib/rubocop/cop/layout/first_hash_element_indentation.rb +2 -2
- data/lib/rubocop/cop/layout/indentation_width.rb +2 -0
- data/lib/rubocop/cop/layout/line_length.rb +4 -1
- data/lib/rubocop/cop/layout/multiline_block_layout.rb +2 -0
- data/lib/rubocop/cop/layout/redundant_line_break.rb +1 -1
- data/lib/rubocop/cop/layout/space_around_block_parameters.rb +1 -1
- data/lib/rubocop/cop/layout/space_around_keyword.rb +1 -1
- data/lib/rubocop/cop/layout/space_before_block_braces.rb +2 -0
- data/lib/rubocop/cop/lint/deprecated_class_methods.rb +4 -4
- data/lib/rubocop/cop/lint/empty_block.rb +1 -1
- data/lib/rubocop/cop/lint/erb_new_arguments.rb +9 -9
- data/lib/rubocop/cop/lint/literal_in_interpolation.rb +4 -0
- data/lib/rubocop/cop/lint/next_without_accumulator.rb +25 -6
- data/lib/rubocop/cop/lint/non_atomic_file_operation.rb +6 -6
- data/lib/rubocop/cop/lint/non_deterministic_require_order.rb +12 -0
- data/lib/rubocop/cop/lint/redundant_safe_navigation.rb +9 -3
- data/lib/rubocop/cop/lint/redundant_with_index.rb +13 -10
- data/lib/rubocop/cop/lint/redundant_with_object.rb +12 -11
- data/lib/rubocop/cop/lint/shadowing_outer_local_variable.rb +1 -0
- data/lib/rubocop/cop/lint/unreachable_loop.rb +7 -1
- data/lib/rubocop/cop/lint/useless_access_modifier.rb +6 -4
- data/lib/rubocop/cop/lint/void.rb +2 -0
- data/lib/rubocop/cop/mixin/check_line_breakable.rb +1 -1
- data/lib/rubocop/cop/mixin/hash_shorthand_syntax.rb +76 -1
- data/lib/rubocop/cop/mixin/hash_transform_method.rb +1 -1
- data/lib/rubocop/cop/mixin/method_complexity.rb +4 -4
- data/lib/rubocop/cop/mixin/multiline_element_indentation.rb +1 -1
- data/lib/rubocop/cop/mixin/range_help.rb +2 -3
- data/lib/rubocop/cop/naming/block_parameter_name.rb +1 -1
- data/lib/rubocop/cop/naming/constant_name.rb +2 -2
- data/lib/rubocop/cop/style/arguments_forwarding.rb +2 -2
- data/lib/rubocop/cop/style/class_methods_definitions.rb +2 -1
- data/lib/rubocop/cop/style/collection_methods.rb +2 -0
- data/lib/rubocop/cop/style/combinable_loops.rb +3 -1
- data/lib/rubocop/cop/style/each_for_simple_loop.rb +1 -1
- data/lib/rubocop/cop/style/each_with_object.rb +39 -8
- data/lib/rubocop/cop/style/empty_block_parameter.rb +1 -1
- data/lib/rubocop/cop/style/empty_lambda_parameter.rb +1 -1
- data/lib/rubocop/cop/style/for.rb +2 -0
- data/lib/rubocop/cop/style/guard_clause.rb +27 -16
- data/lib/rubocop/cop/style/hash_each_methods.rb +3 -1
- data/lib/rubocop/cop/style/hash_syntax.rb +17 -0
- data/lib/rubocop/cop/style/inverse_methods.rb +8 -6
- data/lib/rubocop/cop/style/magic_comment_format.rb +307 -0
- data/lib/rubocop/cop/style/method_call_with_args_parentheses/omit_parentheses.rb +2 -2
- data/lib/rubocop/cop/style/method_called_on_do_end_block.rb +4 -1
- data/lib/rubocop/cop/style/multiline_block_chain.rb +3 -1
- data/lib/rubocop/cop/style/multiline_in_pattern_then.rb +1 -1
- data/lib/rubocop/cop/style/next.rb +3 -5
- data/lib/rubocop/cop/style/nil_lambda.rb +1 -1
- data/lib/rubocop/cop/style/object_then.rb +2 -0
- data/lib/rubocop/cop/style/proc.rb +4 -1
- data/lib/rubocop/cop/style/redundant_begin.rb +2 -0
- data/lib/rubocop/cop/style/redundant_fetch_block.rb +1 -1
- data/lib/rubocop/cop/style/redundant_self.rb +2 -0
- data/lib/rubocop/cop/style/redundant_sort_by.rb +24 -8
- data/lib/rubocop/cop/style/safe_navigation.rb +4 -2
- data/lib/rubocop/cop/style/single_line_block_params.rb +1 -1
- data/lib/rubocop/cop/style/sole_nested_conditional.rb +0 -2
- data/lib/rubocop/cop/style/symbol_array.rb +1 -1
- data/lib/rubocop/cop/style/top_level_method_definition.rb +3 -1
- data/lib/rubocop/cop/style/trailing_comma_in_block_args.rb +1 -1
- data/lib/rubocop/cop/style/word_array.rb +1 -1
- data/lib/rubocop/cop/util.rb +1 -1
- data/lib/rubocop/feature_loader.rb +9 -3
- data/lib/rubocop/formatter/html_formatter.rb +2 -2
- data/lib/rubocop/server/cache.rb +11 -8
- data/lib/rubocop/version.rb +1 -1
- data/lib/rubocop.rb +3 -2
- metadata +9 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 52ce553282d97fbec24636f7104e3c1c1ceb32b27610542ae22470d84a6421ce
|
4
|
+
data.tar.gz: 6176cfc6699491e9d755e323a813964c1dd244a16d61ad2545e93f8109d69fa6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 69e648784e186575033e4f8b65be6f5fb8f456e557d597e5321bbe0f70d9aef39b0a4c974347d13498b5e88c664177b72aae809b5f39bec98292cb0e7a4fb18a
|
7
|
+
data.tar.gz: 866c506305659953fe31ea005c51d936dcfed82429e7582f7d64daab5ea5b077ef1fb619f7932c204749582dc1bec695e090c32d5b81450984d30e7a2e3125b4
|
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.35', require: false
|
57
57
|
```
|
58
58
|
|
59
59
|
See [our versioning policy](https://docs.rubocop.org/rubocop/versioning.html) for further details.
|
data/config/default.yml
CHANGED
@@ -3839,6 +3839,8 @@ Style/HashSyntax:
|
|
3839
3839
|
- never
|
3840
3840
|
# accepts both shorthand and explicit use of hash literal value.
|
3841
3841
|
- either
|
3842
|
+
# like "always", but will avoid mixing styles in a single hash
|
3843
|
+
- consistent
|
3842
3844
|
# Force hashes that have a symbol value to use hash rockets
|
3843
3845
|
UseHashRocketsWithSymbolValues: false
|
3844
3846
|
# Do not suggest { a?: 1 } over { :a? => 1 } in ruby19 style
|
@@ -4015,6 +4017,26 @@ Style/LineEndConcatenation:
|
|
4015
4017
|
VersionAdded: '0.18'
|
4016
4018
|
VersionChanged: '0.64'
|
4017
4019
|
|
4020
|
+
Style/MagicCommentFormat:
|
4021
|
+
Description: 'Use a consistent style for magic comments.'
|
4022
|
+
Enabled: pending
|
4023
|
+
VersionAdded: '1.35'
|
4024
|
+
EnforcedStyle: snake_case
|
4025
|
+
SupportedStyles:
|
4026
|
+
# `snake` will enforce the magic comment is written
|
4027
|
+
# in snake case (words separated by underscores).
|
4028
|
+
# Eg: froze_string_literal: true
|
4029
|
+
- snake_case
|
4030
|
+
# `kebab` will enforce the magic comment is written
|
4031
|
+
# in kebab case (words separated by hyphens).
|
4032
|
+
# Eg: froze-string-literal: true
|
4033
|
+
- kebab_case
|
4034
|
+
DirectiveCapitalization: lowercase
|
4035
|
+
ValueCapitalization: ~
|
4036
|
+
SupportedCapitalizations:
|
4037
|
+
- lowercase
|
4038
|
+
- uppercase
|
4039
|
+
|
4018
4040
|
Style/MapCompactWithConditionalBlock:
|
4019
4041
|
Description: 'Prefer `select` or `reject` over `map { ... }.compact`.'
|
4020
4042
|
Enabled: pending
|
File without changes
|
data/lib/rubocop/config.rb
CHANGED
@@ -242,7 +242,7 @@ module RuboCop
|
|
242
242
|
return nil unless loaded_path
|
243
243
|
|
244
244
|
base_path = base_dir_for_path_parameters
|
245
|
-
['
|
245
|
+
['Gemfile.lock', 'gems.locked'].each do |file_name|
|
246
246
|
path = find_file_upwards(file_name, base_path)
|
247
247
|
return path if path
|
248
248
|
end
|
@@ -7,6 +7,8 @@ module RuboCop
|
|
7
7
|
class << self
|
8
8
|
include RangeHelp
|
9
9
|
|
10
|
+
COMMA_REGEXP = /(?<=\))\s*,/.freeze
|
11
|
+
|
10
12
|
def correct(corrector, node)
|
11
13
|
corrector.remove(node.loc.begin)
|
12
14
|
corrector.remove(node.loc.end)
|
@@ -39,7 +41,15 @@ module RuboCop
|
|
39
41
|
def handle_orphaned_comma(corrector, node)
|
40
42
|
return unless only_closing_paren_before_comma?(node)
|
41
43
|
|
42
|
-
range =
|
44
|
+
range = extend_range_for_heredoc(node, parens_range(node))
|
45
|
+
corrector.remove(range)
|
46
|
+
|
47
|
+
add_heredoc_comma(corrector, node)
|
48
|
+
end
|
49
|
+
|
50
|
+
# Get a range for the closing parenthesis and all whitespace to the left of it
|
51
|
+
def parens_range(node)
|
52
|
+
range_with_surrounding_space(
|
43
53
|
range: node.loc.end,
|
44
54
|
buffer: node.source_range.source_buffer,
|
45
55
|
side: :left,
|
@@ -47,8 +57,28 @@ module RuboCop
|
|
47
57
|
whitespace: true,
|
48
58
|
continuations: true
|
49
59
|
)
|
60
|
+
end
|
50
61
|
|
51
|
-
|
62
|
+
# If the node contains a heredoc, remove the comma too
|
63
|
+
# It'll be added back in the right place later
|
64
|
+
def extend_range_for_heredoc(node, range)
|
65
|
+
return range unless heredoc?(node)
|
66
|
+
|
67
|
+
comma_line = range_by_whole_lines(node.loc.end, buffer: node.source_range.source_buffer)
|
68
|
+
offset = comma_line.source.match(COMMA_REGEXP)[0]&.size || 0
|
69
|
+
|
70
|
+
range.adjust(end_pos: offset)
|
71
|
+
end
|
72
|
+
|
73
|
+
# Add a comma back after the heredoc identifier
|
74
|
+
def add_heredoc_comma(corrector, node)
|
75
|
+
return unless heredoc?(node)
|
76
|
+
|
77
|
+
corrector.insert_after(node.child_nodes.last.loc.expression, ',')
|
78
|
+
end
|
79
|
+
|
80
|
+
def heredoc?(node)
|
81
|
+
node.child_nodes.last.loc.is_a?(Parser::Source::Map::Heredoc)
|
52
82
|
end
|
53
83
|
end
|
54
84
|
end
|
@@ -84,7 +84,7 @@ module RuboCop
|
|
84
84
|
(str "true")
|
85
85
|
PATTERN
|
86
86
|
|
87
|
-
def on_block(node) # rubocop:disable Metrics/MethodLength
|
87
|
+
def on_block(node) # rubocop:disable Metrics/MethodLength, InternalAffairs/NumblockHandler
|
88
88
|
gem_specification(node) do |block_var|
|
89
89
|
metadata_value = metadata(node)
|
90
90
|
mfa_value = mfa_value(metadata_value)
|
@@ -55,8 +55,8 @@ module RuboCop
|
|
55
55
|
end
|
56
56
|
end
|
57
57
|
|
58
|
-
def require_path_fragments(
|
59
|
-
path =
|
58
|
+
def require_path_fragments(require_directive)
|
59
|
+
path = require_directive.match(REQUIRE_PATH)
|
60
60
|
|
61
61
|
path ? path.captures.first.split('/') : []
|
62
62
|
end
|
@@ -0,0 +1,69 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module RuboCop
|
4
|
+
module Cop
|
5
|
+
module InternalAffairs
|
6
|
+
# Checks for missing `numblock handlers. The blocks with numbered
|
7
|
+
# arguments introduced in Ruby 2.7 are parsed with a node type of
|
8
|
+
# `numblock` instead of block. Cops that define `block` handlers
|
9
|
+
# need to define `numblock` handlers or disable this cope for them.
|
10
|
+
#
|
11
|
+
# @example
|
12
|
+
#
|
13
|
+
# # bad
|
14
|
+
# class BlockRelatedCop < Base
|
15
|
+
# def on_block(node)
|
16
|
+
# end
|
17
|
+
# end
|
18
|
+
#
|
19
|
+
# # good
|
20
|
+
# class BlockRelatedCop < Base
|
21
|
+
# def on_block(node)
|
22
|
+
# end
|
23
|
+
#
|
24
|
+
# alias on_numblock on_block
|
25
|
+
# end
|
26
|
+
#
|
27
|
+
# class BlockRelatedCop < Base
|
28
|
+
# def on_block(node)
|
29
|
+
# end
|
30
|
+
#
|
31
|
+
# alias_method :on_numblock, :on_block
|
32
|
+
# end
|
33
|
+
#
|
34
|
+
# class BlockRelatedCop < Base
|
35
|
+
# def on_block(node)
|
36
|
+
# end
|
37
|
+
#
|
38
|
+
# def on_numblock(node)
|
39
|
+
# end
|
40
|
+
# end
|
41
|
+
class NumblockHandler < Base
|
42
|
+
MSG = 'Define on_numblock to handle blocks with numbered arguments.'
|
43
|
+
|
44
|
+
def on_def(node)
|
45
|
+
return unless block_handler?(node)
|
46
|
+
return unless node.parent
|
47
|
+
|
48
|
+
add_offense(node) unless numblock_handler?(node.parent)
|
49
|
+
end
|
50
|
+
|
51
|
+
private
|
52
|
+
|
53
|
+
# @!method block_handler?(node)
|
54
|
+
def_node_matcher :block_handler?, <<~PATTERN
|
55
|
+
(def :on_block (args (arg :node)) ...)
|
56
|
+
PATTERN
|
57
|
+
|
58
|
+
# @!method numblock_handler?(node)
|
59
|
+
def_node_matcher :numblock_handler?, <<~PATTERN
|
60
|
+
{
|
61
|
+
`(def :on_numblock (args (arg :node)) ...)
|
62
|
+
`(alias (sym :on_numblock) (sym :on_block))
|
63
|
+
`(send nil? :alias_method (sym :on_numblock) (sym :on_block))
|
64
|
+
}
|
65
|
+
PATTERN
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
@@ -29,20 +29,21 @@ module RuboCop
|
|
29
29
|
extend AutoCorrector
|
30
30
|
|
31
31
|
MSG = 'Use `%<preferred>s`.'
|
32
|
-
RESTRICT_ON_SEND = %i[==].freeze
|
32
|
+
RESTRICT_ON_SEND = %i[== !=].freeze
|
33
33
|
|
34
34
|
# @!method single_line_comparison(node)
|
35
35
|
def_node_matcher :single_line_comparison, <<~PATTERN
|
36
36
|
{
|
37
|
-
(send (send $_receiver {:line :first_line}) :== (send _receiver :last_line))
|
38
|
-
(send (send $_receiver :last_line) :== (send _receiver {:line :first_line}))
|
37
|
+
(send (send $_receiver {:line :first_line}) {:== :!=} (send _receiver :last_line))
|
38
|
+
(send (send $_receiver :last_line) {:== :!=} (send _receiver {:line :first_line}))
|
39
39
|
}
|
40
40
|
PATTERN
|
41
41
|
|
42
42
|
def on_send(node)
|
43
43
|
return unless (receiver = single_line_comparison(node))
|
44
44
|
|
45
|
-
|
45
|
+
bang = node.method?(:!=) ? '!' : ''
|
46
|
+
preferred = "#{bang}#{extract_receiver(receiver)}.single_line?"
|
46
47
|
|
47
48
|
add_offense(node, message: format(MSG, preferred: preferred)) do |corrector|
|
48
49
|
corrector.replace(node, preferred)
|
@@ -10,6 +10,7 @@ require_relative 'internal_affairs/method_name_equal'
|
|
10
10
|
require_relative 'internal_affairs/node_destructuring'
|
11
11
|
require_relative 'internal_affairs/node_matcher_directive'
|
12
12
|
require_relative 'internal_affairs/node_type_predicate'
|
13
|
+
require_relative 'internal_affairs/numblock_handler'
|
13
14
|
require_relative 'internal_affairs/offense_location_keyword'
|
14
15
|
require_relative 'internal_affairs/redundant_context_config_parameter'
|
15
16
|
require_relative 'internal_affairs/redundant_described_class_as_subject'
|
@@ -80,8 +80,11 @@ module RuboCop
|
|
80
80
|
@block_line = node.source_range.first_line
|
81
81
|
end
|
82
82
|
|
83
|
-
|
84
|
-
|
83
|
+
alias on_numblock on_block
|
84
|
+
|
85
|
+
def on_send(node) # rubocop:disable Metrics/CyclomaticComplexity
|
86
|
+
return unless node.bare_access_modifier? &&
|
87
|
+
!(node.parent&.block_type? || node.parent&.numblock_type?)
|
85
88
|
return if expected_empty_lines?(node)
|
86
89
|
|
87
90
|
message = message(node)
|
@@ -22,20 +22,20 @@ module RuboCop
|
|
22
22
|
# # all platforms.
|
23
23
|
#
|
24
24
|
# # bad
|
25
|
-
# puts 'Hello' # Return character is CR+LF on all
|
25
|
+
# puts 'Hello' # Return character is CR+LF on all platforms.
|
26
26
|
#
|
27
27
|
# # good
|
28
|
-
# puts 'Hello' # Return character is LF on all
|
28
|
+
# puts 'Hello' # Return character is LF on all platforms.
|
29
29
|
#
|
30
30
|
# @example EnforcedStyle: crlf
|
31
31
|
# # The `crlf` style means that CR+LF (Carriage Return + Line Feed) is
|
32
32
|
# # enforced on all platforms.
|
33
33
|
#
|
34
34
|
# # bad
|
35
|
-
# puts 'Hello' # Return character is LF on all
|
35
|
+
# puts 'Hello' # Return character is LF on all platforms.
|
36
36
|
#
|
37
37
|
# # good
|
38
|
-
# puts 'Hello' # Return character is CR+LF on all
|
38
|
+
# puts 'Hello' # Return character is CR+LF on all platforms.
|
39
39
|
#
|
40
40
|
class EndOfLine < Base
|
41
41
|
include ConfigurableEnforcedStyle
|
@@ -143,7 +143,7 @@ module RuboCop
|
|
143
143
|
case indent_base_type
|
144
144
|
when :left_brace_or_bracket
|
145
145
|
'the position of the opening bracket'
|
146
|
-
when :
|
146
|
+
when :first_column_after_left_parenthesis
|
147
147
|
'the first position after the preceding left parenthesis'
|
148
148
|
when :parent_hash_key
|
149
149
|
'the parent hash key'
|
@@ -164,7 +164,7 @@ module RuboCop
|
|
164
164
|
case indent_base_type
|
165
165
|
when :left_brace_or_bracket
|
166
166
|
'Indent the right bracket the same as the left bracket.'
|
167
|
-
when :
|
167
|
+
when :first_column_after_left_parenthesis
|
168
168
|
'Indent the right bracket the same as the first position ' \
|
169
169
|
'after the preceding left parenthesis.'
|
170
170
|
when :parent_hash_key
|
@@ -192,7 +192,7 @@ module RuboCop
|
|
192
192
|
case indent_base_type
|
193
193
|
when :left_brace_or_bracket
|
194
194
|
'the position of the opening brace'
|
195
|
-
when :
|
195
|
+
when :first_column_after_left_parenthesis
|
196
196
|
'the first position after the preceding left parenthesis'
|
197
197
|
when :parent_hash_key
|
198
198
|
'the parent hash key'
|
@@ -213,7 +213,7 @@ module RuboCop
|
|
213
213
|
case indent_base_type
|
214
214
|
when :left_brace_or_bracket
|
215
215
|
'Indent the right brace the same as the left brace.'
|
216
|
-
when :
|
216
|
+
when :first_column_after_left_parenthesis
|
217
217
|
'Indent the right brace the same as the first position ' \
|
218
218
|
'after the preceding left parenthesis.'
|
219
219
|
when :parent_hash_key
|
@@ -22,6 +22,7 @@ module RuboCop
|
|
22
22
|
# (Many of these are enabled by default.)
|
23
23
|
#
|
24
24
|
# * ArgumentAlignment
|
25
|
+
# * ArrayAlignment
|
25
26
|
# * BlockAlignment
|
26
27
|
# * BlockDelimiters
|
27
28
|
# * BlockEndNewline
|
@@ -74,6 +75,8 @@ module RuboCop
|
|
74
75
|
check_for_breakable_block(node)
|
75
76
|
end
|
76
77
|
|
78
|
+
alias on_numblock on_block
|
79
|
+
|
77
80
|
def on_potential_breakable_node(node)
|
78
81
|
check_for_breakable_node(node)
|
79
82
|
end
|
@@ -131,7 +134,7 @@ module RuboCop
|
|
131
134
|
if block_node.arguments? && !block_node.lambda?
|
132
135
|
block_node.arguments.loc.end
|
133
136
|
else
|
134
|
-
block_node.loc.begin
|
137
|
+
block_node.braces? ? block_node.loc.begin : block_node.loc.begin.adjust(begin_pos: 1)
|
135
138
|
end
|
136
139
|
end
|
137
140
|
|
@@ -101,7 +101,7 @@ module RuboCop
|
|
101
101
|
!comment_within?(node) &&
|
102
102
|
node.each_descendant(:if, :case, :kwbegin, :def).none? &&
|
103
103
|
node.each_descendant(:dstr, :str).none?(&:heredoc?) &&
|
104
|
-
node.each_descendant(:begin).none? { |b| b.
|
104
|
+
node.each_descendant(:begin).none? { |b| !b.single_line? }
|
105
105
|
end
|
106
106
|
|
107
107
|
def convertible_block?(node)
|
@@ -66,7 +66,7 @@ module RuboCop
|
|
66
66
|
private
|
67
67
|
|
68
68
|
def delimiter
|
69
|
-
|
69
|
+
CLASS_METHOD_DELIMITER
|
70
70
|
end
|
71
71
|
end
|
72
72
|
|
@@ -89,7 +89,7 @@ module RuboCop
|
|
89
89
|
private
|
90
90
|
|
91
91
|
def delimiter
|
92
|
-
instance_method? ?
|
92
|
+
instance_method? ? INSTANCE_METHOD_DELIMITER : CLASS_METHOD_DELIMITER
|
93
93
|
end
|
94
94
|
|
95
95
|
def instance_method?
|
@@ -126,8 +126,8 @@ module RuboCop
|
|
126
126
|
|
127
127
|
RESTRICT_ON_SEND = DEPRECATED_METHODS_OBJECT.keys.map(&:method).freeze
|
128
128
|
|
129
|
-
|
130
|
-
|
129
|
+
CLASS_METHOD_DELIMITER = '.'
|
130
|
+
INSTANCE_METHOD_DELIMITER = '#'
|
131
131
|
|
132
132
|
def on_send(node)
|
133
133
|
check(node) do |deprecated|
|
@@ -63,7 +63,7 @@ module RuboCop
|
|
63
63
|
class EmptyBlock < Base
|
64
64
|
MSG = 'Empty block detected.'
|
65
65
|
|
66
|
-
def on_block(node)
|
66
|
+
def on_block(node) # rubocop:disable InternalAffairs/NumblockHandler
|
67
67
|
return if node.body
|
68
68
|
return if allow_empty_lambdas? && lambda_or_proc?(node)
|
69
69
|
return if cop_config['AllowComments'] && allow_comment?(node)
|
@@ -6,18 +6,18 @@ module RuboCop
|
|
6
6
|
#
|
7
7
|
# This cop emulates the following Ruby warnings in Ruby 2.6.
|
8
8
|
#
|
9
|
+
# [source,console]
|
10
|
+
# ----
|
9
11
|
# % cat example.rb
|
10
12
|
# ERB.new('hi', nil, '-', '@output_buffer')
|
11
13
|
# % ruby -rerb example.rb
|
12
|
-
# example.rb:1: warning: Passing safe_level with the 2nd argument of
|
13
|
-
#
|
14
|
-
#
|
15
|
-
#
|
16
|
-
#
|
17
|
-
# ERB.new(str,
|
18
|
-
#
|
19
|
-
# is deprecated. Use keyword argument like ERB.new(str, eoutvar: ...)
|
20
|
-
# instead.
|
14
|
+
# example.rb:1: warning: Passing safe_level with the 2nd argument of ERB.new is
|
15
|
+
# deprecated. Do not use it, and specify other arguments as keyword arguments.
|
16
|
+
# example.rb:1: warning: Passing trim_mode with the 3rd argument of ERB.new is
|
17
|
+
# deprecated. Use keyword argument like ERB.new(str, trim_mode:...) instead.
|
18
|
+
# example.rb:1: warning: Passing eoutvar with the 4th argument of ERB.new is
|
19
|
+
# deprecated. Use keyword argument like ERB.new(str, eoutvar: ...) instead.
|
20
|
+
# ----
|
21
21
|
#
|
22
22
|
# Now non-keyword arguments other than first one are softly deprecated
|
23
23
|
# and will be removed when Ruby 2.5 becomes EOL.
|
@@ -58,6 +58,7 @@ module RuboCop
|
|
58
58
|
(node.str_type? && !node.loc.respond_to?(:begin)) || node.source_range.is?('__LINE__')
|
59
59
|
end
|
60
60
|
|
61
|
+
# rubocop:disable Metrics/MethodLength
|
61
62
|
def autocorrected_value(node)
|
62
63
|
case node.type
|
63
64
|
when :int
|
@@ -70,10 +71,13 @@ module RuboCop
|
|
70
71
|
autocorrected_value_for_symbol(node)
|
71
72
|
when :array
|
72
73
|
autocorrected_value_for_array(node)
|
74
|
+
when :nil
|
75
|
+
''
|
73
76
|
else
|
74
77
|
node.source.gsub('"', '\"')
|
75
78
|
end
|
76
79
|
end
|
80
|
+
# rubocop:enable Metrics/MethodLength
|
77
81
|
|
78
82
|
def autocorrected_value_for_string(node)
|
79
83
|
if node.source.start_with?("'", '%q')
|
@@ -25,13 +25,8 @@ module RuboCop
|
|
25
25
|
class NextWithoutAccumulator < Base
|
26
26
|
MSG = 'Use `next` with an accumulator argument in a `reduce`.'
|
27
27
|
|
28
|
-
# @!method on_body_of_reduce(node)
|
29
|
-
def_node_matcher :on_body_of_reduce, <<~PATTERN
|
30
|
-
(block (send _recv {:reduce :inject} !sym) _blockargs $(begin ...))
|
31
|
-
PATTERN
|
32
|
-
|
33
28
|
def on_block(node)
|
34
|
-
|
29
|
+
on_block_body_of_reduce(node) do |body|
|
35
30
|
void_next = body.each_node(:next).find do |n|
|
36
31
|
n.children.empty? && parent_block_node(n) == node
|
37
32
|
end
|
@@ -40,11 +35,35 @@ module RuboCop
|
|
40
35
|
end
|
41
36
|
end
|
42
37
|
|
38
|
+
def on_numblock(node)
|
39
|
+
on_numblock_body_of_reduce(node) do |body|
|
40
|
+
void_next = body.each_node(:next).find do |n|
|
41
|
+
n.children.empty? && parent_numblock_node(n) == node
|
42
|
+
end
|
43
|
+
|
44
|
+
add_offense(void_next) if void_next
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
43
48
|
private
|
44
49
|
|
50
|
+
# @!method on_block_body_of_reduce(node)
|
51
|
+
def_node_matcher :on_block_body_of_reduce, <<~PATTERN
|
52
|
+
(block (send _recv {:reduce :inject} !sym) _blockargs $(begin ...))
|
53
|
+
PATTERN
|
54
|
+
|
55
|
+
# @!method on_numblock_body_of_reduce(node)
|
56
|
+
def_node_matcher :on_numblock_body_of_reduce, <<~PATTERN
|
57
|
+
(numblock (send _recv {:reduce :inject} !sym) _argscount $(begin ...))
|
58
|
+
PATTERN
|
59
|
+
|
45
60
|
def parent_block_node(node)
|
46
61
|
node.each_ancestor(:block).first
|
47
62
|
end
|
63
|
+
|
64
|
+
def parent_numblock_node(node)
|
65
|
+
node.each_ancestor(:numblock).first
|
66
|
+
end
|
48
67
|
end
|
49
68
|
end
|
50
69
|
end
|
@@ -99,19 +99,19 @@ module RuboCop
|
|
99
99
|
end
|
100
100
|
|
101
101
|
def register_offense(node, exist_node)
|
102
|
-
unless force_method?(node)
|
103
|
-
add_offense(node,
|
104
|
-
message: format(MSG_CHANGE_FORCE_METHOD,
|
105
|
-
method_name: replacement_method(node)))
|
106
|
-
end
|
102
|
+
add_offense(node, message: message_change_force_method(node)) unless force_method?(node)
|
107
103
|
|
108
104
|
range = range_between(node.parent.loc.keyword.begin_pos,
|
109
105
|
exist_node.loc.expression.end_pos)
|
110
106
|
add_offense(range, message: message_remove_file_exist_check(exist_node)) do |corrector|
|
111
|
-
autocorrect(corrector, node, range)
|
107
|
+
autocorrect(corrector, node, range) unless node.parent.elsif?
|
112
108
|
end
|
113
109
|
end
|
114
110
|
|
111
|
+
def message_change_force_method(node)
|
112
|
+
format(MSG_CHANGE_FORCE_METHOD, method_name: replacement_method(node))
|
113
|
+
end
|
114
|
+
|
115
115
|
def message_remove_file_exist_check(node)
|
116
116
|
receiver, method_name = receiver_and_method_name(node)
|
117
117
|
format(MSG_REMOVE_FILE_EXIST_CHECK, receiver: receiver, method_name: method_name)
|
@@ -74,6 +74,18 @@ module RuboCop
|
|
74
74
|
end
|
75
75
|
end
|
76
76
|
|
77
|
+
def on_numblock(node)
|
78
|
+
return if target_ruby_version >= 3.0
|
79
|
+
return unless node.body
|
80
|
+
return unless unsorted_dir_loop?(node.send_node)
|
81
|
+
|
82
|
+
node.argument_list
|
83
|
+
.filter { |argument| var_is_required?(node.body, argument.name) }
|
84
|
+
.each do
|
85
|
+
add_offense(node.send_node) { |corrector| correct_block(corrector, node.send_node) }
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
77
89
|
def on_block_pass(node)
|
78
90
|
return if target_ruby_version >= 3.0
|
79
91
|
return unless method_require?(node)
|