rubocop 1.48.1 → 1.49.0
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 +13 -2
- data/lib/rubocop/cli/command/execute_runner.rb +7 -2
- data/lib/rubocop/cli.rb +6 -6
- data/lib/rubocop/config.rb +1 -1
- data/lib/rubocop/cop/autocorrect_logic.rb +28 -12
- data/lib/rubocop/cop/cop.rb +2 -2
- data/lib/rubocop/cop/correctors/parentheses_corrector.rb +1 -1
- data/lib/rubocop/cop/correctors/percent_literal_corrector.rb +2 -2
- data/lib/rubocop/cop/internal_affairs/cop_description.rb +1 -1
- data/lib/rubocop/cop/internal_affairs/example_heredoc_delimiter.rb +2 -2
- data/lib/rubocop/cop/internal_affairs/inherit_deprecated_cop_class.rb +1 -1
- data/lib/rubocop/cop/internal_affairs/redundant_source_range.rb +29 -2
- data/lib/rubocop/cop/layout/empty_lines_around_access_modifier.rb +2 -0
- data/lib/rubocop/cop/layout/end_alignment.rb +5 -1
- data/lib/rubocop/cop/layout/extra_spacing.rb +6 -1
- data/lib/rubocop/cop/layout/first_argument_indentation.rb +6 -1
- data/lib/rubocop/cop/layout/heredoc_argument_closing_parenthesis.rb +2 -2
- data/lib/rubocop/cop/layout/redundant_line_break.rb +6 -7
- data/lib/rubocop/cop/layout/space_before_first_arg.rb +1 -1
- data/lib/rubocop/cop/layout/space_inside_parens.rb +2 -2
- data/lib/rubocop/cop/lint/deprecated_class_methods.rb +3 -3
- data/lib/rubocop/cop/lint/empty_interpolation.rb +1 -1
- data/lib/rubocop/cop/lint/nested_method_definition.rb +2 -2
- data/lib/rubocop/cop/lint/redundant_cop_disable_directive.rb +1 -1
- data/lib/rubocop/cop/lint/to_enum_arguments.rb +7 -1
- data/lib/rubocop/cop/lint/unreachable_loop.rb +3 -3
- data/lib/rubocop/cop/lint/useless_method_definition.rb +10 -2
- data/lib/rubocop/cop/lint/void.rb +7 -3
- data/lib/rubocop/cop/metrics/block_nesting.rb +1 -1
- data/lib/rubocop/cop/mixin/comments_help.rb +1 -1
- data/lib/rubocop/cop/mixin/hash_transform_method.rb +1 -1
- data/lib/rubocop/cop/naming/inclusive_language.rb +22 -3
- data/lib/rubocop/cop/style/class_and_module_children.rb +1 -1
- data/lib/rubocop/cop/style/class_equality_comparison.rb +15 -2
- data/lib/rubocop/cop/style/data_inheritance.rb +75 -0
- data/lib/rubocop/cop/style/disable_cops_within_source_code_directive.rb +2 -2
- data/lib/rubocop/cop/style/document_dynamic_eval_definition.rb +1 -1
- data/lib/rubocop/cop/style/double_negation.rb +2 -2
- data/lib/rubocop/cop/style/hash_except.rb +4 -4
- data/lib/rubocop/cop/style/hash_syntax.rb +4 -1
- data/lib/rubocop/cop/style/if_unless_modifier.rb +38 -12
- data/lib/rubocop/cop/style/map_to_hash.rb +4 -1
- data/lib/rubocop/cop/style/map_to_set.rb +4 -1
- data/lib/rubocop/cop/style/method_call_with_args_parentheses/omit_parentheses.rb +3 -7
- data/lib/rubocop/cop/style/method_call_with_args_parentheses.rb +43 -36
- data/lib/rubocop/cop/style/percent_literal_delimiters.rb +2 -3
- data/lib/rubocop/cop/style/percent_q_literals.rb +1 -1
- data/lib/rubocop/cop/style/redundant_line_continuation.rb +142 -0
- data/lib/rubocop/cop/style/redundant_parentheses.rb +1 -1
- data/lib/rubocop/cop/style/redundant_percent_q.rb +1 -1
- data/lib/rubocop/cop/style/redundant_regexp_character_class.rb +2 -2
- data/lib/rubocop/cop/style/redundant_regexp_escape.rb +1 -1
- data/lib/rubocop/cop/style/redundant_string_escape.rb +2 -3
- data/lib/rubocop/cop/style/sole_nested_conditional.rb +2 -2
- data/lib/rubocop/cop/style/struct_inheritance.rb +1 -1
- data/lib/rubocop/cop/style/trivial_accessors.rb +1 -1
- data/lib/rubocop/cop/style/unless_logical_operators.rb +1 -0
- data/lib/rubocop/ext/regexp_node.rb +1 -1
- data/lib/rubocop/ext/regexp_parser.rb +1 -1
- data/lib/rubocop/formatter/simple_text_formatter.rb +1 -1
- data/lib/rubocop/options.rb +4 -1
- data/lib/rubocop/result_cache.rb +1 -1
- data/lib/rubocop/server/cache.rb +1 -1
- data/lib/rubocop/server/helper.rb +1 -1
- data/lib/rubocop/server/server_command/exec.rb +1 -1
- data/lib/rubocop/version.rb +1 -1
- data/lib/rubocop.rb +2 -0
- metadata +8 -6
@@ -0,0 +1,142 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module RuboCop
|
4
|
+
module Cop
|
5
|
+
module Style
|
6
|
+
# Check for redundant line continuation.
|
7
|
+
#
|
8
|
+
# This cop marks a line continuation as redundant if removing the backslash
|
9
|
+
# does not result in a syntax error.
|
10
|
+
# However, a backslash at the end of a comment or
|
11
|
+
# for string concatenation is not redundant and is not considered an offense.
|
12
|
+
#
|
13
|
+
# @example
|
14
|
+
# # bad
|
15
|
+
# foo. \
|
16
|
+
# bar
|
17
|
+
# foo \
|
18
|
+
# &.bar \
|
19
|
+
# .baz
|
20
|
+
#
|
21
|
+
# # good
|
22
|
+
# foo.
|
23
|
+
# bar
|
24
|
+
# foo
|
25
|
+
# &.bar
|
26
|
+
# .baz
|
27
|
+
#
|
28
|
+
# # bad
|
29
|
+
# [foo, \
|
30
|
+
# bar]
|
31
|
+
# {foo: \
|
32
|
+
# bar}
|
33
|
+
#
|
34
|
+
# # good
|
35
|
+
# [foo,
|
36
|
+
# bar]
|
37
|
+
# {foo:
|
38
|
+
# bar}
|
39
|
+
#
|
40
|
+
# # bad
|
41
|
+
# foo(bar, \
|
42
|
+
# baz)
|
43
|
+
#
|
44
|
+
# # good
|
45
|
+
# foo(bar,
|
46
|
+
# baz)
|
47
|
+
#
|
48
|
+
# # also good - backslash in string concatenation is not redundant
|
49
|
+
# foo('bar' \
|
50
|
+
# 'baz')
|
51
|
+
#
|
52
|
+
# # also good - backslash at the end of a comment is not redundant
|
53
|
+
# foo(bar, # \
|
54
|
+
# baz)
|
55
|
+
#
|
56
|
+
# # also good - backslash at the line following the newline begins with a + or -,
|
57
|
+
# # it is not redundant
|
58
|
+
# 1 \
|
59
|
+
# + 2 \
|
60
|
+
# - 3
|
61
|
+
#
|
62
|
+
# # also good - backslash with newline between the method name and its arguments,
|
63
|
+
# # it is not redundant.
|
64
|
+
# some_method \
|
65
|
+
# (argument)
|
66
|
+
#
|
67
|
+
class RedundantLineContinuation < Base
|
68
|
+
include MatchRange
|
69
|
+
extend AutoCorrector
|
70
|
+
|
71
|
+
MSG = 'Redundant line continuation.'
|
72
|
+
|
73
|
+
def on_new_investigation
|
74
|
+
return unless processed_source.ast
|
75
|
+
|
76
|
+
each_match_range(processed_source.ast.source_range, /(\\\n)/) do |range|
|
77
|
+
next if require_line_continuation?(range)
|
78
|
+
next unless redundant_line_continuation?(range)
|
79
|
+
|
80
|
+
add_offense(range) do |corrector|
|
81
|
+
corrector.remove_leading(range, 1)
|
82
|
+
end
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
86
|
+
private
|
87
|
+
|
88
|
+
def require_line_continuation?(range)
|
89
|
+
!ends_with_backslash_without_comment?(range.source_line) ||
|
90
|
+
string_concatenation?(range.source_line) ||
|
91
|
+
starts_with_plus_or_minus?(processed_source[range.line])
|
92
|
+
end
|
93
|
+
|
94
|
+
def ends_with_backslash_without_comment?(source_line)
|
95
|
+
source_line.gsub(/#.+/, '').end_with?('\\')
|
96
|
+
end
|
97
|
+
|
98
|
+
def string_concatenation?(source_line)
|
99
|
+
/["']\s*\\\z/.match?(source_line)
|
100
|
+
end
|
101
|
+
|
102
|
+
def redundant_line_continuation?(range)
|
103
|
+
return true unless (node = find_node_for_line(range.line))
|
104
|
+
return false if argument_newline?(node)
|
105
|
+
|
106
|
+
parse(node.source.gsub(/\\\n/, "\n")).valid_syntax?
|
107
|
+
end
|
108
|
+
|
109
|
+
def argument_newline?(node)
|
110
|
+
node = node.children.first if node.root? && node.begin_type?
|
111
|
+
return if !node.send_type? || node.arguments.empty?
|
112
|
+
|
113
|
+
node.loc.selector.line != node.first_argument.loc.line
|
114
|
+
end
|
115
|
+
|
116
|
+
def find_node_for_line(line)
|
117
|
+
processed_source.ast.each_node do |node|
|
118
|
+
return node if same_line?(node, line)
|
119
|
+
end
|
120
|
+
end
|
121
|
+
|
122
|
+
def same_line?(node, line)
|
123
|
+
return unless (source_range = node.source_range)
|
124
|
+
|
125
|
+
if node.is_a?(AST::StrNode)
|
126
|
+
if node.heredoc?
|
127
|
+
(node.loc.heredoc_body.line..node.loc.heredoc_body.last_line).cover?(line)
|
128
|
+
else
|
129
|
+
(source_range.line..source_range.last_line).cover?(line)
|
130
|
+
end
|
131
|
+
else
|
132
|
+
source_range.line == line
|
133
|
+
end
|
134
|
+
end
|
135
|
+
|
136
|
+
def starts_with_plus_or_minus?(source_line)
|
137
|
+
%r{\A\s*[+\-*/%]}.match?(source_line)
|
138
|
+
end
|
139
|
+
end
|
140
|
+
end
|
141
|
+
end
|
142
|
+
end
|
@@ -98,7 +98,7 @@ module RuboCop
|
|
98
98
|
end
|
99
99
|
|
100
100
|
def like_method_argument_parentheses?(node)
|
101
|
-
node.send_type? && node.arguments.one? &&
|
101
|
+
node.send_type? && node.arguments.one? && !node.parenthesized? &&
|
102
102
|
!node.arithmetic_operation? && node.first_argument.begin_type?
|
103
103
|
end
|
104
104
|
|
@@ -63,7 +63,7 @@ module RuboCop
|
|
63
63
|
next if expr.type != :set || expr.expressions.size != 1
|
64
64
|
next if expr.negative?
|
65
65
|
next if %i[set posixclass nonposixclass].include?(expr.expressions.first.type)
|
66
|
-
next if
|
66
|
+
next if multiple_codepoints?(expr.expressions.first)
|
67
67
|
|
68
68
|
yield expr
|
69
69
|
end
|
@@ -80,7 +80,7 @@ module RuboCop
|
|
80
80
|
!non_redundant
|
81
81
|
end
|
82
82
|
|
83
|
-
def
|
83
|
+
def multiple_codepoints?(expression)
|
84
84
|
expression.respond_to?(:codepoints) && expression.codepoints.count >= 2
|
85
85
|
end
|
86
86
|
|
@@ -107,7 +107,7 @@ module RuboCop
|
|
107
107
|
end
|
108
108
|
end
|
109
109
|
# Please remove this `else` branch when support for regexp_parser 1.8 will be dropped.
|
110
|
-
# It's for compatibility with
|
110
|
+
# It's for compatibility with regexp_parser 1.8 and will never be maintained.
|
111
111
|
else
|
112
112
|
def each_escape(node)
|
113
113
|
node.parsed_tree&.traverse&.reduce(0) do |char_class_depth, (event, expr)|
|
@@ -36,7 +36,6 @@ module RuboCop
|
|
36
36
|
# STR
|
37
37
|
class RedundantStringEscape < Base
|
38
38
|
include MatchRange
|
39
|
-
include RangeHelp
|
40
39
|
extend AutoCorrector
|
41
40
|
|
42
41
|
MSG = 'Redundant escape of %<char>s inside string literal.'
|
@@ -64,10 +63,10 @@ module RuboCop
|
|
64
63
|
def str_contents_range(node)
|
65
64
|
if heredoc?(node)
|
66
65
|
node.loc.heredoc_body
|
66
|
+
elsif node.str_type?
|
67
|
+
node.source_range
|
67
68
|
elsif begin_loc_present?(node)
|
68
69
|
contents_range(node)
|
69
|
-
else
|
70
|
-
node.source_range
|
71
70
|
end
|
72
71
|
end
|
73
72
|
|
@@ -167,7 +167,7 @@ module RuboCop
|
|
167
167
|
corrector.insert_before(condition,
|
168
168
|
"#{'!' if node.unless?}#{replace_condition(node.condition)} && ")
|
169
169
|
|
170
|
-
corrector.remove(node.condition
|
170
|
+
corrector.remove(node.condition)
|
171
171
|
corrector.remove(range_with_surrounding_space(node.loc.keyword, newlines: false))
|
172
172
|
corrector.replace(if_branch.loc.keyword, 'if')
|
173
173
|
end
|
@@ -187,7 +187,7 @@ module RuboCop
|
|
187
187
|
return if end_pos > begin_pos
|
188
188
|
|
189
189
|
corrector.replace(range_between(end_pos, begin_pos), '(')
|
190
|
-
corrector.insert_after(condition.last_argument
|
190
|
+
corrector.insert_after(condition.last_argument, ')')
|
191
191
|
end
|
192
192
|
|
193
193
|
def insert_bang(corrector, node, is_modify_form)
|
@@ -29,7 +29,7 @@ module RuboCop
|
|
29
29
|
@parsed_tree&.each_expression(true) { |e| e.origin = origin }
|
30
30
|
end
|
31
31
|
# Please remove this `else` branch when support for regexp_parser 1.8 will be dropped.
|
32
|
-
# It's for compatibility with
|
32
|
+
# It's for compatibility with regexp_parser 1.8 and will never be maintained.
|
33
33
|
else
|
34
34
|
def assign_properties(*)
|
35
35
|
super
|
@@ -28,7 +28,7 @@ module RuboCop
|
|
28
28
|
@expression ||= origin.adjust(begin_pos: ts, end_pos: ts + full_length)
|
29
29
|
end
|
30
30
|
# Please remove this `else` branch when support for regexp_parser 1.8 will be dropped.
|
31
|
-
# It's for compatibility with
|
31
|
+
# It's for compatibility with regexp_parser 1.8 and will never be maintained.
|
32
32
|
else
|
33
33
|
attr_accessor :source
|
34
34
|
|
@@ -61,7 +61,7 @@ module RuboCop
|
|
61
61
|
correctable_count,
|
62
62
|
rainbow,
|
63
63
|
# :safe_autocorrect is a derived option based on several command-line
|
64
|
-
# arguments - see
|
64
|
+
# arguments - see RuboCop::Options#add_autocorrection_options
|
65
65
|
safe_autocorrect: @options[:safe_autocorrect])
|
66
66
|
|
67
67
|
output.puts
|
data/lib/rubocop/options.rb
CHANGED
@@ -182,7 +182,10 @@ module RuboCop
|
|
182
182
|
raise OptionArgumentError, message
|
183
183
|
end
|
184
184
|
|
185
|
-
|
185
|
+
cop_names = list.empty? ? [''] : list.split(',')
|
186
|
+
cop_names.unshift('Lint/Syntax') if option == 'only' && !cop_names.include?('Lint/Syntax')
|
187
|
+
|
188
|
+
@options[:"#{option}"] = cop_names
|
186
189
|
end
|
187
190
|
end
|
188
191
|
|
data/lib/rubocop/result_cache.rb
CHANGED
@@ -86,7 +86,7 @@ module RuboCop
|
|
86
86
|
attr :path
|
87
87
|
|
88
88
|
def initialize(file, team, options, config_store, cache_root = nil)
|
89
|
-
cache_root ||= options[:cache_root]
|
89
|
+
cache_root ||= File.join(options[:cache_root], 'rubocop_cache') if options[:cache_root]
|
90
90
|
cache_root ||= ResultCache.cache_root(config_store)
|
91
91
|
@allow_symlinks_in_cache_location =
|
92
92
|
ResultCache.allow_symlinks_in_cache_location?(config_store)
|
data/lib/rubocop/server/cache.rb
CHANGED
@@ -11,7 +11,7 @@
|
|
11
11
|
#
|
12
12
|
module RuboCop
|
13
13
|
module Server
|
14
|
-
# This module has a helper
|
14
|
+
# This module has a helper method for `RuboCop::Server::SocketReader`.
|
15
15
|
# @api private
|
16
16
|
module Helper
|
17
17
|
def self.redirect(stdin: $stdin, stdout: $stdout, stderr: $stderr, &_block)
|
@@ -21,7 +21,7 @@ module RuboCop
|
|
21
21
|
# We must pass the --color option to preserve this behavior.
|
22
22
|
@args.unshift('--color') unless %w[--color --no-color].any? { |f| @args.include?(f) }
|
23
23
|
status = RuboCop::CLI.new.run(@args)
|
24
|
-
# This status file is read by `rubocop --server` (`RuboCop::Server::
|
24
|
+
# This status file is read by `rubocop --server` (`RuboCop::Server::ClientCommand::Exec`).
|
25
25
|
# so that they use the correct exit code.
|
26
26
|
# Status is 1 when there are any issues, and 0 otherwise.
|
27
27
|
Cache.write_status_file(status)
|
data/lib/rubocop/version.rb
CHANGED
data/lib/rubocop.rb
CHANGED
@@ -480,6 +480,7 @@ require_relative 'rubocop/cop/style/concat_array_literals'
|
|
480
480
|
require_relative 'rubocop/cop/style/conditional_assignment'
|
481
481
|
require_relative 'rubocop/cop/style/constant_visibility'
|
482
482
|
require_relative 'rubocop/cop/style/copyright'
|
483
|
+
require_relative 'rubocop/cop/style/data_inheritance'
|
483
484
|
require_relative 'rubocop/cop/style/date_time'
|
484
485
|
require_relative 'rubocop/cop/style/def_with_parentheses'
|
485
486
|
require_relative 'rubocop/cop/style/dir'
|
@@ -563,6 +564,7 @@ require_relative 'rubocop/cop/style/redundant_fetch_block'
|
|
563
564
|
require_relative 'rubocop/cop/style/redundant_file_extension_in_require'
|
564
565
|
require_relative 'rubocop/cop/style/redundant_heredoc_delimiter_quotes'
|
565
566
|
require_relative 'rubocop/cop/style/redundant_initialize'
|
567
|
+
require_relative 'rubocop/cop/style/redundant_line_continuation'
|
566
568
|
require_relative 'rubocop/cop/style/redundant_self_assignment'
|
567
569
|
require_relative 'rubocop/cop/style/redundant_self_assignment_branch'
|
568
570
|
require_relative 'rubocop/cop/style/require_order'
|
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.49.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: 2023-03
|
13
|
+
date: 2023-04-03 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: json
|
@@ -120,7 +120,7 @@ dependencies:
|
|
120
120
|
requirements:
|
121
121
|
- - ">="
|
122
122
|
- !ruby/object:Gem::Version
|
123
|
-
version: 1.
|
123
|
+
version: 1.28.0
|
124
124
|
- - "<"
|
125
125
|
- !ruby/object:Gem::Version
|
126
126
|
version: '2.0'
|
@@ -130,7 +130,7 @@ dependencies:
|
|
130
130
|
requirements:
|
131
131
|
- - ">="
|
132
132
|
- !ruby/object:Gem::Version
|
133
|
-
version: 1.
|
133
|
+
version: 1.28.0
|
134
134
|
- - "<"
|
135
135
|
- !ruby/object:Gem::Version
|
136
136
|
version: '2.0'
|
@@ -683,6 +683,7 @@ files:
|
|
683
683
|
- lib/rubocop/cop/style/conditional_assignment.rb
|
684
684
|
- lib/rubocop/cop/style/constant_visibility.rb
|
685
685
|
- lib/rubocop/cop/style/copyright.rb
|
686
|
+
- lib/rubocop/cop/style/data_inheritance.rb
|
686
687
|
- lib/rubocop/cop/style/date_time.rb
|
687
688
|
- lib/rubocop/cop/style/def_with_parentheses.rb
|
688
689
|
- lib/rubocop/cop/style/dir.rb
|
@@ -827,6 +828,7 @@ files:
|
|
827
828
|
- lib/rubocop/cop/style/redundant_heredoc_delimiter_quotes.rb
|
828
829
|
- lib/rubocop/cop/style/redundant_initialize.rb
|
829
830
|
- lib/rubocop/cop/style/redundant_interpolation.rb
|
831
|
+
- lib/rubocop/cop/style/redundant_line_continuation.rb
|
830
832
|
- lib/rubocop/cop/style/redundant_parentheses.rb
|
831
833
|
- lib/rubocop/cop/style/redundant_percent_q.rb
|
832
834
|
- lib/rubocop/cop/style/redundant_regexp_character_class.rb
|
@@ -988,7 +990,7 @@ metadata:
|
|
988
990
|
homepage_uri: https://rubocop.org/
|
989
991
|
changelog_uri: https://github.com/rubocop/rubocop/blob/master/CHANGELOG.md
|
990
992
|
source_code_uri: https://github.com/rubocop/rubocop/
|
991
|
-
documentation_uri: https://docs.rubocop.org/rubocop/1.
|
993
|
+
documentation_uri: https://docs.rubocop.org/rubocop/1.49/
|
992
994
|
bug_tracker_uri: https://github.com/rubocop/rubocop/issues
|
993
995
|
rubygems_mfa_required: 'true'
|
994
996
|
post_install_message:
|
@@ -1006,7 +1008,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
1006
1008
|
- !ruby/object:Gem::Version
|
1007
1009
|
version: '0'
|
1008
1010
|
requirements: []
|
1009
|
-
rubygems_version: 3.
|
1011
|
+
rubygems_version: 3.4.6
|
1010
1012
|
signing_key:
|
1011
1013
|
specification_version: 4
|
1012
1014
|
summary: Automatic Ruby code style checking tool.
|