rubocop 0.59.0 → 0.59.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 -2
- data/lib/rubocop/ast/node/mixin/method_dispatch_node.rb +20 -1
- data/lib/rubocop/ast/node/send_node.rb +0 -15
- data/lib/rubocop/config.rb +5 -0
- data/lib/rubocop/cop/layout/empty_line_after_guard_clause.rb +13 -7
- data/lib/rubocop/cop/lint/unreachable_code.rb +1 -1
- data/lib/rubocop/cop/naming/binary_operator_parameter_name.rb +1 -1
- data/lib/rubocop/cop/naming/file_name.rb +10 -1
- data/lib/rubocop/cop/rails/find_each.rb +1 -1
- data/lib/rubocop/cop/style/empty_block_parameter.rb +1 -1
- data/lib/rubocop/cop/style/empty_case_condition.rb +10 -3
- data/lib/rubocop/cop/style/empty_lambda_parameter.rb +1 -1
- data/lib/rubocop/cop/style/multiline_method_signature.rb +3 -7
- data/lib/rubocop/cop/style/redundant_begin.rb +1 -1
- data/lib/rubocop/cop/style/stabby_lambda_parentheses.rb +5 -5
- data/lib/rubocop/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c194b5622ecc91385098a2b68a32fefb80dfe3c1
|
4
|
+
data.tar.gz: 6b77f223ef06685ee4af7543faed16456c38d7cb
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 14a31079c85a1f77781219df27ffaeb0756ef006ca737c92a4690ff50f3cff68e407520b3d389bb03cdba4853eddcb07fa375955478547d4bfd219f8dc1e84dc
|
7
|
+
data.tar.gz: cee68c85b7430c9fb32e11206d9e8b8b1f87dd3cc29b0a878daf62b91e26cbd54793e4ead915b4894e1082c5f6d7dcd8584bf5f0a96e4123df32009ca11ff438
|
data/README.md
CHANGED
@@ -1,5 +1,4 @@
|
|
1
1
|
[](http://badge.fury.io/rb/rubocop)
|
2
|
-
[](https://travis-ci.org/rubocop-hq/rubocop)
|
3
2
|
[](https://circleci.com/gh/rubocop-hq/rubocop/tree/master)
|
4
3
|
[](https://ci.appveyor.com/project/bbatsov/rubocop)
|
5
4
|
[](https://codeclimate.com/github/bbatsov/rubocop)
|
@@ -54,7 +53,7 @@ haven't reached version 1.0 yet). To prevent an unwanted RuboCop update you
|
|
54
53
|
might want to use a conservative version locking in your `Gemfile`:
|
55
54
|
|
56
55
|
```rb
|
57
|
-
gem 'rubocop', '~> 0.59.
|
56
|
+
gem 'rubocop', '~> 0.59.1', require: false
|
58
57
|
```
|
59
58
|
|
60
59
|
## Quickstart
|
@@ -3,7 +3,7 @@
|
|
3
3
|
module RuboCop
|
4
4
|
module AST
|
5
5
|
# Common functionality for nodes that are a kind of method dispatch:
|
6
|
-
# `send`, `csend`, `super`, `zsuper`, `yield`
|
6
|
+
# `send`, `csend`, `super`, `zsuper`, `yield`, `defined?`
|
7
7
|
module MethodDispatchNode
|
8
8
|
extend NodePattern::Macros
|
9
9
|
include MethodIdentifierPredicates
|
@@ -163,6 +163,25 @@ module RuboCop
|
|
163
163
|
[self, *each_descendant(:send)].any?(&:adjacent_def_modifier?)
|
164
164
|
end
|
165
165
|
|
166
|
+
# Checks whether this is a lambda. Some versions of parser parses
|
167
|
+
# non-literal lambdas as a method send.
|
168
|
+
#
|
169
|
+
# @return [Boolean] whether this method is a lambda
|
170
|
+
def lambda?
|
171
|
+
block_literal? && command?(:lambda)
|
172
|
+
end
|
173
|
+
|
174
|
+
# Checks whether this is a lambda literal (stabby lambda.)
|
175
|
+
#
|
176
|
+
# @example
|
177
|
+
#
|
178
|
+
# -> (foo) { bar }
|
179
|
+
#
|
180
|
+
# @return [Boolean] whether this method is a lambda literal
|
181
|
+
def lambda_literal?
|
182
|
+
block_literal? && loc.expression && loc.expression.source == '->'
|
183
|
+
end
|
184
|
+
|
166
185
|
private
|
167
186
|
|
168
187
|
def_node_matcher :macro_scope?, <<-PATTERN
|
@@ -8,21 +8,6 @@ module RuboCop
|
|
8
8
|
class SendNode < Node
|
9
9
|
include ParameterizedNode
|
10
10
|
include MethodDispatchNode
|
11
|
-
|
12
|
-
# Checks whether this is a lambda. Some versions of parser parses
|
13
|
-
# non-literal lambdas as a method send.
|
14
|
-
#
|
15
|
-
# @return [Boolean] whether this method is a lambda
|
16
|
-
def lambda?
|
17
|
-
block_literal? && method?(:lambda)
|
18
|
-
end
|
19
|
-
|
20
|
-
# Checks whether this is a stabby lambda. e.g. `-> () {}`
|
21
|
-
#
|
22
|
-
# @return [Boolean] whether this method is a stabby lambda
|
23
|
-
def stabby_lambda?
|
24
|
-
loc.selector && loc.selector.source == '->'
|
25
|
-
end
|
26
11
|
end
|
27
12
|
end
|
28
13
|
end
|
data/lib/rubocop/config.rb
CHANGED
@@ -383,6 +383,11 @@ module RuboCop
|
|
383
383
|
end
|
384
384
|
|
385
385
|
def allowed_camel_case_file?(file)
|
386
|
+
# Gemspecs are allowed to have dashes because that fits with bundler best
|
387
|
+
# practices in the case when the gem is nested under a namespace (e.g.,
|
388
|
+
# `bundler-console` conveys `Bundler::Console`).
|
389
|
+
return true if File.extname(file) == '.gemspec'
|
390
|
+
|
386
391
|
file_to_include?(file) do |pattern, relative_path, absolute_path|
|
387
392
|
pattern.to_s =~ /[A-Z]/ &&
|
388
393
|
(match_path?(pattern, relative_path) ||
|
@@ -47,7 +47,10 @@ module RuboCop
|
|
47
47
|
if last_argument_is_heredoc?(node)
|
48
48
|
heredoc_node = last_argument(node)
|
49
49
|
|
50
|
-
|
50
|
+
heredoc_body = heredoc_node.loc.heredoc_body
|
51
|
+
num_of_heredoc_lines =
|
52
|
+
heredoc_body.last_line - heredoc_body.first_line
|
53
|
+
|
51
54
|
line = node.last_line + num_of_heredoc_lines + END_OF_HEREDOC_LINE
|
52
55
|
|
53
56
|
return if next_line_empty?(line)
|
@@ -62,7 +65,12 @@ module RuboCop
|
|
62
65
|
|
63
66
|
def autocorrect(node)
|
64
67
|
lambda do |corrector|
|
65
|
-
node_range =
|
68
|
+
node_range = if node.respond_to?(:heredoc?) && node.heredoc?
|
69
|
+
range_by_whole_lines(node.loc.heredoc_body)
|
70
|
+
else
|
71
|
+
range_by_whole_lines(node.source_range)
|
72
|
+
end
|
73
|
+
|
66
74
|
corrector.insert_after(node_range, "\n")
|
67
75
|
end
|
68
76
|
end
|
@@ -106,19 +114,17 @@ module RuboCop
|
|
106
114
|
end
|
107
115
|
|
108
116
|
def last_argument_is_heredoc?(node)
|
109
|
-
last_children = node.
|
117
|
+
last_children = node.if_branch
|
110
118
|
|
111
119
|
return false unless last_children && last_children.send_type?
|
112
120
|
|
113
121
|
last_argument = last_argument(node)
|
114
122
|
|
115
|
-
last_argument &&
|
116
|
-
(last_argument.str_type? || last_argument.dstr_type?) &&
|
117
|
-
last_argument.heredoc?
|
123
|
+
last_argument.respond_to?(:heredoc?) && last_argument.heredoc?
|
118
124
|
end
|
119
125
|
|
120
126
|
def last_argument(node)
|
121
|
-
node.children.last
|
127
|
+
node.if_branch.children.last
|
122
128
|
end
|
123
129
|
end
|
124
130
|
end
|
@@ -18,7 +18,7 @@ module RuboCop
|
|
18
18
|
'name its argument `other`.'.freeze
|
19
19
|
|
20
20
|
OP_LIKE_METHODS = %i[eql? equal?].freeze
|
21
|
-
BLACKLISTED = %i[+@ -@ [] []= << `].freeze
|
21
|
+
BLACKLISTED = %i[+@ -@ [] []= << === `].freeze
|
22
22
|
|
23
23
|
def_node_matcher :op_method_candidate?, <<-PATTERN
|
24
24
|
(def [#op_method? $_] (args $(arg [!:other !:_other])) _)
|
@@ -9,6 +9,11 @@ module RuboCop
|
|
9
9
|
# names. Ruby scripts (i.e. source files with a shebang in the
|
10
10
|
# first line) are ignored.
|
11
11
|
#
|
12
|
+
# The cop also ignores `.gemspec` files, because Bundler
|
13
|
+
# recommends using dashes to separate namespaces in nested gems
|
14
|
+
# (i.e. `bundler-console` becomes `Bundler::Console`). As such, the
|
15
|
+
# gemspec is supposed to be named `bundler-console.gemspec`.
|
16
|
+
#
|
12
17
|
# @example
|
13
18
|
# # bad
|
14
19
|
# lib/layoutManager.rb
|
@@ -91,7 +96,11 @@ module RuboCop
|
|
91
96
|
end
|
92
97
|
|
93
98
|
def filename_good?(basename)
|
99
|
+
basename = basename.sub(/^\./, '')
|
94
100
|
basename = basename.sub(/\.[^\.]+$/, '')
|
101
|
+
# special handling for Action Pack Variants file names like
|
102
|
+
# some_file.xlsx+mobile.axlsx
|
103
|
+
basename = basename.sub('+', '_')
|
95
104
|
basename =~ (regex || SNAKE_CASE)
|
96
105
|
end
|
97
106
|
|
@@ -164,7 +173,7 @@ module RuboCop
|
|
164
173
|
# To convert a pathname to a Ruby namespace, we need a starting point
|
165
174
|
# But RC can be run from any working directory, and can check any path
|
166
175
|
# We can't assume that the working directory, or any other, is the
|
167
|
-
# "starting point" to build a namespace
|
176
|
+
# "starting point" to build a namespace.
|
168
177
|
start = %w[lib spec test src]
|
169
178
|
start_index = nil
|
170
179
|
|
@@ -67,9 +67,8 @@ module RuboCop
|
|
67
67
|
private
|
68
68
|
|
69
69
|
def correct_case_when(corrector, case_node, when_nodes)
|
70
|
-
|
71
|
-
|
72
|
-
corrector.replace(case_range, 'if')
|
70
|
+
remove_case_node(corrector, case_node)
|
71
|
+
corrector.replace(when_nodes.first.loc.keyword, 'if')
|
73
72
|
|
74
73
|
when_nodes[1..-1].each do |when_node|
|
75
74
|
corrector.replace(when_node.loc.keyword, 'elsif')
|
@@ -88,6 +87,14 @@ module RuboCop
|
|
88
87
|
corrector.replace(range, conditions.map(&:source).join(' || '))
|
89
88
|
end
|
90
89
|
end
|
90
|
+
|
91
|
+
def remove_case_node(corrector, case_node)
|
92
|
+
range = range_by_whole_lines(
|
93
|
+
case_node.loc.keyword, include_final_newline: true
|
94
|
+
)
|
95
|
+
|
96
|
+
corrector.remove(range)
|
97
|
+
end
|
91
98
|
end
|
92
99
|
end
|
93
100
|
end
|
@@ -22,6 +22,7 @@ module RuboCop
|
|
22
22
|
MSG = 'Avoid multi-line method signatures.'.freeze
|
23
23
|
|
24
24
|
def on_def(node)
|
25
|
+
return unless node.arguments?
|
25
26
|
return if opening_line(node) == closing_line(node)
|
26
27
|
return if correction_exceeds_max_line_length?(node)
|
27
28
|
|
@@ -36,11 +37,7 @@ module RuboCop
|
|
36
37
|
end
|
37
38
|
|
38
39
|
def closing_line(node)
|
39
|
-
|
40
|
-
node.arguments.last_line
|
41
|
-
else
|
42
|
-
node.first_line
|
43
|
-
end
|
40
|
+
node.arguments.last_line
|
44
41
|
end
|
45
42
|
|
46
43
|
def correction_exceeds_max_line_length?(node)
|
@@ -52,8 +49,7 @@ module RuboCop
|
|
52
49
|
end
|
53
50
|
|
54
51
|
def definition_width(node)
|
55
|
-
node.
|
56
|
-
node.loc.end.source.length
|
52
|
+
node.source_range.begin.join(node.arguments.source_range.end).length
|
57
53
|
end
|
58
54
|
|
59
55
|
def max_line_length
|
@@ -30,7 +30,7 @@ module RuboCop
|
|
30
30
|
return unless redundant_parentheses?(node) ||
|
31
31
|
missing_parentheses?(node)
|
32
32
|
|
33
|
-
add_offense(node.
|
33
|
+
add_offense(node.block_node.arguments)
|
34
34
|
end
|
35
35
|
|
36
36
|
def autocorrect(node)
|
@@ -57,7 +57,7 @@ module RuboCop
|
|
57
57
|
|
58
58
|
def missing_parentheses_corrector(node)
|
59
59
|
lambda do |corrector|
|
60
|
-
args_loc = node.
|
60
|
+
args_loc = node.loc.expression
|
61
61
|
|
62
62
|
corrector.insert_before(args_loc, '(')
|
63
63
|
corrector.insert_after(args_loc, ')')
|
@@ -66,7 +66,7 @@ module RuboCop
|
|
66
66
|
|
67
67
|
def unwanted_parentheses_corrector(node)
|
68
68
|
lambda do |corrector|
|
69
|
-
args_loc = node.
|
69
|
+
args_loc = node.loc
|
70
70
|
|
71
71
|
corrector.replace(args_loc.begin, '')
|
72
72
|
corrector.remove(args_loc.end)
|
@@ -74,11 +74,11 @@ module RuboCop
|
|
74
74
|
end
|
75
75
|
|
76
76
|
def stabby_lambda_with_args?(node)
|
77
|
-
node.
|
77
|
+
node.lambda_literal? && node.block_node.arguments?
|
78
78
|
end
|
79
79
|
|
80
80
|
def parentheses?(node)
|
81
|
-
node.
|
81
|
+
node.block_node.arguments.loc.begin
|
82
82
|
end
|
83
83
|
end
|
84
84
|
end
|
data/lib/rubocop/version.rb
CHANGED
@@ -3,7 +3,7 @@
|
|
3
3
|
module RuboCop
|
4
4
|
# This module holds the RuboCop version information.
|
5
5
|
module Version
|
6
|
-
STRING = '0.59.
|
6
|
+
STRING = '0.59.1'.freeze
|
7
7
|
|
8
8
|
MSG = '%<version>s (using Parser %<parser_version>s, running on ' \
|
9
9
|
'%<ruby_engine>s %<ruby_version>s %<ruby_platform>s)'.freeze
|
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: 0.59.
|
4
|
+
version: 0.59.1
|
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: 2018-09-
|
13
|
+
date: 2018-09-15 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: jaro_winkler
|