rubocop 0.83.0 → 0.84.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 +20 -3
- data/lib/rubocop.rb +6 -59
- data/lib/rubocop/ast_aliases.rb +8 -0
- data/lib/rubocop/cli/command/show_cops.rb +2 -6
- data/lib/rubocop/config.rb +1 -3
- data/lib/rubocop/config_loader.rb +3 -9
- data/lib/rubocop/config_loader_resolver.rb +2 -6
- data/lib/rubocop/cop/autocorrect_logic.rb +1 -2
- data/lib/rubocop/cop/corrector.rb +1 -3
- data/lib/rubocop/cop/correctors/alignment_corrector.rb +2 -6
- data/lib/rubocop/cop/correctors/parentheses_corrector.rb +1 -3
- data/lib/rubocop/cop/correctors/space_corrector.rb +1 -3
- data/lib/rubocop/cop/gemspec/ordered_dependencies.rb +1 -3
- data/lib/rubocop/cop/generator.rb +1 -1
- data/lib/rubocop/cop/ignored_node.rb +1 -3
- data/lib/rubocop/cop/layout/empty_lines_around_access_modifier.rb +2 -6
- data/lib/rubocop/cop/layout/empty_lines_around_attribute_accessor.rb +62 -4
- data/lib/rubocop/cop/layout/first_argument_indentation.rb +0 -2
- data/lib/rubocop/cop/layout/first_array_element_indentation.rb +1 -3
- data/lib/rubocop/cop/layout/first_method_argument_line_break.rb +1 -3
- data/lib/rubocop/cop/layout/heredoc_argument_closing_parenthesis.rb +2 -6
- data/lib/rubocop/cop/layout/indentation_width.rb +1 -3
- data/lib/rubocop/cop/layout/multiline_block_layout.rb +1 -3
- data/lib/rubocop/cop/layout/multiline_method_argument_line_breaks.rb +1 -3
- data/lib/rubocop/cop/layout/space_around_method_call_operator.rb +2 -6
- data/lib/rubocop/cop/layout/space_before_comment.rb +1 -3
- data/lib/rubocop/cop/layout/space_inside_array_literal_brackets.rb +1 -3
- data/lib/rubocop/cop/layout/space_inside_reference_brackets.rb +2 -6
- data/lib/rubocop/cop/lint/ambiguous_operator.rb +4 -2
- data/lib/rubocop/cop/lint/deprecated_open_ssl_constant.rb +133 -0
- data/lib/rubocop/cop/lint/erb_new_arguments.rb +2 -6
- data/lib/rubocop/cop/lint/parentheses_as_grouped_expression.rb +11 -3
- data/lib/rubocop/cop/lint/percent_string_array.rb +1 -3
- data/lib/rubocop/cop/lint/suppressed_exception.rb +12 -1
- data/lib/rubocop/cop/lint/syntax.rb +1 -3
- data/lib/rubocop/cop/lint/useless_access_modifier.rb +1 -3
- data/lib/rubocop/cop/migration/department_name.rb +5 -9
- data/lib/rubocop/cop/mixin/alignment.rb +1 -3
- data/lib/rubocop/cop/mixin/array_min_size.rb +2 -6
- data/lib/rubocop/cop/mixin/check_line_breakable.rb +4 -12
- data/lib/rubocop/cop/mixin/configurable_enforced_style.rb +1 -3
- data/lib/rubocop/cop/mixin/configurable_formatting.rb +1 -3
- data/lib/rubocop/cop/mixin/multiline_element_indentation.rb +1 -3
- data/lib/rubocop/cop/mixin/surrounding_space.rb +1 -3
- data/lib/rubocop/cop/mixin/trailing_comma.rb +1 -3
- data/lib/rubocop/cop/naming/file_name.rb +1 -3
- data/lib/rubocop/cop/registry.rb +2 -6
- data/lib/rubocop/cop/severity.rb +1 -3
- data/lib/rubocop/cop/style/and_or.rb +2 -2
- data/lib/rubocop/cop/style/attr.rb +1 -3
- data/lib/rubocop/cop/style/block_delimiters.rb +2 -8
- data/lib/rubocop/cop/style/conditional_assignment.rb +1 -3
- data/lib/rubocop/cop/style/double_negation.rb +41 -4
- data/lib/rubocop/cop/style/empty_literal.rb +1 -3
- data/lib/rubocop/cop/style/frozen_string_literal_comment.rb +2 -4
- data/lib/rubocop/cop/style/hash_syntax.rb +12 -5
- data/lib/rubocop/cop/style/method_call_with_args_parentheses/require_parentheses.rb +1 -3
- data/lib/rubocop/cop/style/method_call_without_args_parentheses.rb +1 -3
- data/lib/rubocop/cop/style/one_line_conditional.rb +2 -6
- data/lib/rubocop/cop/style/redundant_parentheses.rb +2 -6
- data/lib/rubocop/cop/style/safe_navigation.rb +2 -6
- data/lib/rubocop/cop/style/slicing_with_range.rb +1 -1
- data/lib/rubocop/cop/style/special_global_vars.rb +2 -6
- data/lib/rubocop/cop/style/ternary_parentheses.rb +1 -3
- data/lib/rubocop/cop/style/trailing_underscore_variable.rb +2 -6
- data/lib/rubocop/cop/variable_force.rb +3 -9
- data/lib/rubocop/cop/variable_force/branch.rb +2 -6
- data/lib/rubocop/cop/variable_force/variable.rb +2 -6
- data/lib/rubocop/ext/processed_source.rb +18 -0
- data/lib/rubocop/formatter/base_formatter.rb +0 -4
- data/lib/rubocop/formatter/disabled_config_formatter.rb +4 -12
- data/lib/rubocop/formatter/formatter_set.rb +1 -3
- data/lib/rubocop/options.rb +2 -8
- data/lib/rubocop/remote_config.rb +1 -3
- data/lib/rubocop/result_cache.rb +1 -3
- data/lib/rubocop/rspec/cop_helper.rb +1 -3
- data/lib/rubocop/rspec/expect_offense.rb +3 -9
- data/lib/rubocop/rspec/shared_contexts.rb +54 -16
- data/lib/rubocop/runner.rb +8 -10
- data/lib/rubocop/target_finder.rb +2 -6
- data/lib/rubocop/version.rb +5 -3
- metadata +19 -56
- data/lib/rubocop/ast/builder.rb +0 -85
- data/lib/rubocop/ast/node.rb +0 -637
- data/lib/rubocop/ast/node/alias_node.rb +0 -24
- data/lib/rubocop/ast/node/and_node.rb +0 -29
- data/lib/rubocop/ast/node/args_node.rb +0 -29
- data/lib/rubocop/ast/node/array_node.rb +0 -70
- data/lib/rubocop/ast/node/block_node.rb +0 -121
- data/lib/rubocop/ast/node/break_node.rb +0 -17
- data/lib/rubocop/ast/node/case_match_node.rb +0 -56
- data/lib/rubocop/ast/node/case_node.rb +0 -56
- data/lib/rubocop/ast/node/class_node.rb +0 -31
- data/lib/rubocop/ast/node/def_node.rb +0 -82
- data/lib/rubocop/ast/node/defined_node.rb +0 -17
- data/lib/rubocop/ast/node/ensure_node.rb +0 -17
- data/lib/rubocop/ast/node/float_node.rb +0 -12
- data/lib/rubocop/ast/node/for_node.rb +0 -53
- data/lib/rubocop/ast/node/forward_args_node.rb +0 -18
- data/lib/rubocop/ast/node/hash_node.rb +0 -109
- data/lib/rubocop/ast/node/if_node.rb +0 -175
- data/lib/rubocop/ast/node/int_node.rb +0 -12
- data/lib/rubocop/ast/node/keyword_splat_node.rb +0 -45
- data/lib/rubocop/ast/node/mixin/basic_literal_node.rb +0 -16
- data/lib/rubocop/ast/node/mixin/binary_operator_node.rb +0 -43
- data/lib/rubocop/ast/node/mixin/collection_node.rb +0 -15
- data/lib/rubocop/ast/node/mixin/conditional_node.rb +0 -45
- data/lib/rubocop/ast/node/mixin/hash_element_node.rb +0 -125
- data/lib/rubocop/ast/node/mixin/method_dispatch_node.rb +0 -269
- data/lib/rubocop/ast/node/mixin/method_identifier_predicates.rb +0 -114
- data/lib/rubocop/ast/node/mixin/modifier_node.rb +0 -17
- data/lib/rubocop/ast/node/mixin/numeric_node.rb +0 -21
- data/lib/rubocop/ast/node/mixin/parameterized_node.rb +0 -61
- data/lib/rubocop/ast/node/mixin/predicate_operator_node.rb +0 -35
- data/lib/rubocop/ast/node/module_node.rb +0 -24
- data/lib/rubocop/ast/node/or_node.rb +0 -29
- data/lib/rubocop/ast/node/pair_node.rb +0 -63
- data/lib/rubocop/ast/node/range_node.rb +0 -18
- data/lib/rubocop/ast/node/regexp_node.rb +0 -33
- data/lib/rubocop/ast/node/resbody_node.rb +0 -24
- data/lib/rubocop/ast/node/retry_node.rb +0 -17
- data/lib/rubocop/ast/node/return_node.rb +0 -24
- data/lib/rubocop/ast/node/self_class_node.rb +0 -24
- data/lib/rubocop/ast/node/send_node.rb +0 -17
- data/lib/rubocop/ast/node/str_node.rb +0 -16
- data/lib/rubocop/ast/node/super_node.rb +0 -21
- data/lib/rubocop/ast/node/symbol_node.rb +0 -12
- data/lib/rubocop/ast/node/until_node.rb +0 -35
- data/lib/rubocop/ast/node/when_node.rb +0 -53
- data/lib/rubocop/ast/node/while_node.rb +0 -35
- data/lib/rubocop/ast/node/yield_node.rb +0 -21
- data/lib/rubocop/ast/sexp.rb +0 -16
- data/lib/rubocop/ast/traversal.rb +0 -202
- data/lib/rubocop/node_pattern.rb +0 -887
- data/lib/rubocop/processed_source.rb +0 -213
- data/lib/rubocop/token.rb +0 -114
@@ -25,9 +25,7 @@ module RuboCop
|
|
25
25
|
end
|
26
26
|
|
27
27
|
def check_alignment(items, base_column = nil)
|
28
|
-
unless items.empty?
|
29
|
-
base_column ||= display_column(items.first.source_range)
|
30
|
-
end
|
28
|
+
base_column ||= display_column(items.first.source_range) unless items.empty?
|
31
29
|
|
32
30
|
each_bad_alignment(items, base_column) do |current|
|
33
31
|
expr = current.source_range
|
@@ -38,9 +38,7 @@ module RuboCop
|
|
38
38
|
def largest_brackets_size(style, ary_size)
|
39
39
|
self.class.largest_brackets ||= -Float::INFINITY
|
40
40
|
|
41
|
-
if style == :brackets && ary_size > self.class.largest_brackets
|
42
|
-
self.class.largest_brackets = ary_size
|
43
|
-
end
|
41
|
+
self.class.largest_brackets = ary_size if style == :brackets && ary_size > self.class.largest_brackets
|
44
42
|
|
45
43
|
self.class.largest_brackets
|
46
44
|
end
|
@@ -48,9 +46,7 @@ module RuboCop
|
|
48
46
|
def smallest_percent_size(style, ary_size)
|
49
47
|
@smallest_percent ||= Float::INFINITY
|
50
48
|
|
51
|
-
if style == :percent && ary_size < @smallest_percent
|
52
|
-
@smallest_percent = ary_size
|
53
|
-
end
|
49
|
+
@smallest_percent = ary_size if style == :percent && ary_size < @smallest_percent
|
54
50
|
|
55
51
|
@smallest_percent
|
56
52
|
end
|
@@ -88,9 +88,7 @@ module RuboCop
|
|
88
88
|
# or redundant edits, we only mark one offense at a time.
|
89
89
|
return true if contained_by_breakable_collection_on_same_line?(node)
|
90
90
|
|
91
|
-
if contained_by_multiline_collection_that_could_be_broken_up?(node)
|
92
|
-
return true
|
93
|
-
end
|
91
|
+
return true if contained_by_multiline_collection_that_could_be_broken_up?(node)
|
94
92
|
|
95
93
|
false
|
96
94
|
end
|
@@ -133,17 +131,13 @@ module RuboCop
|
|
133
131
|
def contained_by_multiline_collection_that_could_be_broken_up?(node)
|
134
132
|
node.each_ancestor.find do |ancestor|
|
135
133
|
if ancestor.hash_type? || ancestor.array_type?
|
136
|
-
if breakable_collection?(ancestor, ancestor.children)
|
137
|
-
return children_could_be_broken_up?(ancestor.children)
|
138
|
-
end
|
134
|
+
return children_could_be_broken_up?(ancestor.children) if breakable_collection?(ancestor, ancestor.children)
|
139
135
|
end
|
140
136
|
|
141
137
|
next unless ancestor.send_type?
|
142
138
|
|
143
139
|
args = process_args(ancestor.arguments)
|
144
|
-
if breakable_collection?(ancestor, args)
|
145
|
-
return children_could_be_broken_up?(args)
|
146
|
-
end
|
140
|
+
return children_could_be_broken_up?(args) if breakable_collection?(ancestor, args)
|
147
141
|
end
|
148
142
|
|
149
143
|
false
|
@@ -175,9 +169,7 @@ module RuboCop
|
|
175
169
|
# ...then each key/value pair is treated as a method 'argument'
|
176
170
|
# when determining where line breaks should appear.
|
177
171
|
if (last_arg = args.last)
|
178
|
-
if last_arg.hash_type? && !last_arg.braces?
|
179
|
-
args = args.concat(args.pop.children)
|
180
|
-
end
|
172
|
+
args = args.concat(args.pop.children) if last_arg.hash_type? && !last_arg.braces?
|
181
173
|
end
|
182
174
|
args
|
183
175
|
end
|
@@ -67,9 +67,7 @@ module RuboCop
|
|
67
67
|
def style
|
68
68
|
@style ||= begin
|
69
69
|
s = cop_config[style_parameter_name].to_sym
|
70
|
-
unless supported_styles.include?(s)
|
71
|
-
raise "Unknown style #{s} selected!"
|
72
|
-
end
|
70
|
+
raise "Unknown style #{s} selected!" unless supported_styles.include?(s)
|
73
71
|
|
74
72
|
s
|
75
73
|
end
|
@@ -18,9 +18,7 @@ module RuboCop
|
|
18
18
|
|
19
19
|
def report_opposing_styles(node, name)
|
20
20
|
alternative_styles.each do |alternative|
|
21
|
-
if valid_name?(node, name, alternative)
|
22
|
-
return unexpected_style_detected(alternative)
|
23
|
-
end
|
21
|
+
return unexpected_style_detected(alternative) if valid_name?(node, name, alternative)
|
24
22
|
end
|
25
23
|
end
|
26
24
|
|
@@ -67,9 +67,7 @@ module RuboCop
|
|
67
67
|
styles << :consistent
|
68
68
|
styles << :special_inside_parentheses unless left_parenthesis
|
69
69
|
end
|
70
|
-
if left_parenthesis && column == left_parenthesis.column + 1
|
71
|
-
styles << :special_inside_parentheses
|
72
|
-
end
|
70
|
+
styles << :special_inside_parentheses if left_parenthesis && column == left_parenthesis.column + 1
|
73
71
|
styles << brace_alignment_style if column == left_brace.column
|
74
72
|
styles
|
75
73
|
end
|
@@ -107,9 +107,7 @@ module RuboCop
|
|
107
107
|
|
108
108
|
def empty_offenses(node, left, right, message)
|
109
109
|
range = range_between(left.begin_pos, right.end_pos)
|
110
|
-
if offending_empty_space?(empty_config, left, right)
|
111
|
-
empty_offense(node, range, message, 'Use one')
|
112
|
-
end
|
110
|
+
empty_offense(node, range, message, 'Use one') if offending_empty_space?(empty_config, left, right)
|
113
111
|
return unless offending_empty_no_space?(empty_config, left, right)
|
114
112
|
|
115
113
|
empty_offense(node, range, message, 'Do not use')
|
@@ -153,9 +153,7 @@ module RuboCop
|
|
153
153
|
|
154
154
|
namespace, name = *namespace
|
155
155
|
|
156
|
-
if name == expected.last || match_acronym?(expected.last, name)
|
157
|
-
expected.pop
|
158
|
-
end
|
156
|
+
expected.pop if name == expected.last || match_acronym?(expected.last, name)
|
159
157
|
end
|
160
158
|
|
161
159
|
false
|
data/lib/rubocop/cop/registry.rb
CHANGED
@@ -94,9 +94,7 @@ module RuboCop
|
|
94
94
|
# @return [String] Qualified cop name
|
95
95
|
def qualified_cop_name(name, path, shall_warn = true)
|
96
96
|
badge = Badge.parse(name)
|
97
|
-
if shall_warn && department_missing?(badge, name)
|
98
|
-
print_warning(name, path)
|
99
|
-
end
|
97
|
+
print_warning(name, path) if shall_warn && department_missing?(badge, name)
|
100
98
|
return name if registered?(badge)
|
101
99
|
|
102
100
|
potential_badges = qualify_badge(badge)
|
@@ -114,9 +112,7 @@ module RuboCop
|
|
114
112
|
|
115
113
|
def print_warning(name, path)
|
116
114
|
message = "#{path}: Warning: no department given for #{name}."
|
117
|
-
if path.end_with?('.rb')
|
118
|
-
message += ' Run `rubocop -a --only Migration/DepartmentName` to fix.'
|
119
|
-
end
|
115
|
+
message += ' Run `rubocop -a --only Migration/DepartmentName` to fix.' if path.end_with?('.rb')
|
120
116
|
warn message
|
121
117
|
end
|
122
118
|
|
data/lib/rubocop/cop/severity.rb
CHANGED
@@ -31,9 +31,7 @@ module RuboCop
|
|
31
31
|
# @api private
|
32
32
|
def initialize(name_or_code)
|
33
33
|
name = Severity.name_from_code(name_or_code)
|
34
|
-
unless NAMES.include?(name)
|
35
|
-
raise ArgumentError, "Unknown severity: #{name}"
|
36
|
-
end
|
34
|
+
raise ArgumentError, "Unknown severity: #{name}" unless NAMES.include?(name)
|
37
35
|
|
38
36
|
@name = name.freeze
|
39
37
|
freeze
|
@@ -7,7 +7,7 @@ module RuboCop
|
|
7
7
|
# `||` instead. It can be configured to check only in conditions or in
|
8
8
|
# all contexts.
|
9
9
|
#
|
10
|
-
# @example EnforcedStyle: always
|
10
|
+
# @example EnforcedStyle: always
|
11
11
|
# # bad
|
12
12
|
# foo.save and return
|
13
13
|
#
|
@@ -22,7 +22,7 @@ module RuboCop
|
|
22
22
|
# if foo && bar
|
23
23
|
# end
|
24
24
|
#
|
25
|
-
# @example EnforcedStyle: conditionals
|
25
|
+
# @example EnforcedStyle: conditionals (default)
|
26
26
|
# # bad
|
27
27
|
# if foo and bar
|
28
28
|
# end
|
@@ -35,9 +35,7 @@ module RuboCop
|
|
35
35
|
node_expr = node.source_range
|
36
36
|
attr_expr = attr_name.source_range
|
37
37
|
|
38
|
-
if setter&.boolean_type?
|
39
|
-
remove = range_between(attr_expr.end_pos, node_expr.end_pos)
|
40
|
-
end
|
38
|
+
remove = range_between(attr_expr.end_pos, node_expr.end_pos) if setter&.boolean_type?
|
41
39
|
|
42
40
|
lambda do |corrector|
|
43
41
|
corrector.replace(node.loc.selector, replacement_method(node))
|
@@ -1,6 +1,5 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
# rubocop:disable Metrics/ClassLength
|
4
3
|
module RuboCop
|
5
4
|
module Cop
|
6
5
|
module Style
|
@@ -210,9 +209,7 @@ module RuboCop
|
|
210
209
|
end
|
211
210
|
|
212
211
|
def message(node)
|
213
|
-
if braces_required_method?(node.method_name)
|
214
|
-
return braces_required_message(node)
|
215
|
-
end
|
212
|
+
return braces_required_message(node) if braces_required_method?(node.method_name)
|
216
213
|
|
217
214
|
case style
|
218
215
|
when :line_count_based then line_count_based_message(node)
|
@@ -276,9 +273,7 @@ module RuboCop
|
|
276
273
|
# rubocop:enable Metrics/CyclomaticComplexity
|
277
274
|
|
278
275
|
def proper_block_style?(node)
|
279
|
-
if special_method?(node.method_name)
|
280
|
-
return special_method_proper_block_style?(node)
|
281
|
-
end
|
276
|
+
return special_method_proper_block_style?(node) if special_method?(node.method_name)
|
282
277
|
|
283
278
|
case style
|
284
279
|
when :line_count_based then line_count_based_block_style?(node)
|
@@ -387,4 +382,3 @@ module RuboCop
|
|
387
382
|
end
|
388
383
|
end
|
389
384
|
end
|
390
|
-
# rubocop:enable Metrics/ClassLength
|
@@ -312,9 +312,7 @@ module RuboCop
|
|
312
312
|
# ignore pseudo-assignments without rhs in for nodes
|
313
313
|
return if node.parent&.for_type?
|
314
314
|
|
315
|
-
if assignment.begin_type? && assignment.children.one?
|
316
|
-
assignment, = *assignment
|
317
|
-
end
|
315
|
+
assignment, = *assignment if assignment.begin_type? && assignment.children.one?
|
318
316
|
|
319
317
|
assignment
|
320
318
|
end
|
@@ -3,32 +3,69 @@
|
|
3
3
|
module RuboCop
|
4
4
|
module Cop
|
5
5
|
module Style
|
6
|
-
# This cop checks for uses of double negation (
|
7
|
-
# to a boolean value. As this is both cryptic and usually redundant, it
|
8
|
-
# should be avoided.
|
6
|
+
# This cop checks for uses of double negation (`!!`) to convert something to a boolean value.
|
9
7
|
#
|
10
|
-
#
|
8
|
+
# When using `EnforcedStyle: allowed_in_returns`, allow double nagation in contexts
|
9
|
+
# that use boolean as a return value. When using `EnforcedStyle: forbidden`, double nagation
|
10
|
+
# should be forbidden always.
|
11
11
|
#
|
12
|
+
# @example
|
12
13
|
# # bad
|
13
14
|
# !!something
|
14
15
|
#
|
15
16
|
# # good
|
16
17
|
# !something.nil?
|
17
18
|
#
|
19
|
+
# @example EnforcedStyle: allowed_in_returns (default)
|
20
|
+
# # good
|
21
|
+
# def foo?
|
22
|
+
# !!return_value
|
23
|
+
# end
|
24
|
+
#
|
25
|
+
# @example EnforcedStyle: forbidden
|
26
|
+
# # bad
|
27
|
+
# def foo?
|
28
|
+
# !!return_value
|
29
|
+
# end
|
30
|
+
#
|
18
31
|
# Please, note that when something is a boolean value
|
19
32
|
# !!something and !something.nil? are not the same thing.
|
20
33
|
# As you're unlikely to write code that can accept values of any type
|
21
34
|
# this is rarely a problem in practice.
|
22
35
|
class DoubleNegation < Cop
|
36
|
+
include ConfigurableEnforcedStyle
|
37
|
+
|
23
38
|
MSG = 'Avoid the use of double negation (`!!`).'
|
24
39
|
|
25
40
|
def_node_matcher :double_negative?, '(send (send _ :!) :!)'
|
26
41
|
|
27
42
|
def on_send(node)
|
28
43
|
return unless double_negative?(node) && node.prefix_bang?
|
44
|
+
return if style == :allowed_in_returns && allowed_in_returns?(node)
|
29
45
|
|
30
46
|
add_offense(node, location: :selector)
|
31
47
|
end
|
48
|
+
|
49
|
+
private
|
50
|
+
|
51
|
+
def allowed_in_returns?(node)
|
52
|
+
node.parent&.return_type? || end_of_method_definition?(node)
|
53
|
+
end
|
54
|
+
|
55
|
+
def end_of_method_definition?(node)
|
56
|
+
return false unless (def_node = find_def_node_from_ascendant(node))
|
57
|
+
|
58
|
+
last_child = def_node.child_nodes.last
|
59
|
+
|
60
|
+
last_child.last_line == node.last_line
|
61
|
+
end
|
62
|
+
|
63
|
+
def find_def_node_from_ascendant(node)
|
64
|
+
return unless (parent = node.parent)
|
65
|
+
return parent if parent.def_type? || parent.defs_type?
|
66
|
+
|
67
|
+
find_def_node_from_ascendant(node.parent)
|
68
|
+
end
|
32
69
|
end
|
33
70
|
end
|
34
71
|
end
|
@@ -68,9 +68,7 @@ module RuboCop
|
|
68
68
|
|
69
69
|
def first_argument_unparenthesized?(node)
|
70
70
|
parent = node.parent
|
71
|
-
unless parent && %i[send super zsuper].include?(parent.type)
|
72
|
-
return false
|
73
|
-
end
|
71
|
+
return false unless parent && %i[send super zsuper].include?(parent.type)
|
74
72
|
|
75
73
|
node.object_id == parent.arguments.first.object_id &&
|
76
74
|
!parentheses?(node.parent)
|
@@ -149,9 +149,7 @@ module RuboCop
|
|
149
149
|
end
|
150
150
|
|
151
151
|
next_token = processed_source.tokens[token_number]
|
152
|
-
if next_token && next_token.text =~ Encoding::ENCODING_PATTERN
|
153
|
-
token = next_token
|
154
|
-
end
|
152
|
+
token = next_token if next_token && next_token.text =~ Encoding::ENCODING_PATTERN
|
155
153
|
|
156
154
|
token
|
157
155
|
end
|
@@ -216,7 +214,7 @@ module RuboCop
|
|
216
214
|
if comment
|
217
215
|
corrector.insert_after(line_range(comment.line), following_comment)
|
218
216
|
else
|
219
|
-
corrector.insert_before(
|
217
|
+
corrector.insert_before(processed_source.buffer.source_range, preceding_comment)
|
220
218
|
end
|
221
219
|
end
|
222
220
|
|
@@ -168,11 +168,7 @@ module RuboCop
|
|
168
168
|
end
|
169
169
|
|
170
170
|
def autocorrect_ruby19(corrector, pair_node)
|
171
|
-
|
172
|
-
op = pair_node.loc.operator
|
173
|
-
|
174
|
-
range = key.join(op)
|
175
|
-
range = range_with_surrounding_space(range: range, side: :right)
|
171
|
+
range = range_for_autocorrect_ruby19(pair_node)
|
176
172
|
|
177
173
|
space = argument_without_space?(pair_node.parent) ? ' ' : ''
|
178
174
|
|
@@ -180,6 +176,17 @@ module RuboCop
|
|
180
176
|
range,
|
181
177
|
range.source.sub(/^:(.*\S)\s*=>\s*$/, space.to_s + '\1: ')
|
182
178
|
)
|
179
|
+
|
180
|
+
hash_node = pair_node.parent
|
181
|
+
corrector.wrap(hash_node, '{', '}') if hash_node.parent&.return_type? && !hash_node.braces?
|
182
|
+
end
|
183
|
+
|
184
|
+
def range_for_autocorrect_ruby19(pair_node)
|
185
|
+
key = pair_node.key.source_range
|
186
|
+
operator = pair_node.loc.operator
|
187
|
+
|
188
|
+
range = key.join(operator)
|
189
|
+
range_with_surrounding_space(range: range, side: :right)
|
183
190
|
end
|
184
191
|
|
185
192
|
def argument_without_space?(node)
|
@@ -22,9 +22,7 @@ module RuboCop
|
|
22
22
|
lambda do |corrector|
|
23
23
|
corrector.replace(args_begin(node), '(')
|
24
24
|
|
25
|
-
unless args_parenthesized?(node)
|
26
|
-
corrector.insert_after(args_end(node), ')')
|
27
|
-
end
|
25
|
+
corrector.insert_after(args_end(node), ')') unless args_parenthesized?(node)
|
28
26
|
end
|
29
27
|
end
|
30
28
|
|
@@ -41,9 +41,7 @@ module RuboCop
|
|
41
41
|
|
42
42
|
def same_name_assignment?(node)
|
43
43
|
any_assignment?(node) do |asgn_node|
|
44
|
-
if asgn_node.masgn_type?
|
45
|
-
next variable_in_mass_assignment?(node.method_name, asgn_node)
|
46
|
-
end
|
44
|
+
next variable_in_mass_assignment?(node.method_name, asgn_node) if asgn_node.masgn_type?
|
47
45
|
|
48
46
|
asgn_node.loc.name.source == node.method_name.to_s
|
49
47
|
end
|
@@ -49,13 +49,9 @@ module RuboCop
|
|
49
49
|
def replacement(node)
|
50
50
|
return to_ternary(node) unless node.parent
|
51
51
|
|
52
|
-
if %i[and or].include?(node.parent.type)
|
53
|
-
return "(#{to_ternary(node)})"
|
54
|
-
end
|
52
|
+
return "(#{to_ternary(node)})" if %i[and or].include?(node.parent.type)
|
55
53
|
|
56
|
-
if node.parent.send_type? && node.parent.operator_method?
|
57
|
-
return "(#{to_ternary(node)})"
|
58
|
-
end
|
54
|
+
return "(#{to_ternary(node)})" if node.parent.send_type? && node.parent.operator_method?
|
59
55
|
|
60
56
|
to_ternary(node)
|
61
57
|
end
|
@@ -93,12 +93,8 @@ module RuboCop
|
|
93
93
|
|
94
94
|
def check(begin_node)
|
95
95
|
node = begin_node.children.first
|
96
|
-
if keyword_with_redundant_parentheses?(node)
|
97
|
-
|
98
|
-
end
|
99
|
-
if disallowed_literal?(begin_node, node)
|
100
|
-
return offense(begin_node, 'a literal')
|
101
|
-
end
|
96
|
+
return offense(begin_node, 'a keyword') if keyword_with_redundant_parentheses?(node)
|
97
|
+
return offense(begin_node, 'a literal') if disallowed_literal?(begin_node, node)
|
102
98
|
return offense(begin_node, 'a variable') if node.variable?
|
103
99
|
return offense(begin_node, 'a constant') if node.const_type?
|
104
100
|
|