rubocop 1.31.2 → 1.32.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 +23 -0
- data/lib/rubocop/cli.rb +1 -0
- data/lib/rubocop/config.rb +1 -1
- data/lib/rubocop/cop/internal_affairs/useless_restrict_on_send.rb +7 -1
- data/lib/rubocop/cop/layout/line_continuation_leading_space.rb +57 -13
- data/lib/rubocop/cop/layout/line_length.rb +2 -0
- data/lib/rubocop/cop/layout/multiline_method_argument_line_breaks.rb +4 -1
- data/lib/rubocop/cop/layout/multiline_method_parameter_line_breaks.rb +45 -0
- data/lib/rubocop/cop/lint/ambiguous_block_association.rb +7 -0
- data/lib/rubocop/cop/lint/deprecated_class_methods.rb +10 -4
- data/lib/rubocop/cop/lint/non_atomic_file_operation.rb +55 -24
- data/lib/rubocop/cop/lint/number_conversion.rb +7 -1
- data/lib/rubocop/cop/lint/redundant_safe_navigation.rb +7 -0
- data/lib/rubocop/cop/lint/require_range_parentheses.rb +57 -0
- data/lib/rubocop/cop/lint/safe_navigation_chain.rb +35 -1
- data/lib/rubocop/cop/metrics/block_length.rb +1 -0
- data/lib/rubocop/cop/metrics/method_length.rb +1 -0
- data/lib/rubocop/cop/mixin/check_line_breakable.rb +4 -0
- data/lib/rubocop/cop/mixin/percent_array.rb +60 -1
- data/lib/rubocop/cop/naming/predicate_name.rb +8 -0
- data/lib/rubocop/cop/style/class_equality_comparison.rb +22 -0
- data/lib/rubocop/cop/style/empty_else.rb +37 -0
- data/lib/rubocop/cop/style/empty_heredoc.rb +59 -0
- data/lib/rubocop/cop/style/fetch_env_var.rb +10 -177
- data/lib/rubocop/cop/style/format_string_token.rb +6 -0
- data/lib/rubocop/cop/style/if_with_boolean_literal_branches.rb +2 -0
- data/lib/rubocop/cop/style/method_call_without_args_parentheses.rb +12 -0
- data/lib/rubocop/cop/style/nested_parenthesized_calls.rb +9 -0
- data/lib/rubocop/cop/style/numeric_predicate.rb +20 -6
- data/lib/rubocop/cop/style/semicolon.rb +27 -3
- data/lib/rubocop/cop/style/symbol_array.rb +2 -3
- data/lib/rubocop/cop/style/symbol_proc.rb +9 -1
- data/lib/rubocop/cop/style/top_level_method_definition.rb +2 -0
- data/lib/rubocop/cop/style/trivial_accessors.rb +3 -0
- data/lib/rubocop/cop/style/word_array.rb +2 -3
- data/lib/rubocop/options.rb +3 -6
- data/lib/rubocop/rspec/shared_contexts.rb +14 -14
- data/lib/rubocop/rspec/support.rb +14 -0
- data/lib/rubocop/runner.rb +4 -0
- data/lib/rubocop/server/client_command/base.rb +1 -1
- data/lib/rubocop/version.rb +1 -1
- data/lib/rubocop.rb +3 -0
- metadata +8 -5
@@ -64,12 +64,14 @@ module RuboCop
|
|
64
64
|
# Make the obvious check first
|
65
65
|
return unless processed_source.raw_source.include?(';')
|
66
66
|
|
67
|
-
each_semicolon
|
67
|
+
each_semicolon do |line, column, token_before_semicolon|
|
68
|
+
register_semicolon(line, column, false, token_before_semicolon)
|
69
|
+
end
|
68
70
|
end
|
69
71
|
|
70
72
|
def each_semicolon
|
71
73
|
tokens_for_lines.each do |line, tokens|
|
72
|
-
yield line, tokens.last.column if tokens.last.semicolon?
|
74
|
+
yield line, tokens.last.column, tokens[-2] if tokens.last.semicolon?
|
73
75
|
yield line, tokens.first.column if tokens.first.semicolon?
|
74
76
|
end
|
75
77
|
end
|
@@ -78,13 +80,21 @@ module RuboCop
|
|
78
80
|
processed_source.tokens.group_by(&:line)
|
79
81
|
end
|
80
82
|
|
81
|
-
def register_semicolon(line, column, after_expression)
|
83
|
+
def register_semicolon(line, column, after_expression, token_before_semicolon = nil)
|
82
84
|
range = source_range(processed_source.buffer, line, column)
|
83
85
|
|
84
86
|
add_offense(range) do |corrector|
|
85
87
|
if after_expression
|
86
88
|
corrector.replace(range, "\n")
|
87
89
|
else
|
90
|
+
# Prevents becoming one range instance with subsequent line when endless range
|
91
|
+
# without parentheses.
|
92
|
+
# See: https://github.com/rubocop/rubocop/issues/10791
|
93
|
+
if token_before_semicolon&.regexp_dots?
|
94
|
+
range_node = find_range_node(token_before_semicolon)
|
95
|
+
corrector.wrap(range_node, '(', ')') if range_node
|
96
|
+
end
|
97
|
+
|
88
98
|
corrector.remove(range)
|
89
99
|
end
|
90
100
|
end
|
@@ -103,6 +113,20 @@ module RuboCop
|
|
103
113
|
yield Regexp.last_match.begin(0)
|
104
114
|
end
|
105
115
|
end
|
116
|
+
|
117
|
+
def find_range_node(token_before_semicolon)
|
118
|
+
range_nodes.detect do |range_node|
|
119
|
+
range_node.source_range.contains?(token_before_semicolon.pos)
|
120
|
+
end
|
121
|
+
end
|
122
|
+
|
123
|
+
def range_nodes
|
124
|
+
return @range_nodes if instance_variable_defined?(:@range_nodes)
|
125
|
+
|
126
|
+
ast = processed_source.ast
|
127
|
+
@range_nodes = ast.range_type? ? [ast] : []
|
128
|
+
@range_nodes.concat(ast.each_descendant(:irange, :erange).to_a)
|
129
|
+
end
|
106
130
|
end
|
107
131
|
end
|
108
132
|
end
|
@@ -39,7 +39,7 @@ module RuboCop
|
|
39
39
|
minimum_target_ruby_version 2.0
|
40
40
|
|
41
41
|
PERCENT_MSG = 'Use `%i` or `%I` for an array of symbols.'
|
42
|
-
ARRAY_MSG = 'Use
|
42
|
+
ARRAY_MSG = 'Use %<prefer>s for an array of symbols.'
|
43
43
|
|
44
44
|
class << self
|
45
45
|
attr_accessor :largest_brackets
|
@@ -74,8 +74,7 @@ module RuboCop
|
|
74
74
|
to_symbol_literal(c.value.to_s)
|
75
75
|
end
|
76
76
|
end
|
77
|
-
|
78
|
-
"[#{syms.join(', ')}]"
|
77
|
+
build_bracketed_array_with_appropriate_whitespace(elements: syms, node: node)
|
79
78
|
end
|
80
79
|
|
81
80
|
def to_symbol_literal(string)
|
@@ -7,6 +7,8 @@ module RuboCop
|
|
7
7
|
#
|
8
8
|
# If you prefer a style that allows block for method with arguments,
|
9
9
|
# please set `true` to `AllowMethodsWithArguments`.
|
10
|
+
# respond_to , and `define_method?` methods are ignored by default.
|
11
|
+
# These are customizable with `IgnoredMethods` option.
|
10
12
|
#
|
11
13
|
# @safety
|
12
14
|
# This cop is unsafe because `proc`s and blocks work differently
|
@@ -68,6 +70,12 @@ module RuboCop
|
|
68
70
|
# s.upcase # some comment
|
69
71
|
# # some comment
|
70
72
|
# end
|
73
|
+
#
|
74
|
+
# @example IgnoredMethods: [respond_to, define_method] (default)
|
75
|
+
# # good
|
76
|
+
# respond_to { |foo| foo.bar }
|
77
|
+
# define_method(:foo) { |foo| foo.bar }
|
78
|
+
#
|
71
79
|
class SymbolProc < Base
|
72
80
|
include CommentsHelp
|
73
81
|
include RangeHelp
|
@@ -81,7 +89,7 @@ module RuboCop
|
|
81
89
|
def_node_matcher :proc_node?, '(send (const {nil? cbase} :Proc) :new)'
|
82
90
|
|
83
91
|
# @!method symbol_proc_receiver?(node)
|
84
|
-
def_node_matcher :symbol_proc_receiver?, '{(
|
92
|
+
def_node_matcher :symbol_proc_receiver?, '{(call ...) (super ...) zsuper}'
|
85
93
|
|
86
94
|
# @!method symbol_proc?(node)
|
87
95
|
def_node_matcher :symbol_proc?, <<~PATTERN
|
@@ -5,6 +5,9 @@ module RuboCop
|
|
5
5
|
module Style
|
6
6
|
# Looks for trivial reader/writer methods, that could
|
7
7
|
# have been created with the attr_* family of functions automatically.
|
8
|
+
# `to_ary`, `to_a`, `to_c`, `to_enum`, `to_h`, `to_hash`, `to_i`, `to_int`, `to_io`,
|
9
|
+
# `to_open`, `to_path`, `to_proc`, `to_r`, `to_regexp`, `to_str`, `to_s`, and `to_sym` methods
|
10
|
+
# are allowed by default. These are customizable with `AllowedMethods` option.
|
8
11
|
#
|
9
12
|
# @example
|
10
13
|
# # bad
|
@@ -44,7 +44,7 @@ module RuboCop
|
|
44
44
|
extend AutoCorrector
|
45
45
|
|
46
46
|
PERCENT_MSG = 'Use `%w` or `%W` for an array of words.'
|
47
|
-
ARRAY_MSG = 'Use
|
47
|
+
ARRAY_MSG = 'Use %<prefer>s for an array of words.'
|
48
48
|
|
49
49
|
class << self
|
50
50
|
attr_accessor :largest_brackets
|
@@ -92,8 +92,7 @@ module RuboCop
|
|
92
92
|
to_string_literal(word.children[0])
|
93
93
|
end
|
94
94
|
end
|
95
|
-
|
96
|
-
"[#{words.join(', ')}]"
|
95
|
+
build_bracketed_array_with_appropriate_whitespace(elements: words, node: node)
|
97
96
|
end
|
98
97
|
end
|
99
98
|
end
|
data/lib/rubocop/options.rb
CHANGED
@@ -421,12 +421,9 @@ module RuboCop
|
|
421
421
|
end
|
422
422
|
|
423
423
|
def invalid_arguments_for_parallel
|
424
|
-
[('--auto-gen-config'
|
425
|
-
('-F/--fail-fast'
|
426
|
-
('
|
427
|
-
('-a/--autocorrect' if @options.key?(:safe_autocorrect)),
|
428
|
-
('-A/--autocorrect-all' if @options.key?(:autocorrect_all)),
|
429
|
-
('--cache false' if @options > { cache: 'false' })].compact
|
424
|
+
[('--auto-gen-config' if @options.key?(:auto_gen_config)),
|
425
|
+
('-F/--fail-fast' if @options.key?(:fail_fast)),
|
426
|
+
('--cache false' if @options > { cache: 'false' })].compact
|
430
427
|
end
|
431
428
|
|
432
429
|
def only_includes_redundant_disable?
|
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
require 'tmpdir'
|
4
4
|
|
5
|
-
RSpec.shared_context 'isolated environment'
|
5
|
+
RSpec.shared_context 'isolated environment' do
|
6
6
|
around do |example|
|
7
7
|
Dir.mktmpdir do |tmpdir|
|
8
8
|
original_home = Dir.home
|
@@ -38,7 +38,7 @@ RSpec.shared_context 'isolated environment', :isolated_environment do
|
|
38
38
|
end
|
39
39
|
end
|
40
40
|
|
41
|
-
RSpec.shared_context 'maintain registry'
|
41
|
+
RSpec.shared_context 'maintain registry' do
|
42
42
|
around(:each) { |example| RuboCop::Cop::Registry.with_temporary_global { example.run } }
|
43
43
|
|
44
44
|
def stub_cop_class(name, inherit: RuboCop::Cop::Base, &block)
|
@@ -49,7 +49,7 @@ RSpec.shared_context 'maintain registry', :restore_registry do
|
|
49
49
|
end
|
50
50
|
|
51
51
|
# This context assumes nothing and defines `cop`, among others.
|
52
|
-
RSpec.shared_context 'config'
|
52
|
+
RSpec.shared_context 'config' do # rubocop:disable Metrics/BlockLength
|
53
53
|
### Meant to be overridden at will
|
54
54
|
|
55
55
|
let(:cop_class) do
|
@@ -116,46 +116,46 @@ RSpec.shared_context 'mock console output' do
|
|
116
116
|
end
|
117
117
|
end
|
118
118
|
|
119
|
-
RSpec.shared_context 'ruby 2.0'
|
119
|
+
RSpec.shared_context 'ruby 2.0' do
|
120
120
|
let(:ruby_version) { 2.0 }
|
121
121
|
end
|
122
122
|
|
123
|
-
RSpec.shared_context 'ruby 2.1'
|
123
|
+
RSpec.shared_context 'ruby 2.1' do
|
124
124
|
let(:ruby_version) { 2.1 }
|
125
125
|
end
|
126
126
|
|
127
|
-
RSpec.shared_context 'ruby 2.2'
|
127
|
+
RSpec.shared_context 'ruby 2.2' do
|
128
128
|
let(:ruby_version) { 2.2 }
|
129
129
|
end
|
130
130
|
|
131
|
-
RSpec.shared_context 'ruby 2.3'
|
131
|
+
RSpec.shared_context 'ruby 2.3' do
|
132
132
|
let(:ruby_version) { 2.3 }
|
133
133
|
end
|
134
134
|
|
135
|
-
RSpec.shared_context 'ruby 2.4'
|
135
|
+
RSpec.shared_context 'ruby 2.4' do
|
136
136
|
let(:ruby_version) { 2.4 }
|
137
137
|
end
|
138
138
|
|
139
|
-
RSpec.shared_context 'ruby 2.5'
|
139
|
+
RSpec.shared_context 'ruby 2.5' do
|
140
140
|
let(:ruby_version) { 2.5 }
|
141
141
|
end
|
142
142
|
|
143
|
-
RSpec.shared_context 'ruby 2.6'
|
143
|
+
RSpec.shared_context 'ruby 2.6' do
|
144
144
|
let(:ruby_version) { 2.6 }
|
145
145
|
end
|
146
146
|
|
147
|
-
RSpec.shared_context 'ruby 2.7'
|
147
|
+
RSpec.shared_context 'ruby 2.7' do
|
148
148
|
let(:ruby_version) { 2.7 }
|
149
149
|
end
|
150
150
|
|
151
|
-
RSpec.shared_context 'ruby 3.0'
|
151
|
+
RSpec.shared_context 'ruby 3.0' do
|
152
152
|
let(:ruby_version) { 3.0 }
|
153
153
|
end
|
154
154
|
|
155
|
-
RSpec.shared_context 'ruby 3.1'
|
155
|
+
RSpec.shared_context 'ruby 3.1' do
|
156
156
|
let(:ruby_version) { 3.1 }
|
157
157
|
end
|
158
158
|
|
159
|
-
RSpec.shared_context 'ruby 3.2'
|
159
|
+
RSpec.shared_context 'ruby 3.2' do
|
160
160
|
let(:ruby_version) { 3.2 }
|
161
161
|
end
|
@@ -11,4 +11,18 @@ require_relative 'parallel_formatter'
|
|
11
11
|
RSpec.configure do |config|
|
12
12
|
config.include CopHelper
|
13
13
|
config.include HostEnvironmentSimulatorHelper
|
14
|
+
config.include_context 'config', :config
|
15
|
+
config.include_context 'isolated environment', :isolated_environment
|
16
|
+
config.include_context 'maintain registry', :restore_registry
|
17
|
+
config.include_context 'ruby 2.0', :ruby20
|
18
|
+
config.include_context 'ruby 2.1', :ruby21
|
19
|
+
config.include_context 'ruby 2.2', :ruby22
|
20
|
+
config.include_context 'ruby 2.3', :ruby23
|
21
|
+
config.include_context 'ruby 2.4', :ruby24
|
22
|
+
config.include_context 'ruby 2.5', :ruby25
|
23
|
+
config.include_context 'ruby 2.6', :ruby26
|
24
|
+
config.include_context 'ruby 2.7', :ruby27
|
25
|
+
config.include_context 'ruby 3.0', :ruby30
|
26
|
+
config.include_context 'ruby 3.1', :ruby31
|
27
|
+
config.include_context 'ruby 3.2', :ruby32
|
14
28
|
end
|
data/lib/rubocop/runner.rb
CHANGED
@@ -63,8 +63,12 @@ module RuboCop
|
|
63
63
|
# Warms up the RuboCop cache by forking a suitable number of RuboCop
|
64
64
|
# instances that each inspects its allotted group of files.
|
65
65
|
def warm_cache(target_files)
|
66
|
+
saved_options = @options.dup
|
66
67
|
puts 'Running parallel inspection' if @options[:debug]
|
68
|
+
%i[autocorrect safe_autocorrect].each { |opt| @options[opt] = false }
|
67
69
|
Parallel.each(target_files) { |target_file| file_offenses(target_file) }
|
70
|
+
ensure
|
71
|
+
@options = saved_options
|
68
72
|
end
|
69
73
|
|
70
74
|
def find_target_files(paths)
|
@@ -29,7 +29,7 @@ module RuboCop
|
|
29
29
|
socket.puts [Cache.token_path.read, Dir.pwd, command, *args].shelljoin
|
30
30
|
socket.write body
|
31
31
|
socket.close_write
|
32
|
-
$stdout.write socket.
|
32
|
+
$stdout.write socket.readpartial(4096) until socket.eof?
|
33
33
|
end
|
34
34
|
end
|
35
35
|
|
data/lib/rubocop/version.rb
CHANGED
data/lib/rubocop.rb
CHANGED
@@ -233,6 +233,7 @@ require_relative 'rubocop/cop/layout/multiline_method_argument_line_breaks'
|
|
233
233
|
require_relative 'rubocop/cop/layout/multiline_method_call_brace_layout'
|
234
234
|
require_relative 'rubocop/cop/layout/multiline_method_call_indentation'
|
235
235
|
require_relative 'rubocop/cop/layout/multiline_method_definition_brace_layout'
|
236
|
+
require_relative 'rubocop/cop/layout/multiline_method_parameter_line_breaks'
|
236
237
|
require_relative 'rubocop/cop/layout/multiline_operation_indentation'
|
237
238
|
require_relative 'rubocop/cop/layout/parameter_alignment'
|
238
239
|
require_relative 'rubocop/cop/layout/redundant_line_break'
|
@@ -356,6 +357,7 @@ require_relative 'rubocop/cop/lint/redundant_with_object'
|
|
356
357
|
require_relative 'rubocop/cop/lint/refinement_import_methods'
|
357
358
|
require_relative 'rubocop/cop/lint/regexp_as_condition'
|
358
359
|
require_relative 'rubocop/cop/lint/require_parentheses'
|
360
|
+
require_relative 'rubocop/cop/lint/require_range_parentheses'
|
359
361
|
require_relative 'rubocop/cop/lint/require_relative_self_path'
|
360
362
|
require_relative 'rubocop/cop/lint/rescue_exception'
|
361
363
|
require_relative 'rubocop/cop/lint/rescue_type'
|
@@ -479,6 +481,7 @@ require_relative 'rubocop/cop/style/each_with_object'
|
|
479
481
|
require_relative 'rubocop/cop/style/empty_block_parameter'
|
480
482
|
require_relative 'rubocop/cop/style/empty_case_condition'
|
481
483
|
require_relative 'rubocop/cop/style/empty_else'
|
484
|
+
require_relative 'rubocop/cop/style/empty_heredoc'
|
482
485
|
require_relative 'rubocop/cop/style/empty_lambda_parameter'
|
483
486
|
require_relative 'rubocop/cop/style/empty_literal'
|
484
487
|
require_relative 'rubocop/cop/style/empty_method'
|
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.32.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: 2022-07-
|
13
|
+
date: 2022-07-21 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.19.1
|
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.19.1
|
134
134
|
- - "<"
|
135
135
|
- !ruby/object:Gem::Version
|
136
136
|
version: '2.0'
|
@@ -367,6 +367,7 @@ files:
|
|
367
367
|
- lib/rubocop/cop/layout/multiline_method_call_brace_layout.rb
|
368
368
|
- lib/rubocop/cop/layout/multiline_method_call_indentation.rb
|
369
369
|
- lib/rubocop/cop/layout/multiline_method_definition_brace_layout.rb
|
370
|
+
- lib/rubocop/cop/layout/multiline_method_parameter_line_breaks.rb
|
370
371
|
- lib/rubocop/cop/layout/multiline_operation_indentation.rb
|
371
372
|
- lib/rubocop/cop/layout/parameter_alignment.rb
|
372
373
|
- lib/rubocop/cop/layout/redundant_line_break.rb
|
@@ -491,6 +492,7 @@ files:
|
|
491
492
|
- lib/rubocop/cop/lint/refinement_import_methods.rb
|
492
493
|
- lib/rubocop/cop/lint/regexp_as_condition.rb
|
493
494
|
- lib/rubocop/cop/lint/require_parentheses.rb
|
495
|
+
- lib/rubocop/cop/lint/require_range_parentheses.rb
|
494
496
|
- lib/rubocop/cop/lint/require_relative_self_path.rb
|
495
497
|
- lib/rubocop/cop/lint/rescue_exception.rb
|
496
498
|
- lib/rubocop/cop/lint/rescue_type.rb
|
@@ -696,6 +698,7 @@ files:
|
|
696
698
|
- lib/rubocop/cop/style/empty_block_parameter.rb
|
697
699
|
- lib/rubocop/cop/style/empty_case_condition.rb
|
698
700
|
- lib/rubocop/cop/style/empty_else.rb
|
701
|
+
- lib/rubocop/cop/style/empty_heredoc.rb
|
699
702
|
- lib/rubocop/cop/style/empty_lambda_parameter.rb
|
700
703
|
- lib/rubocop/cop/style/empty_literal.rb
|
701
704
|
- lib/rubocop/cop/style/empty_method.rb
|
@@ -968,7 +971,7 @@ metadata:
|
|
968
971
|
homepage_uri: https://rubocop.org/
|
969
972
|
changelog_uri: https://github.com/rubocop/rubocop/blob/master/CHANGELOG.md
|
970
973
|
source_code_uri: https://github.com/rubocop/rubocop/
|
971
|
-
documentation_uri: https://docs.rubocop.org/rubocop/1.
|
974
|
+
documentation_uri: https://docs.rubocop.org/rubocop/1.32/
|
972
975
|
bug_tracker_uri: https://github.com/rubocop/rubocop/issues
|
973
976
|
rubygems_mfa_required: 'true'
|
974
977
|
post_install_message:
|