rubocop 1.17.0 → 1.18.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +1 -1
- data/config/default.yml +69 -28
- data/lib/rubocop.rb +2 -0
- data/lib/rubocop/cli/command/suggest_extensions.rb +3 -3
- data/lib/rubocop/config_loader.rb +1 -1
- data/lib/rubocop/config_validator.rb +5 -5
- data/lib/rubocop/cop/base.rb +2 -2
- data/lib/rubocop/cop/bundler/duplicated_gem.rb +1 -1
- data/lib/rubocop/cop/bundler/gem_version.rb +38 -4
- data/lib/rubocop/cop/corrector.rb +4 -4
- data/lib/rubocop/cop/generator.rb +1 -1
- data/lib/rubocop/cop/internal_affairs/node_matcher_directive.rb +1 -1
- data/lib/rubocop/cop/layout/argument_alignment.rb +1 -1
- data/lib/rubocop/cop/layout/array_alignment.rb +2 -2
- data/lib/rubocop/cop/layout/block_alignment.rb +1 -1
- data/lib/rubocop/cop/layout/closing_parenthesis_indentation.rb +7 -1
- data/lib/rubocop/cop/layout/comment_indentation.rb +1 -1
- 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/first_parameter_indentation.rb +1 -1
- data/lib/rubocop/cop/layout/hash_alignment.rb +10 -9
- data/lib/rubocop/cop/layout/heredoc_argument_closing_parenthesis.rb +1 -1
- data/lib/rubocop/cop/layout/line_end_string_concatenation_indentation.rb +127 -0
- data/lib/rubocop/cop/layout/multiline_array_brace_layout.rb +6 -6
- data/lib/rubocop/cop/layout/multiline_assignment_layout.rb +2 -2
- data/lib/rubocop/cop/layout/multiline_hash_brace_layout.rb +6 -6
- data/lib/rubocop/cop/layout/multiline_method_call_brace_layout.rb +6 -6
- data/lib/rubocop/cop/layout/multiline_method_definition_brace_layout.rb +6 -6
- data/lib/rubocop/cop/layout/multiline_operation_indentation.rb +3 -3
- data/lib/rubocop/cop/layout/parameter_alignment.rb +2 -2
- data/lib/rubocop/cop/layout/space_around_operators.rb +1 -1
- data/lib/rubocop/cop/lint/nested_percent_literal.rb +1 -1
- data/lib/rubocop/cop/lint/percent_string_array.rb +1 -1
- data/lib/rubocop/cop/lint/percent_symbol_array.rb +1 -1
- data/lib/rubocop/cop/lint/symbol_conversion.rb +1 -1
- data/lib/rubocop/cop/lint/unused_block_argument.rb +1 -1
- data/lib/rubocop/cop/lint/useless_assignment.rb +1 -1
- data/lib/rubocop/cop/metrics/utils/code_length_calculator.rb +1 -1
- data/lib/rubocop/cop/mixin/check_line_breakable.rb +10 -1
- data/lib/rubocop/cop/naming/inclusive_language.rb +249 -0
- data/lib/rubocop/cop/naming/memoized_instance_variable_name.rb +2 -2
- data/lib/rubocop/cop/style/class_and_module_children.rb +14 -0
- data/lib/rubocop/cop/style/comment_annotation.rb +50 -6
- data/lib/rubocop/cop/style/multiple_comparison.rb +1 -1
- data/lib/rubocop/cop/style/percent_literal_delimiters.rb +1 -1
- data/lib/rubocop/cop/style/quoted_symbols.rb +2 -2
- data/lib/rubocop/cop/style/redundant_regexp_character_class.rb +1 -1
- data/lib/rubocop/cop/style/regexp_literal.rb +3 -2
- data/lib/rubocop/cop/style/special_global_vars.rb +3 -3
- data/lib/rubocop/cop/style/string_concatenation.rb +32 -5
- data/lib/rubocop/cop/style/string_literals.rb +2 -2
- data/lib/rubocop/cop/style/swap_values.rb +1 -1
- data/lib/rubocop/cop/style/unpack_first.rb +1 -1
- data/lib/rubocop/cop/variable_force/variable_table.rb +1 -1
- data/lib/rubocop/options.rb +4 -4
- data/lib/rubocop/rspec/cop_helper.rb +1 -1
- data/lib/rubocop/rspec/expect_offense.rb +1 -1
- data/lib/rubocop/version.rb +1 -1
- metadata +5 -3
@@ -44,7 +44,7 @@ module RuboCop
|
|
44
44
|
extend AutoCorrector
|
45
45
|
|
46
46
|
MSG = 'Avoid comparing a variable with multiple items ' \
|
47
|
-
|
47
|
+
'in a conditional, use `Array#include?` instead.'
|
48
48
|
|
49
49
|
def on_new_investigation
|
50
50
|
@last_comparison = nil
|
@@ -36,9 +36,9 @@ module RuboCop
|
|
36
36
|
extend AutoCorrector
|
37
37
|
|
38
38
|
MSG_SINGLE = "Prefer single-quoted symbols when you don't need string interpolation " \
|
39
|
-
|
39
|
+
'or special symbols.'
|
40
40
|
MSG_DOUBLE = 'Prefer double-quoted symbols unless you need single quotes to ' \
|
41
|
-
|
41
|
+
'avoid extra backslashes for escaping.'
|
42
42
|
|
43
43
|
def on_sym(node)
|
44
44
|
return unless quoted?(node)
|
@@ -32,7 +32,7 @@ module RuboCop
|
|
32
32
|
|
33
33
|
REQUIRES_ESCAPE_OUTSIDE_CHAR_CLASS_CHARS = '.*+?{}()|$'.chars.freeze
|
34
34
|
MSG_REDUNDANT_CHARACTER_CLASS = 'Redundant single-element character class, ' \
|
35
|
-
|
35
|
+
'`%<char_class>s` can be replaced with `%<element>s`.'
|
36
36
|
|
37
37
|
def on_regexp(node)
|
38
38
|
each_redundant_character_class(node) do |loc|
|
@@ -117,7 +117,7 @@ module RuboCop
|
|
117
117
|
def allowed_percent_r_literal?(node)
|
118
118
|
style == :slashes && contains_disallowed_slash?(node) ||
|
119
119
|
style == :percent_r ||
|
120
|
-
allowed_mixed_percent_r?(node) ||
|
120
|
+
allowed_mixed_percent_r?(node) || allowed_omit_parentheses_with_percent_r_literal?(node)
|
121
121
|
end
|
122
122
|
|
123
123
|
def allowed_mixed_percent_r?(node)
|
@@ -149,8 +149,9 @@ module RuboCop
|
|
149
149
|
config.for_cop('Style/PercentLiteralDelimiters') ['PreferredDelimiters']['%r'].chars
|
150
150
|
end
|
151
151
|
|
152
|
-
def
|
152
|
+
def allowed_omit_parentheses_with_percent_r_literal?(node)
|
153
153
|
return false unless node.parent&.call_type?
|
154
|
+
return true if node.content.start_with?(' ')
|
154
155
|
|
155
156
|
enforced_style = config.for_cop('Style/MethodCallWithArgsParentheses')['EnforcedStyle']
|
156
157
|
|
@@ -53,10 +53,10 @@ module RuboCop
|
|
53
53
|
extend AutoCorrector
|
54
54
|
|
55
55
|
MSG_BOTH = 'Prefer `%<prefer>s` from the stdlib \'English\' ' \
|
56
|
-
|
57
|
-
|
56
|
+
'module (don\'t forget to require it) or `%<regular>s` over ' \
|
57
|
+
'`%<global>s`.'
|
58
58
|
MSG_ENGLISH = 'Prefer `%<prefer>s` from the stdlib \'English\' ' \
|
59
|
-
|
59
|
+
'module (don\'t forget to require it) over `%<global>s`.'
|
60
60
|
MSG_REGULAR = 'Prefer `%<prefer>s` over `%<global>s`.'
|
61
61
|
|
62
62
|
ENGLISH_VARS = { # rubocop:disable Style/MutableConstant
|
@@ -15,18 +15,37 @@ module RuboCop
|
|
15
15
|
# lines, this cop does not register an offense; instead,
|
16
16
|
# `Style/LineEndConcatenation` will pick up the offense if enabled.
|
17
17
|
#
|
18
|
-
#
|
18
|
+
# Two modes are supported:
|
19
|
+
# 1. `aggressive` style checks and corrects all occurrences of `+` where
|
20
|
+
# either the left or right side of `+` is a string literal.
|
21
|
+
# 2. `conservative` style on the other hand, checks and corrects only if
|
22
|
+
# left side (receiver of `+` method call) is a string literal.
|
23
|
+
# This is useful when the receiver is some expression that returns string like `Pathname`
|
24
|
+
# instead of a string literal.
|
25
|
+
#
|
26
|
+
# @example Mode: aggressive (default)
|
19
27
|
# # bad
|
20
28
|
# email_with_name = user.name + ' <' + user.email + '>'
|
29
|
+
# Pathname.new('/') + 'test'
|
21
30
|
#
|
22
31
|
# # good
|
23
32
|
# email_with_name = "#{user.name} <#{user.email}>"
|
24
33
|
# email_with_name = format('%s <%s>', user.name, user.email)
|
34
|
+
# "#{Pathname.new('/')}test"
|
25
35
|
#
|
26
36
|
# # accepted, line-end concatenation
|
27
37
|
# name = 'First' +
|
28
38
|
# 'Last'
|
29
39
|
#
|
40
|
+
# @example Mode: conservative
|
41
|
+
# # bad
|
42
|
+
# 'Hello' + user.name
|
43
|
+
#
|
44
|
+
# # good
|
45
|
+
# "Hello #{user.name}"
|
46
|
+
# user.name + '!!'
|
47
|
+
# Pathname.new('/') + 'test'
|
48
|
+
#
|
30
49
|
class StringConcatenation < Base
|
31
50
|
include Util
|
32
51
|
include RangeHelp
|
@@ -52,10 +71,15 @@ module RuboCop
|
|
52
71
|
return if line_end_concatenation?(node)
|
53
72
|
|
54
73
|
topmost_plus_node = find_topmost_plus_node(node)
|
74
|
+
parts = collect_parts(topmost_plus_node)
|
75
|
+
return unless parts[0..-2].any? { |receiver_node| offensive_for_mode?(receiver_node) }
|
55
76
|
|
56
|
-
parts
|
57
|
-
|
77
|
+
register_offense(topmost_plus_node, parts)
|
78
|
+
end
|
79
|
+
|
80
|
+
private
|
58
81
|
|
82
|
+
def register_offense(topmost_plus_node, parts)
|
59
83
|
add_offense(topmost_plus_node) do |corrector|
|
60
84
|
correctable_parts = parts.none? { |part| uncorrectable?(part) }
|
61
85
|
if correctable_parts && !corrected_ancestor?(topmost_plus_node)
|
@@ -67,7 +91,10 @@ module RuboCop
|
|
67
91
|
end
|
68
92
|
end
|
69
93
|
|
70
|
-
|
94
|
+
def offensive_for_mode?(receiver_node)
|
95
|
+
mode = cop_config['Mode'].to_sym
|
96
|
+
mode == :aggressive || mode == :conservative && receiver_node.str_type?
|
97
|
+
end
|
71
98
|
|
72
99
|
def line_end_concatenation?(node)
|
73
100
|
# If the concatenation happens at the end of the line,
|
@@ -87,7 +114,7 @@ module RuboCop
|
|
87
114
|
current
|
88
115
|
end
|
89
116
|
|
90
|
-
def collect_parts(node, parts)
|
117
|
+
def collect_parts(node, parts = [])
|
91
118
|
return unless node
|
92
119
|
|
93
120
|
if plus_node?(node)
|
@@ -87,10 +87,10 @@ module RuboCop
|
|
87
87
|
def message(_node)
|
88
88
|
if style == :single_quotes
|
89
89
|
"Prefer single-quoted strings when you don't need string " \
|
90
|
-
|
90
|
+
'interpolation or special symbols.'
|
91
91
|
else
|
92
92
|
'Prefer double-quoted strings unless you need single quotes to ' \
|
93
|
-
|
93
|
+
'avoid extra backslashes for escaping.'
|
94
94
|
end
|
95
95
|
end
|
96
96
|
|
@@ -21,7 +21,7 @@ module RuboCop
|
|
21
21
|
extend AutoCorrector
|
22
22
|
|
23
23
|
MSG = 'Replace this and assignments at lines %<x_line>d '\
|
24
|
-
|
24
|
+
'and %<y_line>d with `%<replacement>s`.'
|
25
25
|
|
26
26
|
SIMPLE_ASSIGNMENT_TYPES = %i[lvasgn ivasgn cvasgn gvasgn casgn].to_set.freeze
|
27
27
|
|
@@ -21,7 +21,7 @@ module RuboCop
|
|
21
21
|
extend AutoCorrector
|
22
22
|
|
23
23
|
MSG = 'Use `%<receiver>s.unpack1(%<format>s)` instead of '\
|
24
|
-
|
24
|
+
'`%<receiver>s.unpack(%<format>s)%<method>s`.'
|
25
25
|
RESTRICT_ON_SEND = %i[first [] slice at].freeze
|
26
26
|
|
27
27
|
# @!method unpack_and_first_element?(node)
|
data/lib/rubocop/options.rb
CHANGED
@@ -12,9 +12,9 @@ module RuboCop
|
|
12
12
|
# @api private
|
13
13
|
class Options
|
14
14
|
E_STDIN_NO_PATH = '-s/--stdin requires exactly one path, relative to the ' \
|
15
|
-
|
16
|
-
|
17
|
-
|
15
|
+
'root of the project. RuboCop will use this path to determine which ' \
|
16
|
+
'cops are enabled (via eg. Include/Exclude), and so that certain cops ' \
|
17
|
+
'like Naming/FileName can be checked.'
|
18
18
|
EXITING_OPTIONS = %i[version verbose_version show_cops].freeze
|
19
19
|
DEFAULT_MAXIMUM_EXCLUSION_ITEMS = 15
|
20
20
|
|
@@ -292,7 +292,7 @@ module RuboCop
|
|
292
292
|
|
293
293
|
if display_only_fail_level_offenses_with_autocorrect?
|
294
294
|
raise OptionArgumentError, '--autocorrect cannot be used with ' \
|
295
|
-
|
295
|
+
'--display-only-fail-level-offenses'
|
296
296
|
end
|
297
297
|
validate_auto_gen_config
|
298
298
|
validate_auto_correct
|
@@ -15,7 +15,7 @@ module CopHelper
|
|
15
15
|
processed_source = parse_source(source, file)
|
16
16
|
unless processed_source.valid_syntax?
|
17
17
|
raise 'Error parsing example code: ' \
|
18
|
-
|
18
|
+
"#{processed_source.diagnostics.map(&:render).join("\n")}"
|
19
19
|
end
|
20
20
|
|
21
21
|
_investigate(cop, processed_source)
|
@@ -195,7 +195,7 @@ module RuboCop
|
|
195
195
|
return processed_source if processed_source.valid_syntax?
|
196
196
|
|
197
197
|
raise 'Error parsing example code: ' \
|
198
|
-
|
198
|
+
"#{processed_source.diagnostics.map(&:render).join("\n")}"
|
199
199
|
end
|
200
200
|
|
201
201
|
def set_formatter_options
|
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.
|
4
|
+
version: 1.18.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: 2021-
|
13
|
+
date: 2021-07-02 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: parallel
|
@@ -319,6 +319,7 @@ files:
|
|
319
319
|
- lib/rubocop/cop/layout/initial_indentation.rb
|
320
320
|
- lib/rubocop/cop/layout/leading_comment_space.rb
|
321
321
|
- lib/rubocop/cop/layout/leading_empty_lines.rb
|
322
|
+
- lib/rubocop/cop/layout/line_end_string_concatenation_indentation.rb
|
322
323
|
- lib/rubocop/cop/layout/line_length.rb
|
323
324
|
- lib/rubocop/cop/layout/multiline_array_brace_layout.rb
|
324
325
|
- lib/rubocop/cop/layout/multiline_array_line_breaks.rb
|
@@ -579,6 +580,7 @@ files:
|
|
579
580
|
- lib/rubocop/cop/naming/file_name.rb
|
580
581
|
- lib/rubocop/cop/naming/heredoc_delimiter_case.rb
|
581
582
|
- lib/rubocop/cop/naming/heredoc_delimiter_naming.rb
|
583
|
+
- lib/rubocop/cop/naming/inclusive_language.rb
|
582
584
|
- lib/rubocop/cop/naming/memoized_instance_variable_name.rb
|
583
585
|
- lib/rubocop/cop/naming/method_name.rb
|
584
586
|
- lib/rubocop/cop/naming/method_parameter_name.rb
|
@@ -881,7 +883,7 @@ metadata:
|
|
881
883
|
homepage_uri: https://rubocop.org/
|
882
884
|
changelog_uri: https://github.com/rubocop/rubocop/blob/master/CHANGELOG.md
|
883
885
|
source_code_uri: https://github.com/rubocop/rubocop/
|
884
|
-
documentation_uri: https://docs.rubocop.org/rubocop/1.
|
886
|
+
documentation_uri: https://docs.rubocop.org/rubocop/1.18/
|
885
887
|
bug_tracker_uri: https://github.com/rubocop/rubocop/issues
|
886
888
|
post_install_message:
|
887
889
|
rdoc_options: []
|