rubocop 0.80.1 → 0.81.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 +1 -1
- data/config/default.yml +62 -15
- data/lib/rubocop.rb +4 -1
- data/lib/rubocop/ast/builder.rb +2 -0
- data/lib/rubocop/ast/node.rb +11 -6
- data/lib/rubocop/ast/node/block_node.rb +5 -1
- data/lib/rubocop/ast/node/case_match_node.rb +56 -0
- data/lib/rubocop/ast/traversal.rb +11 -9
- data/lib/rubocop/config_obsoletion.rb +1 -0
- data/lib/rubocop/cop/layout/array_alignment.rb +53 -10
- data/lib/rubocop/cop/layout/block_end_newline.rb +5 -3
- data/lib/rubocop/cop/layout/else_alignment.rb +8 -0
- data/lib/rubocop/cop/layout/multiline_method_call_indentation.rb +1 -1
- data/lib/rubocop/cop/lint/boolean_symbol.rb +12 -0
- data/lib/rubocop/cop/lint/erb_new_arguments.rb +1 -1
- data/lib/rubocop/cop/lint/loop.rb +6 -4
- data/lib/rubocop/cop/lint/nested_method_definition.rb +2 -2
- data/lib/rubocop/cop/lint/raise_exception.rb +39 -0
- data/lib/rubocop/cop/lint/safe_navigation_chain.rb +1 -1
- data/lib/rubocop/cop/lint/struct_new_override.rb +58 -0
- data/lib/rubocop/cop/lint/suppressed_exception.rb +12 -22
- data/lib/rubocop/cop/lint/unused_method_argument.rb +32 -6
- data/lib/rubocop/cop/migration/department_name.rb +22 -9
- data/lib/rubocop/cop/mixin/end_keyword_alignment.rb +6 -1
- data/lib/rubocop/cop/mixin/method_complexity.rb +5 -0
- data/lib/rubocop/cop/naming/method_name.rb +30 -0
- data/lib/rubocop/cop/style/access_modifier_declarations.rb +26 -6
- data/lib/rubocop/cop/style/collection_methods.rb +2 -0
- data/lib/rubocop/cop/style/documentation.rb +43 -5
- data/lib/rubocop/cop/style/end_block.rb +6 -0
- data/lib/rubocop/cop/style/hash_each_methods.rb +2 -0
- data/lib/rubocop/cop/style/hash_transform_keys.rb +6 -2
- data/lib/rubocop/cop/style/hash_transform_values.rb +6 -2
- data/lib/rubocop/cop/style/inverse_methods.rb +1 -1
- data/lib/rubocop/cop/style/lambda.rb +1 -0
- data/lib/rubocop/cop/style/module_function.rb +56 -10
- data/lib/rubocop/cop/style/nested_parenthesized_calls.rb +2 -2
- data/lib/rubocop/cop/style/one_line_conditional.rb +3 -2
- data/lib/rubocop/cop/style/redundant_sort.rb +2 -2
- data/lib/rubocop/cop/style/trailing_comma_in_arguments.rb +34 -0
- data/lib/rubocop/cop/style/trailing_comma_in_array_literal.rb +41 -0
- data/lib/rubocop/cop/style/trailing_comma_in_block_args.rb +85 -0
- data/lib/rubocop/cop/style/trailing_comma_in_hash_literal.rb +44 -0
- data/lib/rubocop/formatter/clang_style_formatter.rb +1 -1
- data/lib/rubocop/formatter/junit_formatter.rb +17 -6
- data/lib/rubocop/formatter/tap_formatter.rb +1 -1
- data/lib/rubocop/processed_source.rb +1 -1
- data/lib/rubocop/version.rb +1 -1
- metadata +8 -5
- data/lib/rubocop/cop/lint/end_in_method.rb +0 -40
@@ -8,10 +8,10 @@ module RuboCop
|
|
8
8
|
#
|
9
9
|
# @example
|
10
10
|
# # good
|
11
|
-
# method1(method2(arg)
|
11
|
+
# method1(method2(arg))
|
12
12
|
#
|
13
13
|
# # bad
|
14
|
-
# method1(method2 arg
|
14
|
+
# method1(method2 arg)
|
15
15
|
class NestedParenthesizedCalls < Cop
|
16
16
|
include RangeHelp
|
17
17
|
|
@@ -91,9 +91,10 @@ module RuboCop
|
|
91
91
|
|
92
92
|
def keyword_with_changed_precedence?(node)
|
93
93
|
return false unless node.keyword?
|
94
|
-
return true if node.prefix_not?
|
94
|
+
return true if node.respond_to?(:prefix_not?) && node.prefix_not?
|
95
95
|
|
96
|
-
node.arguments? &&
|
96
|
+
node.respond_to?(:arguments?) && node.arguments? &&
|
97
|
+
!node.parenthesized_call?
|
97
98
|
end
|
98
99
|
end
|
99
100
|
end
|
@@ -63,9 +63,9 @@ module RuboCop
|
|
63
63
|
(send $(send _ $:sort_by _) ${:last :first})
|
64
64
|
(send $(send _ $:sort_by _) ${:[] :at :slice} {(int 0) (int -1)})
|
65
65
|
|
66
|
-
(send (block $(send _ ${:sort_by :sort}) ...) ${:last :first})
|
66
|
+
(send ({block numblock} $(send _ ${:sort_by :sort}) ...) ${:last :first})
|
67
67
|
(send
|
68
|
-
(block $(send _ ${:sort_by :sort}) ...)
|
68
|
+
({block numblock} $(send _ ${:sort_by :sort}) ...)
|
69
69
|
${:[] :at :slice} {(int 0) (int -1)}
|
70
70
|
)
|
71
71
|
}
|
@@ -4,6 +4,13 @@ module RuboCop
|
|
4
4
|
module Cop
|
5
5
|
module Style
|
6
6
|
# This cop checks for trailing comma in argument lists.
|
7
|
+
# The supported styles are:
|
8
|
+
#
|
9
|
+
# - `consistent_comma`: Requires a comma after the last argument,
|
10
|
+
# for all parenthesized method calls with arguments.
|
11
|
+
# - `comma`: Requires a comma after the last argument, but only for
|
12
|
+
# parenthesized method calls where each argument is on its own line.
|
13
|
+
# - `no_comma`: Does not requires a comma after the last argument.
|
7
14
|
#
|
8
15
|
# @example EnforcedStyleForMultiline: consistent_comma
|
9
16
|
# # bad
|
@@ -20,6 +27,11 @@ module RuboCop
|
|
20
27
|
#
|
21
28
|
# # good
|
22
29
|
# method(
|
30
|
+
# 1, 2, 3,
|
31
|
+
# )
|
32
|
+
#
|
33
|
+
# # good
|
34
|
+
# method(
|
23
35
|
# 1,
|
24
36
|
# 2,
|
25
37
|
# )
|
@@ -31,6 +43,28 @@ module RuboCop
|
|
31
43
|
# # good
|
32
44
|
# method(1, 2)
|
33
45
|
#
|
46
|
+
# # bad
|
47
|
+
# method(
|
48
|
+
# 1, 2,
|
49
|
+
# 3,
|
50
|
+
# )
|
51
|
+
#
|
52
|
+
# # good
|
53
|
+
# method(
|
54
|
+
# 1, 2,
|
55
|
+
# 3
|
56
|
+
# )
|
57
|
+
#
|
58
|
+
# # bad
|
59
|
+
# method(
|
60
|
+
# 1, 2, 3,
|
61
|
+
# )
|
62
|
+
#
|
63
|
+
# # good
|
64
|
+
# method(
|
65
|
+
# 1, 2, 3
|
66
|
+
# )
|
67
|
+
#
|
34
68
|
# # good
|
35
69
|
# method(
|
36
70
|
# 1,
|
@@ -4,12 +4,23 @@ module RuboCop
|
|
4
4
|
module Cop
|
5
5
|
module Style
|
6
6
|
# This cop checks for trailing comma in array literals.
|
7
|
+
# The configuration options are:
|
8
|
+
#
|
9
|
+
# - `consistent_comma`: Requires a comma after the
|
10
|
+
# last item of all non-empty, multiline array literals.
|
11
|
+
# - `comma`: Requires a comma after last item in an array,
|
12
|
+
# but only when each item is on its own line.
|
13
|
+
# - `no_comma`: Does not requires a comma after the
|
14
|
+
# last item in an array
|
7
15
|
#
|
8
16
|
# @example EnforcedStyleForMultiline: consistent_comma
|
9
17
|
# # bad
|
10
18
|
# a = [1, 2,]
|
11
19
|
#
|
12
20
|
# # good
|
21
|
+
# a = [1, 2]
|
22
|
+
#
|
23
|
+
# # good
|
13
24
|
# a = [
|
14
25
|
# 1, 2,
|
15
26
|
# 3,
|
@@ -17,6 +28,11 @@ module RuboCop
|
|
17
28
|
#
|
18
29
|
# # good
|
19
30
|
# a = [
|
31
|
+
# 1, 2, 3,
|
32
|
+
# ]
|
33
|
+
#
|
34
|
+
# # good
|
35
|
+
# a = [
|
20
36
|
# 1,
|
21
37
|
# 2,
|
22
38
|
# ]
|
@@ -26,6 +42,31 @@ module RuboCop
|
|
26
42
|
# a = [1, 2,]
|
27
43
|
#
|
28
44
|
# # good
|
45
|
+
# a = [1, 2]
|
46
|
+
#
|
47
|
+
# # bad
|
48
|
+
# a = [
|
49
|
+
# 1, 2,
|
50
|
+
# 3,
|
51
|
+
# ]
|
52
|
+
#
|
53
|
+
# # good
|
54
|
+
# a = [
|
55
|
+
# 1, 2,
|
56
|
+
# 3
|
57
|
+
# ]
|
58
|
+
#
|
59
|
+
# # bad
|
60
|
+
# a = [
|
61
|
+
# 1, 2, 3,
|
62
|
+
# ]
|
63
|
+
#
|
64
|
+
# # good
|
65
|
+
# a = [
|
66
|
+
# 1, 2, 3
|
67
|
+
# ]
|
68
|
+
#
|
69
|
+
# # good
|
29
70
|
# a = [
|
30
71
|
# 1,
|
31
72
|
# 2,
|
@@ -0,0 +1,85 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module RuboCop
|
4
|
+
module Cop
|
5
|
+
module Style
|
6
|
+
# This cop checks whether trailing commas in block arguments are
|
7
|
+
# required. Blocks with only one argument and a trailing comma require
|
8
|
+
# that comma to be present. Blocks with more than one argument never
|
9
|
+
# require a trailing comma.
|
10
|
+
#
|
11
|
+
# @example
|
12
|
+
# # bad
|
13
|
+
# add { |foo, bar,| foo + bar }
|
14
|
+
#
|
15
|
+
# # good
|
16
|
+
# add { |foo, bar| foo + bar }
|
17
|
+
#
|
18
|
+
# # good
|
19
|
+
# add { |foo,| foo }
|
20
|
+
#
|
21
|
+
# # good
|
22
|
+
# add { foo }
|
23
|
+
#
|
24
|
+
# # bad
|
25
|
+
# add do |foo, bar,|
|
26
|
+
# foo + bar
|
27
|
+
# end
|
28
|
+
#
|
29
|
+
# # good
|
30
|
+
# add do |foo, bar|
|
31
|
+
# foo + bar
|
32
|
+
# end
|
33
|
+
#
|
34
|
+
# # good
|
35
|
+
# add do |foo,|
|
36
|
+
# foo
|
37
|
+
# end
|
38
|
+
#
|
39
|
+
# # good
|
40
|
+
# add do
|
41
|
+
# foo + bar
|
42
|
+
# end
|
43
|
+
class TrailingCommaInBlockArgs < Cop
|
44
|
+
MSG = 'Useless trailing comma present in block arguments.'
|
45
|
+
|
46
|
+
def on_block(node)
|
47
|
+
return unless useless_trailing_comma?(node)
|
48
|
+
|
49
|
+
add_offense(node, location: last_comma(node).pos)
|
50
|
+
end
|
51
|
+
|
52
|
+
def autocorrect(node)
|
53
|
+
->(corrector) { corrector.replace(last_comma(node).pos, '') }
|
54
|
+
end
|
55
|
+
|
56
|
+
private
|
57
|
+
|
58
|
+
def useless_trailing_comma?(node)
|
59
|
+
arg_count(node) > 1 && trailing_comma?(node)
|
60
|
+
end
|
61
|
+
|
62
|
+
def arg_count(node)
|
63
|
+
node.arguments.each_descendant(:arg, :optarg, :kwoptarg).to_a.size
|
64
|
+
end
|
65
|
+
|
66
|
+
def trailing_comma?(node)
|
67
|
+
argument_tokens(node).last.comma?
|
68
|
+
end
|
69
|
+
|
70
|
+
def last_comma(node)
|
71
|
+
argument_tokens(node).last
|
72
|
+
end
|
73
|
+
|
74
|
+
def argument_tokens(node)
|
75
|
+
pipes = tokens(node).select { |token| token.type == :tPIPE }
|
76
|
+
begin_pos, end_pos = pipes.map do |pipe|
|
77
|
+
tokens(node).index(pipe)
|
78
|
+
end
|
79
|
+
|
80
|
+
tokens(node)[begin_pos + 1..end_pos - 1]
|
81
|
+
end
|
82
|
+
end
|
83
|
+
end
|
84
|
+
end
|
85
|
+
end
|
@@ -4,12 +4,24 @@ module RuboCop
|
|
4
4
|
module Cop
|
5
5
|
module Style
|
6
6
|
# This cop checks for trailing comma in hash literals.
|
7
|
+
# The configuration options are:
|
8
|
+
#
|
9
|
+
# - `consistent_comma`: Requires a comma after the
|
10
|
+
# last item of all non-empty, multiline hash literals.
|
11
|
+
# - `comma`: Requires a comma after the last item in a hash,
|
12
|
+
# but only when each item is on its own line.
|
13
|
+
# - `no_comma`: Does not requires a comma after the
|
14
|
+
# last item in a hash
|
7
15
|
#
|
8
16
|
# @example EnforcedStyleForMultiline: consistent_comma
|
17
|
+
#
|
9
18
|
# # bad
|
10
19
|
# a = { foo: 1, bar: 2, }
|
11
20
|
#
|
12
21
|
# # good
|
22
|
+
# a = { foo: 1, bar: 2 }
|
23
|
+
#
|
24
|
+
# # good
|
13
25
|
# a = {
|
14
26
|
# foo: 1, bar: 2,
|
15
27
|
# qux: 3,
|
@@ -17,21 +29,53 @@ module RuboCop
|
|
17
29
|
#
|
18
30
|
# # good
|
19
31
|
# a = {
|
32
|
+
# foo: 1, bar: 2, qux: 3,
|
33
|
+
# }
|
34
|
+
#
|
35
|
+
# # good
|
36
|
+
# a = {
|
20
37
|
# foo: 1,
|
21
38
|
# bar: 2,
|
22
39
|
# }
|
23
40
|
#
|
24
41
|
# @example EnforcedStyleForMultiline: comma
|
42
|
+
#
|
25
43
|
# # bad
|
26
44
|
# a = { foo: 1, bar: 2, }
|
27
45
|
#
|
28
46
|
# # good
|
47
|
+
# a = { foo: 1, bar: 2 }
|
48
|
+
#
|
49
|
+
# # bad
|
50
|
+
# a = {
|
51
|
+
# foo: 1, bar: 2,
|
52
|
+
# qux: 3,
|
53
|
+
# }
|
54
|
+
#
|
55
|
+
# # good
|
56
|
+
# a = {
|
57
|
+
# foo: 1, bar: 2,
|
58
|
+
# qux: 3
|
59
|
+
# }
|
60
|
+
#
|
61
|
+
# # bad
|
62
|
+
# a = {
|
63
|
+
# foo: 1, bar: 2, qux: 3,
|
64
|
+
# }
|
65
|
+
#
|
66
|
+
# # good
|
67
|
+
# a = {
|
68
|
+
# foo: 1, bar: 2, qux: 3
|
69
|
+
# }
|
70
|
+
#
|
71
|
+
# # good
|
29
72
|
# a = {
|
30
73
|
# foo: 1,
|
31
74
|
# bar: 2,
|
32
75
|
# }
|
33
76
|
#
|
34
77
|
# @example EnforcedStyleForMultiline: no_comma (default)
|
78
|
+
#
|
35
79
|
# # bad
|
36
80
|
# a = { foo: 1, bar: 2, }
|
37
81
|
#
|
@@ -29,7 +29,7 @@ module RuboCop
|
|
29
29
|
|
30
30
|
report_line(offense.location)
|
31
31
|
report_highlighted_area(offense.highlighted_area)
|
32
|
-
rescue IndexError
|
32
|
+
rescue IndexError
|
33
33
|
# range is not on a valid line; perhaps the source file is empty
|
34
34
|
end
|
35
35
|
end
|
@@ -29,18 +29,29 @@ module RuboCop
|
|
29
29
|
end
|
30
30
|
|
31
31
|
def file_finished(file, offenses)
|
32
|
-
|
32
|
+
# TODO: Returns all cops with the same behavior as
|
33
|
+
# the original rubocop-junit-formatter.
|
34
|
+
# https://github.com/mikian/rubocop-junit-formatter/blob/v0.1.4/lib/rubocop/formatter/junit_formatter.rb#L9
|
35
|
+
#
|
36
|
+
# In the future, it would be preferable to return only enabled cops.
|
37
|
+
Cop::Cop.all.each do |cop|
|
33
38
|
REXML::Element.new('testcase', @testsuite).tap do |testcase|
|
34
|
-
testcase.attributes['classname'] = file
|
35
|
-
|
36
|
-
).gsub("#{Dir.pwd}/", '').tr('/', '.')
|
37
|
-
testcase.attributes['name'] = cop_name
|
39
|
+
testcase.attributes['classname'] = classname_attribute_value(file)
|
40
|
+
testcase.attributes['name'] = cop.cop_name
|
38
41
|
|
39
|
-
|
42
|
+
target_offenses = offenses.select do |offense|
|
43
|
+
offense.cop_name == cop.cop_name
|
44
|
+
end
|
45
|
+
|
46
|
+
add_failure_to(testcase, target_offenses, cop.cop_name)
|
40
47
|
end
|
41
48
|
end
|
42
49
|
end
|
43
50
|
|
51
|
+
def classname_attribute_value(file)
|
52
|
+
file.gsub(/\.rb\Z/, '').gsub("#{Dir.pwd}/", '').tr('/', '.')
|
53
|
+
end
|
54
|
+
|
44
55
|
def finished(_inspected_files)
|
45
56
|
@document.write(output, 2)
|
46
57
|
end
|
@@ -56,7 +56,7 @@ module RuboCop
|
|
56
56
|
|
57
57
|
report_line(offense.location)
|
58
58
|
report_highlighted_area(offense.highlighted_area)
|
59
|
-
rescue IndexError
|
59
|
+
rescue IndexError
|
60
60
|
# range is not on a valid line; perhaps the source file is empty
|
61
61
|
end
|
62
62
|
end
|
@@ -163,7 +163,7 @@ module RuboCop
|
|
163
163
|
ast, comments, tokens = parser.tokenize(@buffer)
|
164
164
|
|
165
165
|
ast.respond_to?(:complete!) && ast.complete!
|
166
|
-
rescue Parser::SyntaxError
|
166
|
+
rescue Parser::SyntaxError
|
167
167
|
# All errors are in diagnostics. No need to handle exception.
|
168
168
|
end
|
169
169
|
|
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: 0.
|
4
|
+
version: 0.81.0
|
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-
|
13
|
+
date: 2020-04-01 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: jaro_winkler
|
@@ -111,7 +111,7 @@ dependencies:
|
|
111
111
|
version: 1.4.0
|
112
112
|
- - "<"
|
113
113
|
- !ruby/object:Gem::Version
|
114
|
-
version: '
|
114
|
+
version: '2.0'
|
115
115
|
type: :runtime
|
116
116
|
prerelease: false
|
117
117
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -121,7 +121,7 @@ dependencies:
|
|
121
121
|
version: 1.4.0
|
122
122
|
- - "<"
|
123
123
|
- !ruby/object:Gem::Version
|
124
|
-
version: '
|
124
|
+
version: '2.0'
|
125
125
|
- !ruby/object:Gem::Dependency
|
126
126
|
name: bundler
|
127
127
|
requirement: !ruby/object:Gem::Requirement
|
@@ -170,6 +170,7 @@ files:
|
|
170
170
|
- lib/rubocop/ast/node/array_node.rb
|
171
171
|
- lib/rubocop/ast/node/block_node.rb
|
172
172
|
- lib/rubocop/ast/node/break_node.rb
|
173
|
+
- lib/rubocop/ast/node/case_match_node.rb
|
173
174
|
- lib/rubocop/ast/node/case_node.rb
|
174
175
|
- lib/rubocop/ast/node/class_node.rb
|
175
176
|
- lib/rubocop/ast/node/def_node.rb
|
@@ -377,7 +378,6 @@ files:
|
|
377
378
|
- lib/rubocop/cop/lint/empty_expression.rb
|
378
379
|
- lib/rubocop/cop/lint/empty_interpolation.rb
|
379
380
|
- lib/rubocop/cop/lint/empty_when.rb
|
380
|
-
- lib/rubocop/cop/lint/end_in_method.rb
|
381
381
|
- lib/rubocop/cop/lint/ensure_return.rb
|
382
382
|
- lib/rubocop/cop/lint/erb_new_arguments.rb
|
383
383
|
- lib/rubocop/cop/lint/flip_flop.rb
|
@@ -403,6 +403,7 @@ files:
|
|
403
403
|
- lib/rubocop/cop/lint/parentheses_as_grouped_expression.rb
|
404
404
|
- lib/rubocop/cop/lint/percent_string_array.rb
|
405
405
|
- lib/rubocop/cop/lint/percent_symbol_array.rb
|
406
|
+
- lib/rubocop/cop/lint/raise_exception.rb
|
406
407
|
- lib/rubocop/cop/lint/rand_one.rb
|
407
408
|
- lib/rubocop/cop/lint/redundant_cop_disable_directive.rb
|
408
409
|
- lib/rubocop/cop/lint/redundant_cop_enable_directive.rb
|
@@ -424,6 +425,7 @@ files:
|
|
424
425
|
- lib/rubocop/cop/lint/shadowed_argument.rb
|
425
426
|
- lib/rubocop/cop/lint/shadowed_exception.rb
|
426
427
|
- lib/rubocop/cop/lint/shadowing_outer_local_variable.rb
|
428
|
+
- lib/rubocop/cop/lint/struct_new_override.rb
|
427
429
|
- lib/rubocop/cop/lint/suppressed_exception.rb
|
428
430
|
- lib/rubocop/cop/lint/syntax.rb
|
429
431
|
- lib/rubocop/cop/lint/to_json.rb
|
@@ -701,6 +703,7 @@ files:
|
|
701
703
|
- lib/rubocop/cop/style/trailing_body_on_module.rb
|
702
704
|
- lib/rubocop/cop/style/trailing_comma_in_arguments.rb
|
703
705
|
- lib/rubocop/cop/style/trailing_comma_in_array_literal.rb
|
706
|
+
- lib/rubocop/cop/style/trailing_comma_in_block_args.rb
|
704
707
|
- lib/rubocop/cop/style/trailing_comma_in_hash_literal.rb
|
705
708
|
- lib/rubocop/cop/style/trailing_method_end_statement.rb
|
706
709
|
- lib/rubocop/cop/style/trailing_underscore_variable.rb
|