rubocop 1.5.1 → 1.5.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/rubocop/cli/command/suggest_extensions.rb +35 -7
- data/lib/rubocop/cop/layout/heredoc_argument_closing_parenthesis.rb +12 -0
- data/lib/rubocop/cop/layout/multiline_method_call_indentation.rb +7 -3
- data/lib/rubocop/cop/lint/shadowing_outer_local_variable.rb +13 -0
- data/lib/rubocop/cop/style/redundant_regexp_escape.rb +24 -8
- data/lib/rubocop/cop/style/sole_nested_conditional.rb +14 -4
- data/lib/rubocop/cop/style/string_concatenation.rb +7 -1
- data/lib/rubocop/ext/regexp_node.rb +31 -9
- data/lib/rubocop/ext/regexp_parser.rb +21 -3
- data/lib/rubocop/version.rb +1 -1
- metadata +16 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 77baac77fdf5ed6293449d9653e1caeadc94b18e49bbd5115176c3681b8ed752
|
4
|
+
data.tar.gz: 677ced7d3409d54555aaba855aec07fac0717bdb100eef4ea0196d68688247d6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d083c6f78d892e14780bc3ab2cadf4b4208b87ab3dae357df39cc5dcbd9c2a18ff416795cd73a39c0d743fd07923ccbd092b916be3e738114558aa2b37f724cc
|
7
|
+
data.tar.gz: 6a5e0502cfbc9c0c5c11f075b89a91ea7ae4ec1b70134fbe6930caca9f7959282dea23f9358db291cca2a4e1fa72e830a1717c1c845528024eb89d23e6368379
|
@@ -11,13 +11,37 @@ module RuboCop
|
|
11
11
|
|
12
12
|
self.command_name = :suggest_extensions
|
13
13
|
|
14
|
-
|
15
|
-
|
14
|
+
class << self
|
15
|
+
# Gems that the current bundle depends on
|
16
|
+
# Suggestions are only made for gems that are 1st party dependencies
|
17
|
+
def dependent_gems
|
18
|
+
bundler do |gems|
|
19
|
+
gems.dependencies.map(&:name)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
# All installed gems in the current bundle
|
24
|
+
# If a suggestion is installed but not depended on, it still should not
|
25
|
+
# be suggested.
|
26
|
+
def installed_gems
|
27
|
+
bundler do
|
28
|
+
# Load specs from the lockfile without trying to resolve them
|
29
|
+
return [] unless Bundler.default_lockfile
|
30
|
+
|
31
|
+
lockfile = Bundler.read_file(Bundler.default_lockfile)
|
32
|
+
Bundler::LockfileParser.new(lockfile).specs.map(&:name)
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
private
|
16
37
|
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
38
|
+
def bundler
|
39
|
+
return [] unless defined?(Bundler)
|
40
|
+
|
41
|
+
yield Bundler.load
|
42
|
+
rescue Bundler::BundlerError
|
43
|
+
[]
|
44
|
+
end
|
21
45
|
end
|
22
46
|
|
23
47
|
def run
|
@@ -62,7 +86,7 @@ module RuboCop
|
|
62
86
|
|
63
87
|
@extensions ||= begin
|
64
88
|
extensions = @config_store.for_pwd.for_all_cops['SuggestExtensions'] || {}
|
65
|
-
extensions.select { |_, v| (Array(v) & dependent_gems).any? }.keys -
|
89
|
+
extensions.select { |_, v| (Array(v) & dependent_gems).any? }.keys - installed_gems
|
66
90
|
end
|
67
91
|
end
|
68
92
|
|
@@ -74,6 +98,10 @@ module RuboCop
|
|
74
98
|
def dependent_gems
|
75
99
|
@dependent_gems ||= self.class.dependent_gems
|
76
100
|
end
|
101
|
+
|
102
|
+
def installed_gems
|
103
|
+
@installed_gems ||= self.class.installed_gems
|
104
|
+
end
|
77
105
|
end
|
78
106
|
end
|
79
107
|
end
|
@@ -69,6 +69,7 @@ module RuboCop
|
|
69
69
|
return unless outermost_send
|
70
70
|
return unless outermost_send.loc.end
|
71
71
|
return unless heredoc_arg.first_line != outermost_send.loc.end.line
|
72
|
+
return if subsequent_closing_parentheses_in_same_line?(outermost_send)
|
72
73
|
|
73
74
|
add_offense(outermost_send.loc.end) do |corrector|
|
74
75
|
autocorrect(corrector, outermost_send)
|
@@ -160,6 +161,17 @@ module RuboCop
|
|
160
161
|
|
161
162
|
# Closing parenthesis helpers.
|
162
163
|
|
164
|
+
def subsequent_closing_parentheses_in_same_line?(outermost_send)
|
165
|
+
last_arg_of_outer_send = outermost_send.last_argument
|
166
|
+
return false unless last_arg_of_outer_send&.loc.respond_to?(:end) &&
|
167
|
+
(end_of_last_arg_of_outer_send = last_arg_of_outer_send.loc.end)
|
168
|
+
|
169
|
+
end_of_outer_send = outermost_send.loc.end
|
170
|
+
|
171
|
+
end_of_outer_send.line == end_of_last_arg_of_outer_send.line &&
|
172
|
+
end_of_outer_send.column == end_of_last_arg_of_outer_send.column + 1
|
173
|
+
end
|
174
|
+
|
163
175
|
def fix_closing_parenthesis(node, corrector)
|
164
176
|
remove_incorrect_closing_paren(node, corrector)
|
165
177
|
add_correct_closing_paren(node, corrector)
|
@@ -77,7 +77,7 @@ module RuboCop
|
|
77
77
|
|
78
78
|
@base = alignment_base(node, rhs, given_style)
|
79
79
|
correct_column = if @base
|
80
|
-
@base.column + extra_indentation(given_style)
|
80
|
+
@base.column + extra_indentation(given_style, node.parent)
|
81
81
|
else
|
82
82
|
indentation(lhs) + correct_indentation(node)
|
83
83
|
end
|
@@ -85,9 +85,13 @@ module RuboCop
|
|
85
85
|
rhs if @column_delta.nonzero?
|
86
86
|
end
|
87
87
|
|
88
|
-
def extra_indentation(given_style)
|
88
|
+
def extra_indentation(given_style, parent)
|
89
89
|
if given_style == :indented_relative_to_receiver
|
90
|
-
|
90
|
+
if parent && (parent.splat_type? || parent.kwsplat_type?)
|
91
|
+
configured_indentation_width - parent.loc.operator.length
|
92
|
+
else
|
93
|
+
configured_indentation_width
|
94
|
+
end
|
91
95
|
else
|
92
96
|
0
|
93
97
|
end
|
@@ -8,6 +8,14 @@ module RuboCop
|
|
8
8
|
# given by `ruby -cw` prior to Ruby 2.6:
|
9
9
|
# "shadowing outer local variable - foo".
|
10
10
|
#
|
11
|
+
# NOTE: Shadowing of variables in block passed to `Ractor.new` is allowed
|
12
|
+
# because `Ractor` should not access outer variables.
|
13
|
+
# eg. following syle is encouraged:
|
14
|
+
#
|
15
|
+
# worker_id, pipe = env
|
16
|
+
# Ractor.new(worker_id, pipe) do |worker_id, pipe|
|
17
|
+
# end
|
18
|
+
#
|
11
19
|
# @example
|
12
20
|
#
|
13
21
|
# # bad
|
@@ -34,12 +42,17 @@ module RuboCop
|
|
34
42
|
class ShadowingOuterLocalVariable < Base
|
35
43
|
MSG = 'Shadowing outer local variable - `%<variable>s`.'
|
36
44
|
|
45
|
+
def_node_matcher :ractor_block?, <<~PATTERN
|
46
|
+
(block (send (const nil? :Ractor) :new ...) ...)
|
47
|
+
PATTERN
|
48
|
+
|
37
49
|
def self.joining_forces
|
38
50
|
VariableForce
|
39
51
|
end
|
40
52
|
|
41
53
|
def before_declaring_variable(variable, variable_table)
|
42
54
|
return if variable.should_be_unused?
|
55
|
+
return if ractor_block?(variable.scope.node)
|
43
56
|
|
44
57
|
outer_local_variable = variable_table.find_variable(variable.name)
|
45
58
|
return unless outer_local_variable
|
@@ -80,14 +80,30 @@ module RuboCop
|
|
80
80
|
delimiters.include?(char)
|
81
81
|
end
|
82
82
|
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
83
|
+
if Gem::Version.new(Regexp::Parser::VERSION) >= Gem::Version.new('2.0')
|
84
|
+
def each_escape(node)
|
85
|
+
node.parsed_tree&.traverse&.reduce(0) do |char_class_depth, (event, expr)|
|
86
|
+
yield(expr.text[1], expr.ts, !char_class_depth.zero?) if expr.type == :escape
|
87
|
+
|
88
|
+
if expr.type == :set
|
89
|
+
char_class_depth + (event == :enter ? 1 : -1)
|
90
|
+
else
|
91
|
+
char_class_depth
|
92
|
+
end
|
93
|
+
end
|
94
|
+
end
|
95
|
+
# Please remove this `else` branch when support for regexp_parser 1.8 will be dropped.
|
96
|
+
# It's for compatibility with regexp_arser 1.8 and will never be maintained.
|
97
|
+
else
|
98
|
+
def each_escape(node)
|
99
|
+
node.parsed_tree&.traverse&.reduce(0) do |char_class_depth, (event, expr)|
|
100
|
+
yield(expr.text[1], expr.start_index, !char_class_depth.zero?) if expr.type == :escape
|
101
|
+
|
102
|
+
if expr.type == :set
|
103
|
+
char_class_depth + (event == :enter ? 1 : -1)
|
104
|
+
else
|
105
|
+
char_class_depth
|
106
|
+
end
|
91
107
|
end
|
92
108
|
end
|
93
109
|
end
|
@@ -68,6 +68,8 @@ module RuboCop
|
|
68
68
|
corrector.insert_before(node.condition, '!')
|
69
69
|
end
|
70
70
|
|
71
|
+
corrector.wrap(node.condition, '(', ')') if node.condition.or_type?
|
72
|
+
|
71
73
|
and_operator = if_branch.unless? ? ' && !' : ' && '
|
72
74
|
if if_branch.modifier_form?
|
73
75
|
correct_for_gurad_condition_style(corrector, node, if_branch, and_operator)
|
@@ -79,11 +81,10 @@ module RuboCop
|
|
79
81
|
end
|
80
82
|
|
81
83
|
def correct_for_gurad_condition_style(corrector, node, if_branch, and_operator)
|
82
|
-
|
84
|
+
condition = if_branch.condition
|
85
|
+
corrector.insert_after(node.condition, replacement_condition(and_operator, condition))
|
83
86
|
|
84
|
-
range = range_between(
|
85
|
-
if_branch.loc.keyword.begin_pos, if_branch.condition.source_range.end_pos
|
86
|
-
)
|
87
|
+
range = range_between(if_branch.loc.keyword.begin_pos, condition.source_range.end_pos)
|
87
88
|
corrector.remove(range_with_surrounding_space(range: range, newlines: false))
|
88
89
|
corrector.remove(if_branch.loc.keyword)
|
89
90
|
end
|
@@ -94,6 +95,7 @@ module RuboCop
|
|
94
95
|
)
|
95
96
|
corrector.replace(range, and_operator)
|
96
97
|
corrector.remove(range_by_whole_lines(node.loc.end, include_final_newline: true))
|
98
|
+
corrector.wrap(if_branch.condition, '(', ')') if if_branch.condition.or_type?
|
97
99
|
end
|
98
100
|
|
99
101
|
def correct_for_comment(corrector, node, if_branch)
|
@@ -103,6 +105,14 @@ module RuboCop
|
|
103
105
|
corrector.insert_before(node.loc.keyword, comment_text) unless comments.empty?
|
104
106
|
end
|
105
107
|
|
108
|
+
def replacement_condition(and_operator, condition)
|
109
|
+
if condition.or_type?
|
110
|
+
"#{and_operator}(#{condition.source})"
|
111
|
+
else
|
112
|
+
"#{and_operator}#{condition.source}"
|
113
|
+
end
|
114
|
+
end
|
115
|
+
|
106
116
|
def allow_modifier?
|
107
117
|
cop_config['AllowModifier']
|
108
118
|
end
|
@@ -106,7 +106,13 @@ module RuboCop
|
|
106
106
|
end
|
107
107
|
end
|
108
108
|
|
109
|
-
"\"#{interpolated_parts.join}\""
|
109
|
+
"\"#{handle_quotes(interpolated_parts).join}\""
|
110
|
+
end
|
111
|
+
|
112
|
+
def handle_quotes(parts)
|
113
|
+
parts.map do |part|
|
114
|
+
part == '"' ? '\"' : part
|
115
|
+
end
|
110
116
|
end
|
111
117
|
|
112
118
|
def single_quoted?(str_node)
|
@@ -15,17 +15,39 @@ module RuboCop
|
|
15
15
|
# see `ext/regexp_parser`.
|
16
16
|
attr_reader :parsed_tree
|
17
17
|
|
18
|
-
|
19
|
-
|
18
|
+
if Gem::Version.new(Regexp::Parser::VERSION) >= Gem::Version.new('2.0')
|
19
|
+
def assign_properties(*)
|
20
|
+
super
|
20
21
|
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
22
|
+
str = with_interpolations_blanked
|
23
|
+
@parsed_tree = begin
|
24
|
+
Regexp::Parser.parse(str, options: options)
|
25
|
+
rescue StandardError
|
26
|
+
nil
|
27
|
+
end
|
28
|
+
origin = loc.begin.end
|
29
|
+
@parsed_tree&.each_expression(true) { |e| e.origin = origin }
|
30
|
+
end
|
31
|
+
# Please remove this `else` branch when support for regexp_parser 1.8 will be dropped.
|
32
|
+
# It's for compatibility with regexp_arser 1.8 and will never be maintained.
|
33
|
+
else
|
34
|
+
def assign_properties(*)
|
35
|
+
super
|
36
|
+
|
37
|
+
str = with_interpolations_blanked
|
38
|
+
begin
|
39
|
+
@parsed_tree = Regexp::Parser.parse(str, options: options)
|
40
|
+
rescue StandardError
|
41
|
+
@parsed_tree = nil
|
42
|
+
else
|
43
|
+
origin = loc.begin.end
|
44
|
+
source = @parsed_tree.to_s
|
45
|
+
@parsed_tree.each_expression(true) do |e|
|
46
|
+
e.origin = origin
|
47
|
+
e.source = source
|
48
|
+
end
|
49
|
+
end
|
26
50
|
end
|
27
|
-
origin = loc.begin.end
|
28
|
-
@parsed_tree&.each_expression(true) { |e| e.origin = origin }
|
29
51
|
end
|
30
52
|
|
31
53
|
def each_capture(named: ANY)
|
@@ -22,9 +22,27 @@ module RuboCop
|
|
22
22
|
module Base
|
23
23
|
attr_accessor :origin
|
24
24
|
|
25
|
-
|
26
|
-
|
27
|
-
|
25
|
+
if Gem::Version.new(Regexp::Parser::VERSION) >= Gem::Version.new('2.0')
|
26
|
+
# Shortcut to `loc.expression`
|
27
|
+
def expression
|
28
|
+
@expression ||= origin.adjust(begin_pos: ts, end_pos: ts + full_length)
|
29
|
+
end
|
30
|
+
# Please remove this `else` branch when support for regexp_parser 1.8 will be dropped.
|
31
|
+
# It's for compatibility with regexp_arser 1.8 and will never be maintained.
|
32
|
+
else
|
33
|
+
attr_accessor :source
|
34
|
+
|
35
|
+
def start_index
|
36
|
+
# ts is a byte index; convert it to a character index
|
37
|
+
@start_index ||= source.byteslice(0, ts).length
|
38
|
+
end
|
39
|
+
|
40
|
+
# Shortcut to `loc.expression`
|
41
|
+
def expression
|
42
|
+
@expression ||= begin
|
43
|
+
origin.adjust(begin_pos: start_index, end_pos: start_index + full_length)
|
44
|
+
end
|
45
|
+
end
|
28
46
|
end
|
29
47
|
|
30
48
|
# @returns a location map like `parser` does, with:
|
data/lib/rubocop/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rubocop
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.5.
|
4
|
+
version: 1.5.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Bozhidar Batsov
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: exe
|
12
12
|
cert_chain: []
|
13
|
-
date: 2020-12-
|
13
|
+
date: 2020-12-04 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: parallel
|
@@ -66,14 +66,20 @@ dependencies:
|
|
66
66
|
requirements:
|
67
67
|
- - ">="
|
68
68
|
- !ruby/object:Gem::Version
|
69
|
-
version: '
|
69
|
+
version: '1.8'
|
70
|
+
- - "<"
|
71
|
+
- !ruby/object:Gem::Version
|
72
|
+
version: '3.0'
|
70
73
|
type: :runtime
|
71
74
|
prerelease: false
|
72
75
|
version_requirements: !ruby/object:Gem::Requirement
|
73
76
|
requirements:
|
74
77
|
- - ">="
|
75
78
|
- !ruby/object:Gem::Version
|
76
|
-
version: '
|
79
|
+
version: '1.8'
|
80
|
+
- - "<"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '3.0'
|
77
83
|
- !ruby/object:Gem::Dependency
|
78
84
|
name: rexml
|
79
85
|
requirement: !ruby/object:Gem::Requirement
|
@@ -95,6 +101,9 @@ dependencies:
|
|
95
101
|
- - ">="
|
96
102
|
- !ruby/object:Gem::Version
|
97
103
|
version: 1.2.0
|
104
|
+
- - "<"
|
105
|
+
- !ruby/object:Gem::Version
|
106
|
+
version: '2.0'
|
98
107
|
type: :runtime
|
99
108
|
prerelease: false
|
100
109
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -102,6 +111,9 @@ dependencies:
|
|
102
111
|
- - ">="
|
103
112
|
- !ruby/object:Gem::Version
|
104
113
|
version: 1.2.0
|
114
|
+
- - "<"
|
115
|
+
- !ruby/object:Gem::Version
|
116
|
+
version: '2.0'
|
105
117
|
- !ruby/object:Gem::Dependency
|
106
118
|
name: ruby-progressbar
|
107
119
|
requirement: !ruby/object:Gem::Requirement
|