rubocop 1.75.8 → 1.81.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 +20 -16
- data/config/default.yml +117 -26
- data/config/obsoletion.yml +6 -3
- data/exe/rubocop +1 -8
- data/lib/rubocop/cli/command/auto_generate_config.rb +2 -2
- data/lib/rubocop/cli.rb +18 -3
- data/lib/rubocop/config_loader.rb +4 -39
- data/lib/rubocop/config_store.rb +5 -0
- data/lib/rubocop/cop/autocorrect_logic.rb +4 -4
- data/lib/rubocop/cop/bundler/ordered_gems.rb +1 -1
- data/lib/rubocop/cop/correctors/alignment_corrector.rb +7 -4
- data/lib/rubocop/cop/correctors/for_to_each_corrector.rb +7 -2
- data/lib/rubocop/cop/correctors/parentheses_corrector.rb +5 -2
- data/lib/rubocop/cop/gemspec/attribute_assignment.rb +91 -0
- data/lib/rubocop/cop/gemspec/duplicated_assignment.rb +0 -22
- data/lib/rubocop/cop/gemspec/ordered_dependencies.rb +1 -1
- data/lib/rubocop/cop/gemspec/require_mfa.rb +15 -1
- data/lib/rubocop/cop/internal_affairs/example_description.rb +1 -1
- data/lib/rubocop/cop/internal_affairs/node_matcher_directive.rb +4 -4
- data/lib/rubocop/cop/internal_affairs/node_pattern_groups.rb +4 -1
- data/lib/rubocop/cop/internal_affairs/node_type_group.rb +3 -2
- data/lib/rubocop/cop/internal_affairs/on_send_without_on_csend.rb +1 -1
- data/lib/rubocop/cop/internal_affairs/useless_restrict_on_send.rb +1 -1
- data/lib/rubocop/cop/layout/class_structure.rb +1 -1
- data/lib/rubocop/cop/layout/closing_parenthesis_indentation.rb +1 -1
- data/lib/rubocop/cop/layout/dot_position.rb +1 -1
- data/lib/rubocop/cop/layout/empty_line_between_defs.rb +30 -12
- data/lib/rubocop/cop/layout/empty_lines_after_module_inclusion.rb +101 -0
- data/lib/rubocop/cop/layout/empty_lines_around_access_modifier.rb +1 -1
- data/lib/rubocop/cop/layout/empty_lines_around_arguments.rb +8 -29
- data/lib/rubocop/cop/layout/empty_lines_around_class_body.rb +1 -1
- data/lib/rubocop/cop/layout/line_length.rb +35 -6
- data/lib/rubocop/cop/layout/multiline_operation_indentation.rb +8 -4
- data/lib/rubocop/cop/layout/rescue_ensure_alignment.rb +8 -0
- data/lib/rubocop/cop/layout/space_around_keyword.rb +6 -1
- data/lib/rubocop/cop/layout/space_around_operators.rb +8 -0
- data/lib/rubocop/cop/layout/space_before_brackets.rb +2 -9
- data/lib/rubocop/cop/layout/space_inside_array_literal_brackets.rb +7 -2
- data/lib/rubocop/cop/layout/trailing_whitespace.rb +1 -1
- data/lib/rubocop/cop/lint/ambiguous_range.rb +5 -0
- data/lib/rubocop/cop/lint/deprecated_open_ssl_constant.rb +4 -1
- data/lib/rubocop/cop/lint/duplicate_methods.rb +25 -4
- data/lib/rubocop/cop/lint/duplicate_regexp_character_class_element.rb +5 -42
- data/lib/rubocop/cop/lint/empty_interpolation.rb +3 -1
- data/lib/rubocop/cop/lint/float_comparison.rb +4 -4
- data/lib/rubocop/cop/lint/identity_comparison.rb +19 -15
- data/lib/rubocop/cop/lint/literal_as_condition.rb +34 -28
- data/lib/rubocop/cop/lint/missing_cop_enable_directive.rb +1 -2
- data/lib/rubocop/cop/lint/numeric_operation_with_constant_result.rb +1 -0
- data/lib/rubocop/cop/lint/redundant_regexp_quantifiers.rb +1 -1
- data/lib/rubocop/cop/lint/redundant_safe_navigation.rb +101 -2
- data/lib/rubocop/cop/lint/redundant_type_conversion.rb +4 -4
- data/lib/rubocop/cop/lint/require_range_parentheses.rb +1 -1
- data/lib/rubocop/cop/lint/rescue_type.rb +1 -1
- data/lib/rubocop/cop/lint/safe_navigation_chain.rb +4 -4
- data/lib/rubocop/cop/lint/self_assignment.rb +30 -4
- data/lib/rubocop/cop/lint/shadowed_argument.rb +7 -7
- data/lib/rubocop/cop/lint/shadowing_outer_local_variable.rb +5 -0
- data/lib/rubocop/cop/lint/uri_escape_unescape.rb +2 -0
- data/lib/rubocop/cop/lint/useless_access_modifier.rb +29 -4
- data/lib/rubocop/cop/lint/useless_default_value_argument.rb +90 -0
- data/lib/rubocop/cop/lint/useless_numeric_operation.rb +1 -0
- data/lib/rubocop/cop/lint/useless_or.rb +98 -0
- data/lib/rubocop/cop/lint/useless_ruby2_keywords.rb +3 -3
- data/lib/rubocop/cop/lint/utils/nil_receiver_checker.rb +121 -0
- data/lib/rubocop/cop/lint/void.rb +7 -0
- data/lib/rubocop/cop/message_annotator.rb +1 -1
- data/lib/rubocop/cop/mixin/alignment.rb +1 -1
- data/lib/rubocop/cop/mixin/check_line_breakable.rb +1 -1
- data/lib/rubocop/cop/mixin/end_keyword_alignment.rb +1 -7
- data/lib/rubocop/cop/mixin/frozen_string_literal.rb +1 -1
- data/lib/rubocop/cop/mixin/gemspec_help.rb +22 -0
- data/lib/rubocop/cop/mixin/line_length_help.rb +24 -8
- data/lib/rubocop/cop/mixin/ordered_gem_node.rb +1 -1
- data/lib/rubocop/cop/mixin/trailing_comma.rb +1 -1
- data/lib/rubocop/cop/naming/file_name.rb +2 -2
- data/lib/rubocop/cop/naming/method_name.rb +127 -13
- data/lib/rubocop/cop/naming/predicate_method.rb +319 -0
- data/lib/rubocop/cop/naming/{predicate_name.rb → predicate_prefix.rb} +4 -4
- data/lib/rubocop/cop/security/eval.rb +2 -1
- data/lib/rubocop/cop/security/open.rb +1 -0
- data/lib/rubocop/cop/style/access_modifier_declarations.rb +1 -1
- data/lib/rubocop/cop/style/accessor_grouping.rb +13 -1
- data/lib/rubocop/cop/style/arguments_forwarding.rb +11 -17
- data/lib/rubocop/cop/style/array_intersect.rb +98 -34
- data/lib/rubocop/cop/style/array_intersect_with_single_element.rb +47 -0
- data/lib/rubocop/cop/style/bitwise_predicate.rb +8 -1
- data/lib/rubocop/cop/style/block_delimiters.rb +1 -1
- data/lib/rubocop/cop/style/case_like_if.rb +1 -1
- data/lib/rubocop/cop/style/collection_querying.rb +167 -0
- data/lib/rubocop/cop/style/conditional_assignment.rb +4 -2
- data/lib/rubocop/cop/style/dig_chain.rb +1 -1
- data/lib/rubocop/cop/style/double_negation.rb +1 -1
- data/lib/rubocop/cop/style/empty_string_inside_interpolation.rb +100 -0
- data/lib/rubocop/cop/style/explicit_block_argument.rb +1 -1
- data/lib/rubocop/cop/style/exponential_notation.rb +3 -2
- data/lib/rubocop/cop/style/fetch_env_var.rb +32 -6
- data/lib/rubocop/cop/style/hash_conversion.rb +16 -8
- data/lib/rubocop/cop/style/hash_syntax.rb +1 -1
- data/lib/rubocop/cop/style/if_unless_modifier.rb +13 -6
- data/lib/rubocop/cop/style/infinite_loop.rb +1 -1
- data/lib/rubocop/cop/style/inverse_methods.rb +1 -1
- data/lib/rubocop/cop/style/it_assignment.rb +69 -12
- data/lib/rubocop/cop/style/it_block_parameter.rb +36 -15
- data/lib/rubocop/cop/style/map_to_hash.rb +1 -3
- data/lib/rubocop/cop/style/map_to_set.rb +1 -3
- data/lib/rubocop/cop/style/method_call_with_args_parentheses/omit_parentheses.rb +4 -6
- data/lib/rubocop/cop/style/method_call_with_args_parentheses.rb +16 -0
- data/lib/rubocop/cop/style/min_max_comparison.rb +13 -5
- data/lib/rubocop/cop/style/nil_comparison.rb +9 -7
- data/lib/rubocop/cop/style/parallel_assignment.rb +32 -20
- data/lib/rubocop/cop/style/redundant_array_flatten.rb +50 -0
- data/lib/rubocop/cop/style/redundant_begin.rb +34 -0
- data/lib/rubocop/cop/style/redundant_condition.rb +1 -1
- data/lib/rubocop/cop/style/redundant_exception.rb +1 -1
- data/lib/rubocop/cop/style/redundant_fetch_block.rb +1 -9
- data/lib/rubocop/cop/style/redundant_format.rb +18 -3
- data/lib/rubocop/cop/style/redundant_freeze.rb +1 -1
- data/lib/rubocop/cop/style/redundant_interpolation.rb +1 -1
- data/lib/rubocop/cop/style/redundant_line_continuation.rb +1 -1
- data/lib/rubocop/cop/style/redundant_parentheses.rb +55 -16
- data/lib/rubocop/cop/style/redundant_regexp_argument.rb +4 -0
- data/lib/rubocop/cop/style/redundant_regexp_escape.rb +8 -0
- data/lib/rubocop/cop/style/redundant_self.rb +8 -5
- data/lib/rubocop/cop/style/safe_navigation.rb +44 -12
- data/lib/rubocop/cop/style/single_line_methods.rb +7 -4
- data/lib/rubocop/cop/style/sole_nested_conditional.rb +32 -2
- data/lib/rubocop/cop/style/stabby_lambda_parentheses.rb +1 -1
- data/lib/rubocop/cop/style/string_concatenation.rb +17 -13
- data/lib/rubocop/cop/style/symbol_array.rb +1 -1
- data/lib/rubocop/cop/style/symbol_proc.rb +1 -1
- data/lib/rubocop/cop/style/trailing_comma_in_arguments.rb +45 -0
- data/lib/rubocop/cop/style/trailing_comma_in_block_args.rb +1 -1
- data/lib/rubocop/cop/style/unless_else.rb +10 -9
- data/lib/rubocop/cop/utils/format_string.rb +10 -0
- data/lib/rubocop/cop/variable_force/variable.rb +1 -1
- data/lib/rubocop/cop/variable_force.rb +25 -8
- data/lib/rubocop/cops_documentation_generator.rb +1 -0
- data/lib/rubocop/formatter/disabled_config_formatter.rb +18 -5
- data/lib/rubocop/formatter/fuubar_style_formatter.rb +1 -1
- data/lib/rubocop/formatter/markdown_formatter.rb +1 -0
- data/lib/rubocop/formatter/offense_count_formatter.rb +1 -1
- data/lib/rubocop/formatter/pacman_formatter.rb +1 -0
- data/lib/rubocop/lsp/diagnostic.rb +25 -24
- data/lib/rubocop/lsp/routes.rb +65 -9
- data/lib/rubocop/lsp/runtime.rb +2 -2
- data/lib/rubocop/lsp/server.rb +2 -2
- data/lib/rubocop/lsp/stdin_runner.rb +0 -16
- data/lib/rubocop/pending_cops_reporter.rb +56 -0
- data/lib/rubocop/result_cache.rb +14 -12
- data/lib/rubocop/rspec/expect_offense.rb +9 -3
- data/lib/rubocop/runner.rb +6 -4
- data/lib/rubocop/server/cache.rb +4 -2
- data/lib/rubocop/server/client_command/base.rb +10 -0
- data/lib/rubocop/server/client_command/exec.rb +2 -1
- data/lib/rubocop/server/client_command/start.rb +11 -1
- data/lib/rubocop/target_finder.rb +9 -9
- data/lib/rubocop/target_ruby.rb +10 -1
- data/lib/rubocop/version.rb +1 -1
- data/lib/rubocop.rb +12 -1
- data/lib/ruby_lsp/rubocop/addon.rb +25 -10
- data/lib/ruby_lsp/rubocop/runtime_adapter.rb +49 -15
- metadata +22 -8
data/lib/rubocop/runner.rb
CHANGED
@@ -273,7 +273,8 @@ module RuboCop
|
|
273
273
|
end
|
274
274
|
|
275
275
|
def do_inspection_loop(file)
|
276
|
-
|
276
|
+
# We can reuse the prism result since the source did not change yet.
|
277
|
+
processed_source = get_processed_source(file, @prism_result)
|
277
278
|
# This variable is 2d array used to track corrected offenses after each
|
278
279
|
# inspection iteration. This is used to output meaningful infinite loop
|
279
280
|
# error message.
|
@@ -295,7 +296,8 @@ module RuboCop
|
|
295
296
|
# loop if we find any.
|
296
297
|
break unless updated_source_file
|
297
298
|
|
298
|
-
|
299
|
+
# Autocorrect has happened, don't use the prism result since it is stale.
|
300
|
+
processed_source = get_processed_source(file, nil)
|
299
301
|
end
|
300
302
|
|
301
303
|
# Return summary of corrected offenses after all iterations
|
@@ -482,7 +484,7 @@ module RuboCop
|
|
482
484
|
end
|
483
485
|
|
484
486
|
# rubocop:disable Metrics/MethodLength
|
485
|
-
def get_processed_source(file)
|
487
|
+
def get_processed_source(file, prism_result)
|
486
488
|
config = @config_store.for_file(file)
|
487
489
|
ruby_version = config.target_ruby_version
|
488
490
|
parser_engine = config.parser_engine
|
@@ -493,7 +495,7 @@ module RuboCop
|
|
493
495
|
ruby_version,
|
494
496
|
file,
|
495
497
|
parser_engine: parser_engine,
|
496
|
-
prism_result:
|
498
|
+
prism_result: prism_result
|
497
499
|
)
|
498
500
|
else
|
499
501
|
begin
|
data/lib/rubocop/server/cache.rb
CHANGED
@@ -46,12 +46,14 @@ module RuboCop
|
|
46
46
|
end
|
47
47
|
|
48
48
|
# rubocop:disable Metrics/AbcSize
|
49
|
-
def restart_key
|
49
|
+
def restart_key(args_config_file_path: nil)
|
50
50
|
lockfile_path = LOCKFILE_NAMES.map do |lockfile_name|
|
51
51
|
Pathname(project_dir).join(lockfile_name)
|
52
52
|
end.find(&:exist?)
|
53
53
|
version_data = lockfile_path&.read || RuboCop::Version::STRING
|
54
|
-
config_data = Pathname(
|
54
|
+
config_data = Pathname(
|
55
|
+
args_config_file_path || ConfigFinder.find_config_path(Dir.pwd)
|
56
|
+
).read
|
55
57
|
yaml = load_erb_templated_yaml(config_data)
|
56
58
|
|
57
59
|
inherit_from_data = inherit_from_data(yaml)
|
@@ -38,6 +38,16 @@ module RuboCop
|
|
38
38
|
warn 'RuboCop server is not running.' unless running
|
39
39
|
end
|
40
40
|
end
|
41
|
+
|
42
|
+
class << self
|
43
|
+
def args_config_file_path
|
44
|
+
first_args_config_key_index = ARGV.index { |value| ['-c', '--config'].include?(value) }
|
45
|
+
|
46
|
+
return if first_args_config_key_index.nil?
|
47
|
+
|
48
|
+
ARGV[first_args_config_key_index + 1]
|
49
|
+
end
|
50
|
+
end
|
41
51
|
end
|
42
52
|
end
|
43
53
|
end
|
@@ -34,7 +34,7 @@ module RuboCop
|
|
34
34
|
exit 0
|
35
35
|
end
|
36
36
|
|
37
|
-
|
37
|
+
write_version_file
|
38
38
|
|
39
39
|
host = ENV.fetch('RUBOCOP_SERVER_HOST', '127.0.0.1')
|
40
40
|
port = ENV.fetch('RUBOCOP_SERVER_PORT', 0)
|
@@ -42,6 +42,16 @@ module RuboCop
|
|
42
42
|
Server::Core.new.start(host, port, detach: @detach)
|
43
43
|
end
|
44
44
|
end
|
45
|
+
|
46
|
+
private
|
47
|
+
|
48
|
+
def write_version_file
|
49
|
+
Cache.write_version_file(
|
50
|
+
Cache.restart_key(
|
51
|
+
args_config_file_path: self.class.args_config_file_path
|
52
|
+
)
|
53
|
+
)
|
54
|
+
end
|
45
55
|
end
|
46
56
|
end
|
47
57
|
end
|
@@ -42,14 +42,12 @@ module RuboCop
|
|
42
42
|
# Support Windows: Backslashes from command-line -> forward slashes
|
43
43
|
base_dir = base_dir.gsub(File::ALT_SEPARATOR, File::SEPARATOR) if File::ALT_SEPARATOR
|
44
44
|
all_files = find_files(base_dir, File::FNM_DOTMATCH)
|
45
|
-
# use file.include? for performance optimization
|
46
|
-
hidden_files = all_files.select { |file| file.include?(HIDDEN_PATH_SUBSTRING) }.sort
|
47
45
|
base_dir_config = @config_store.for(base_dir)
|
48
46
|
|
49
|
-
target_files = if
|
47
|
+
target_files = if hidden_path?(base_dir)
|
50
48
|
all_files.select { |file| ruby_file?(file) }
|
51
49
|
else
|
52
|
-
all_files.select { |file| to_inspect?(file,
|
50
|
+
all_files.select { |file| to_inspect?(file, base_dir_config) }
|
53
51
|
end
|
54
52
|
|
55
53
|
target_files.sort_by!(&order)
|
@@ -74,18 +72,20 @@ module RuboCop
|
|
74
72
|
|
75
73
|
private
|
76
74
|
|
77
|
-
def to_inspect?(file,
|
75
|
+
def to_inspect?(file, base_dir_config)
|
78
76
|
return false if base_dir_config.file_to_exclude?(file)
|
79
|
-
return true if !
|
80
|
-
file <=> hidden_file
|
81
|
-
end && ruby_file?(file)
|
77
|
+
return true if !hidden_path?(file) && ruby_file?(file)
|
82
78
|
|
83
79
|
base_dir_config.file_to_include?(file)
|
84
80
|
end
|
85
81
|
|
82
|
+
def hidden_path?(path)
|
83
|
+
path.include?(HIDDEN_PATH_SUBSTRING)
|
84
|
+
end
|
85
|
+
|
86
86
|
def wanted_dir_patterns(base_dir, exclude_pattern, flags)
|
87
87
|
# Escape glob characters in base_dir to avoid unwanted behavior.
|
88
|
-
base_dir = base_dir.gsub(/[
|
88
|
+
base_dir = base_dir.gsub(/[\\{}\[\]*?]/) do |reserved_glob_character|
|
89
89
|
"\\#{reserved_glob_character}"
|
90
90
|
end
|
91
91
|
|
data/lib/rubocop/target_ruby.rb
CHANGED
@@ -110,8 +110,17 @@ module RuboCop
|
|
110
110
|
end
|
111
111
|
|
112
112
|
def version_from_gemspec_file(file)
|
113
|
+
# When using parser_prism, we need to use a Ruby version that Prism supports (3.3+)
|
114
|
+
# for parsing the gemspec file. This doesn't affect the detected Ruby version,
|
115
|
+
# it's just for the parsing step.
|
116
|
+
ruby_version_for_parsing = if @config.parser_engine == :parser_prism
|
117
|
+
3.3
|
118
|
+
else
|
119
|
+
DEFAULT_VERSION
|
120
|
+
end
|
121
|
+
|
113
122
|
processed_source = ProcessedSource.from_file(
|
114
|
-
file,
|
123
|
+
file, ruby_version_for_parsing, parser_engine: @config.parser_engine
|
115
124
|
)
|
116
125
|
return unless processed_source.valid_syntax?
|
117
126
|
|
data/lib/rubocop/version.rb
CHANGED
data/lib/rubocop.rb
CHANGED
@@ -180,6 +180,7 @@ require_relative 'rubocop/cop/bundler/insecure_protocol_source'
|
|
180
180
|
require_relative 'rubocop/cop/bundler/ordered_gems'
|
181
181
|
|
182
182
|
require_relative 'rubocop/cop/gemspec/add_runtime_dependency'
|
183
|
+
require_relative 'rubocop/cop/gemspec/attribute_assignment'
|
183
184
|
require_relative 'rubocop/cop/gemspec/dependency_version'
|
184
185
|
require_relative 'rubocop/cop/gemspec/deprecated_attribute_assignment'
|
185
186
|
require_relative 'rubocop/cop/gemspec/development_dependencies'
|
@@ -210,6 +211,7 @@ require_relative 'rubocop/cop/layout/empty_line_after_guard_clause'
|
|
210
211
|
require_relative 'rubocop/cop/layout/empty_line_after_magic_comment'
|
211
212
|
require_relative 'rubocop/cop/layout/empty_line_after_multiline_condition'
|
212
213
|
require_relative 'rubocop/cop/layout/empty_line_between_defs'
|
214
|
+
require_relative 'rubocop/cop/layout/empty_lines_after_module_inclusion'
|
213
215
|
require_relative 'rubocop/cop/layout/empty_lines_around_access_modifier'
|
214
216
|
require_relative 'rubocop/cop/layout/empty_lines_around_arguments'
|
215
217
|
require_relative 'rubocop/cop/layout/empty_lines_around_attribute_accessor'
|
@@ -289,6 +291,7 @@ require_relative 'rubocop/cop/layout/space_inside_string_interpolation'
|
|
289
291
|
require_relative 'rubocop/cop/layout/trailing_empty_lines'
|
290
292
|
require_relative 'rubocop/cop/layout/trailing_whitespace'
|
291
293
|
|
294
|
+
require_relative 'rubocop/cop/lint/utils/nil_receiver_checker'
|
292
295
|
require_relative 'rubocop/cop/lint/ambiguous_assignment'
|
293
296
|
require_relative 'rubocop/cop/lint/ambiguous_block_association'
|
294
297
|
require_relative 'rubocop/cop/lint/ambiguous_operator'
|
@@ -430,10 +433,12 @@ require_relative 'rubocop/cop/lint/uri_regexp'
|
|
430
433
|
require_relative 'rubocop/cop/lint/useless_access_modifier'
|
431
434
|
require_relative 'rubocop/cop/lint/useless_assignment'
|
432
435
|
require_relative 'rubocop/cop/lint/useless_constant_scoping'
|
436
|
+
require_relative 'rubocop/cop/lint/useless_default_value_argument'
|
433
437
|
require_relative 'rubocop/cop/lint/useless_defined'
|
434
438
|
require_relative 'rubocop/cop/lint/useless_else_without_rescue'
|
435
439
|
require_relative 'rubocop/cop/lint/useless_method_definition'
|
436
440
|
require_relative 'rubocop/cop/lint/useless_numeric_operation'
|
441
|
+
require_relative 'rubocop/cop/lint/useless_or'
|
437
442
|
require_relative 'rubocop/cop/lint/useless_rescue'
|
438
443
|
require_relative 'rubocop/cop/lint/useless_ruby2_keywords'
|
439
444
|
require_relative 'rubocop/cop/lint/useless_setter_call'
|
@@ -469,7 +474,8 @@ require_relative 'rubocop/cop/naming/memoized_instance_variable_name'
|
|
469
474
|
require_relative 'rubocop/cop/naming/method_name'
|
470
475
|
require_relative 'rubocop/cop/naming/method_parameter_name'
|
471
476
|
require_relative 'rubocop/cop/naming/binary_operator_parameter_name'
|
472
|
-
require_relative 'rubocop/cop/naming/
|
477
|
+
require_relative 'rubocop/cop/naming/predicate_method'
|
478
|
+
require_relative 'rubocop/cop/naming/predicate_prefix'
|
473
479
|
require_relative 'rubocop/cop/naming/rescued_exceptions_variable_name'
|
474
480
|
require_relative 'rubocop/cop/naming/variable_name'
|
475
481
|
require_relative 'rubocop/cop/naming/variable_number'
|
@@ -483,6 +489,7 @@ require_relative 'rubocop/cop/style/arguments_forwarding'
|
|
483
489
|
require_relative 'rubocop/cop/style/array_coercion'
|
484
490
|
require_relative 'rubocop/cop/style/array_first_last'
|
485
491
|
require_relative 'rubocop/cop/style/array_intersect'
|
492
|
+
require_relative 'rubocop/cop/style/array_intersect_with_single_element'
|
486
493
|
require_relative 'rubocop/cop/style/array_join'
|
487
494
|
require_relative 'rubocop/cop/style/ascii_comments'
|
488
495
|
require_relative 'rubocop/cop/style/attr'
|
@@ -504,6 +511,7 @@ require_relative 'rubocop/cop/style/class_methods_definitions'
|
|
504
511
|
require_relative 'rubocop/cop/style/class_vars'
|
505
512
|
require_relative 'rubocop/cop/style/collection_compact'
|
506
513
|
require_relative 'rubocop/cop/style/collection_methods'
|
514
|
+
require_relative 'rubocop/cop/style/collection_querying'
|
507
515
|
require_relative 'rubocop/cop/style/colon_method_call'
|
508
516
|
require_relative 'rubocop/cop/style/colon_method_definition'
|
509
517
|
require_relative 'rubocop/cop/style/combinable_defined'
|
@@ -538,6 +546,7 @@ require_relative 'rubocop/cop/style/empty_heredoc'
|
|
538
546
|
require_relative 'rubocop/cop/style/empty_lambda_parameter'
|
539
547
|
require_relative 'rubocop/cop/style/empty_literal'
|
540
548
|
require_relative 'rubocop/cop/style/empty_method'
|
549
|
+
require_relative 'rubocop/cop/style/empty_string_inside_interpolation'
|
541
550
|
require_relative 'rubocop/cop/style/endless_method'
|
542
551
|
require_relative 'rubocop/cop/style/encoding'
|
543
552
|
require_relative 'rubocop/cop/style/end_block'
|
@@ -604,6 +613,7 @@ require_relative 'rubocop/cop/style/numbered_parameters'
|
|
604
613
|
require_relative 'rubocop/cop/style/open_struct_use'
|
605
614
|
require_relative 'rubocop/cop/style/operator_method_call'
|
606
615
|
require_relative 'rubocop/cop/style/redundant_array_constructor'
|
616
|
+
require_relative 'rubocop/cop/style/redundant_array_flatten'
|
607
617
|
require_relative 'rubocop/cop/style/redundant_assignment'
|
608
618
|
require_relative 'rubocop/cop/style/redundant_constant_base'
|
609
619
|
require_relative 'rubocop/cop/style/redundant_current_directory_in_path'
|
@@ -805,6 +815,7 @@ require_relative 'rubocop/options'
|
|
805
815
|
require_relative 'rubocop/remote_config'
|
806
816
|
require_relative 'rubocop/target_ruby'
|
807
817
|
require_relative 'rubocop/yaml_duplication_checker'
|
818
|
+
require_relative 'rubocop/pending_cops_reporter'
|
808
819
|
|
809
820
|
# rubocop:enable Style/RequireOrder
|
810
821
|
|
@@ -8,7 +8,10 @@ module RubyLsp
|
|
8
8
|
module RuboCop
|
9
9
|
# A Ruby LSP add-on for RuboCop.
|
10
10
|
class Addon < RubyLsp::Addon
|
11
|
-
|
11
|
+
RESTART_WATCHERS = %w[.rubocop.yml .rubocop_todo.yml .rubocop].freeze
|
12
|
+
|
13
|
+
def initialize
|
14
|
+
super
|
12
15
|
@runtime_adapter = nil
|
13
16
|
end
|
14
17
|
|
@@ -16,12 +19,16 @@ module RubyLsp
|
|
16
19
|
'RuboCop'
|
17
20
|
end
|
18
21
|
|
22
|
+
def version
|
23
|
+
::RuboCop::Version::STRING
|
24
|
+
end
|
25
|
+
|
19
26
|
def activate(global_state, message_queue)
|
20
27
|
::RuboCop::LSP::Logger.log(
|
21
28
|
"Activating RuboCop LSP addon #{::RuboCop::Version::STRING}.", prefix: '[RuboCop]'
|
22
29
|
)
|
23
30
|
|
24
|
-
@runtime_adapter = RuntimeAdapter.new
|
31
|
+
@runtime_adapter = RuntimeAdapter.new(message_queue)
|
25
32
|
global_state.register_formatter('rubocop', @runtime_adapter)
|
26
33
|
register_additional_file_watchers(global_state, message_queue)
|
27
34
|
|
@@ -34,7 +41,7 @@ module RubyLsp
|
|
34
41
|
@runtime_adapter = nil
|
35
42
|
end
|
36
43
|
|
37
|
-
# rubocop:disable
|
44
|
+
# rubocop:disable Metrics/MethodLength
|
38
45
|
def register_additional_file_watchers(global_state, message_queue)
|
39
46
|
return unless global_state.supports_watching_files
|
40
47
|
|
@@ -49,7 +56,7 @@ module RubyLsp
|
|
49
56
|
register_options: Interface::DidChangeWatchedFilesRegistrationOptions.new(
|
50
57
|
watchers: [
|
51
58
|
Interface::FileSystemWatcher.new(
|
52
|
-
glob_pattern:
|
59
|
+
glob_pattern: "**/{#{RESTART_WATCHERS.join(',')}}",
|
53
60
|
kind: Constant::WatchKind::CREATE | Constant::WatchKind::CHANGE | Constant::WatchKind::DELETE
|
54
61
|
)
|
55
62
|
]
|
@@ -59,16 +66,24 @@ module RubyLsp
|
|
59
66
|
)
|
60
67
|
)
|
61
68
|
end
|
62
|
-
# rubocop:enable
|
69
|
+
# rubocop:enable Metrics/MethodLength
|
63
70
|
|
64
71
|
def workspace_did_change_watched_files(changes)
|
65
|
-
|
72
|
+
if (changed_config_file = changed_config_file(changes))
|
73
|
+
@runtime_adapter.reload_config
|
74
|
+
|
75
|
+
::RuboCop::LSP::Logger.log(<<~MESSAGE, prefix: '[RuboCop]')
|
76
|
+
Re-initialized RuboCop LSP addon #{::RuboCop::Version::STRING} due to #{changed_config_file} change.
|
77
|
+
MESSAGE
|
78
|
+
end
|
79
|
+
end
|
66
80
|
|
67
|
-
|
81
|
+
private
|
68
82
|
|
69
|
-
|
70
|
-
|
71
|
-
|
83
|
+
def changed_config_file(changes)
|
84
|
+
RESTART_WATCHERS.find do |file_name|
|
85
|
+
changes.any? { |change| change[:uri].end_with?(file_name) }
|
86
|
+
end
|
72
87
|
end
|
73
88
|
end
|
74
89
|
end
|
@@ -7,30 +7,45 @@ module RubyLsp
|
|
7
7
|
# Provides an adapter to bridge RuboCop's built-in LSP runtime with Ruby LSP's add-on.
|
8
8
|
# @api private
|
9
9
|
class RuntimeAdapter
|
10
|
-
|
10
|
+
def initialize(message_queue)
|
11
|
+
@message_queue = message_queue
|
12
|
+
reload_config
|
13
|
+
end
|
11
14
|
|
12
|
-
def
|
13
|
-
|
15
|
+
def reload_config
|
16
|
+
@runtime = nil
|
17
|
+
options, _paths = ::RuboCop::Options.new.parse([])
|
14
18
|
|
19
|
+
config_store = ::RuboCop::ConfigStore.new
|
20
|
+
config_store.apply_options!(options)
|
15
21
|
@runtime = ::RuboCop::LSP::Runtime.new(config_store)
|
22
|
+
rescue ::RuboCop::Error => e
|
23
|
+
@message_queue << Notification.window_show_message(
|
24
|
+
"RuboCop configuration error: #{e.message}. Formatting will not be available.",
|
25
|
+
type: Constant::MessageType::ERROR
|
26
|
+
)
|
16
27
|
end
|
17
28
|
|
18
29
|
def run_diagnostic(uri, document)
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
30
|
+
with_error_handling do
|
31
|
+
@runtime.offenses(
|
32
|
+
uri_to_path(uri),
|
33
|
+
document.source,
|
34
|
+
document.encoding,
|
35
|
+
prism_result: prism_result(document)
|
36
|
+
)
|
37
|
+
end
|
25
38
|
end
|
26
39
|
|
27
40
|
def run_formatting(uri, document)
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
41
|
+
with_error_handling do
|
42
|
+
@runtime.format(
|
43
|
+
uri_to_path(uri),
|
44
|
+
document.source,
|
45
|
+
command: 'rubocop.formatAutocorrects',
|
46
|
+
prism_result: prism_result(document)
|
47
|
+
)
|
48
|
+
end
|
34
49
|
end
|
35
50
|
|
36
51
|
def run_range_formatting(_uri, _partial_source, _base_indentation)
|
@@ -43,6 +58,25 @@ module RubyLsp
|
|
43
58
|
|
44
59
|
private
|
45
60
|
|
61
|
+
def with_error_handling
|
62
|
+
return unless @runtime
|
63
|
+
|
64
|
+
yield
|
65
|
+
rescue StandardError => e
|
66
|
+
::RuboCop::LSP::Logger.log(e.full_message, prefix: '[RuboCop]')
|
67
|
+
|
68
|
+
message = if e.is_a?(::RuboCop::ErrorWithAnalyzedFileLocation)
|
69
|
+
"for the #{e.cop.name} cop"
|
70
|
+
else
|
71
|
+
"- #{e.message}"
|
72
|
+
end
|
73
|
+
raise Requests::Formatting::Error, <<~MSG
|
74
|
+
An internal error occurred #{message}.
|
75
|
+
Updating to a newer version of RuboCop may solve this.
|
76
|
+
For more details, run RuboCop on the command line.
|
77
|
+
MSG
|
78
|
+
end
|
79
|
+
|
46
80
|
# duplicated from: lib/standard/lsp/routes.rb
|
47
81
|
# modified to incorporate Ruby LSP's to_standardized_path method
|
48
82
|
def uri_to_path(uri)
|
metadata
CHANGED
@@ -1,15 +1,16 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rubocop
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.81.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Bozhidar Batsov
|
8
8
|
- Jonas Arvidsson
|
9
9
|
- Yuji Nakayama
|
10
|
+
autorequire:
|
10
11
|
bindir: exe
|
11
12
|
cert_chain: []
|
12
|
-
date: 2025-
|
13
|
+
date: 2025-09-26 00:00:00.000000000 Z
|
13
14
|
dependencies:
|
14
15
|
- !ruby/object:Gem::Dependency
|
15
16
|
name: json
|
@@ -127,7 +128,7 @@ dependencies:
|
|
127
128
|
requirements:
|
128
129
|
- - ">="
|
129
130
|
- !ruby/object:Gem::Version
|
130
|
-
version: 1.
|
131
|
+
version: 1.47.1
|
131
132
|
- - "<"
|
132
133
|
- !ruby/object:Gem::Version
|
133
134
|
version: '2.0'
|
@@ -137,7 +138,7 @@ dependencies:
|
|
137
138
|
requirements:
|
138
139
|
- - ">="
|
139
140
|
- !ruby/object:Gem::Version
|
140
|
-
version: 1.
|
141
|
+
version: 1.47.1
|
141
142
|
- - "<"
|
142
143
|
- !ruby/object:Gem::Version
|
143
144
|
version: '2.0'
|
@@ -265,6 +266,7 @@ files:
|
|
265
266
|
- lib/rubocop/cop/exclude_limit.rb
|
266
267
|
- lib/rubocop/cop/force.rb
|
267
268
|
- lib/rubocop/cop/gemspec/add_runtime_dependency.rb
|
269
|
+
- lib/rubocop/cop/gemspec/attribute_assignment.rb
|
268
270
|
- lib/rubocop/cop/gemspec/dependency_version.rb
|
269
271
|
- lib/rubocop/cop/gemspec/deprecated_attribute_assignment.rb
|
270
272
|
- lib/rubocop/cop/gemspec/development_dependencies.rb
|
@@ -341,6 +343,7 @@ files:
|
|
341
343
|
- lib/rubocop/cop/layout/empty_line_after_multiline_condition.rb
|
342
344
|
- lib/rubocop/cop/layout/empty_line_between_defs.rb
|
343
345
|
- lib/rubocop/cop/layout/empty_lines.rb
|
346
|
+
- lib/rubocop/cop/layout/empty_lines_after_module_inclusion.rb
|
344
347
|
- lib/rubocop/cop/layout/empty_lines_around_access_modifier.rb
|
345
348
|
- lib/rubocop/cop/layout/empty_lines_around_arguments.rb
|
346
349
|
- lib/rubocop/cop/layout/empty_lines_around_attribute_accessor.rb
|
@@ -561,14 +564,17 @@ files:
|
|
561
564
|
- lib/rubocop/cop/lint/useless_access_modifier.rb
|
562
565
|
- lib/rubocop/cop/lint/useless_assignment.rb
|
563
566
|
- lib/rubocop/cop/lint/useless_constant_scoping.rb
|
567
|
+
- lib/rubocop/cop/lint/useless_default_value_argument.rb
|
564
568
|
- lib/rubocop/cop/lint/useless_defined.rb
|
565
569
|
- lib/rubocop/cop/lint/useless_else_without_rescue.rb
|
566
570
|
- lib/rubocop/cop/lint/useless_method_definition.rb
|
567
571
|
- lib/rubocop/cop/lint/useless_numeric_operation.rb
|
572
|
+
- lib/rubocop/cop/lint/useless_or.rb
|
568
573
|
- lib/rubocop/cop/lint/useless_rescue.rb
|
569
574
|
- lib/rubocop/cop/lint/useless_ruby2_keywords.rb
|
570
575
|
- lib/rubocop/cop/lint/useless_setter_call.rb
|
571
576
|
- lib/rubocop/cop/lint/useless_times.rb
|
577
|
+
- lib/rubocop/cop/lint/utils/nil_receiver_checker.rb
|
572
578
|
- lib/rubocop/cop/lint/void.rb
|
573
579
|
- lib/rubocop/cop/message_annotator.rb
|
574
580
|
- lib/rubocop/cop/metrics/abc_size.rb
|
@@ -679,7 +685,8 @@ files:
|
|
679
685
|
- lib/rubocop/cop/naming/memoized_instance_variable_name.rb
|
680
686
|
- lib/rubocop/cop/naming/method_name.rb
|
681
687
|
- lib/rubocop/cop/naming/method_parameter_name.rb
|
682
|
-
- lib/rubocop/cop/naming/
|
688
|
+
- lib/rubocop/cop/naming/predicate_method.rb
|
689
|
+
- lib/rubocop/cop/naming/predicate_prefix.rb
|
683
690
|
- lib/rubocop/cop/naming/rescued_exceptions_variable_name.rb
|
684
691
|
- lib/rubocop/cop/naming/variable_name.rb
|
685
692
|
- lib/rubocop/cop/naming/variable_number.rb
|
@@ -702,6 +709,7 @@ files:
|
|
702
709
|
- lib/rubocop/cop/style/array_coercion.rb
|
703
710
|
- lib/rubocop/cop/style/array_first_last.rb
|
704
711
|
- lib/rubocop/cop/style/array_intersect.rb
|
712
|
+
- lib/rubocop/cop/style/array_intersect_with_single_element.rb
|
705
713
|
- lib/rubocop/cop/style/array_join.rb
|
706
714
|
- lib/rubocop/cop/style/ascii_comments.rb
|
707
715
|
- lib/rubocop/cop/style/attr.rb
|
@@ -724,6 +732,7 @@ files:
|
|
724
732
|
- lib/rubocop/cop/style/class_vars.rb
|
725
733
|
- lib/rubocop/cop/style/collection_compact.rb
|
726
734
|
- lib/rubocop/cop/style/collection_methods.rb
|
735
|
+
- lib/rubocop/cop/style/collection_querying.rb
|
727
736
|
- lib/rubocop/cop/style/colon_method_call.rb
|
728
737
|
- lib/rubocop/cop/style/colon_method_definition.rb
|
729
738
|
- lib/rubocop/cop/style/combinable_defined.rb
|
@@ -758,6 +767,7 @@ files:
|
|
758
767
|
- lib/rubocop/cop/style/empty_lambda_parameter.rb
|
759
768
|
- lib/rubocop/cop/style/empty_literal.rb
|
760
769
|
- lib/rubocop/cop/style/empty_method.rb
|
770
|
+
- lib/rubocop/cop/style/empty_string_inside_interpolation.rb
|
761
771
|
- lib/rubocop/cop/style/encoding.rb
|
762
772
|
- lib/rubocop/cop/style/end_block.rb
|
763
773
|
- lib/rubocop/cop/style/endless_method.rb
|
@@ -878,6 +888,7 @@ files:
|
|
878
888
|
- lib/rubocop/cop/style/random_with_offset.rb
|
879
889
|
- lib/rubocop/cop/style/redundant_argument.rb
|
880
890
|
- lib/rubocop/cop/style/redundant_array_constructor.rb
|
891
|
+
- lib/rubocop/cop/style/redundant_array_flatten.rb
|
881
892
|
- lib/rubocop/cop/style/redundant_assignment.rb
|
882
893
|
- lib/rubocop/cop/style/redundant_begin.rb
|
883
894
|
- lib/rubocop/cop/style/redundant_capital_w.rb
|
@@ -1033,6 +1044,7 @@ files:
|
|
1033
1044
|
- lib/rubocop/name_similarity.rb
|
1034
1045
|
- lib/rubocop/options.rb
|
1035
1046
|
- lib/rubocop/path_util.rb
|
1047
|
+
- lib/rubocop/pending_cops_reporter.rb
|
1036
1048
|
- lib/rubocop/platform.rb
|
1037
1049
|
- lib/rubocop/plugin.rb
|
1038
1050
|
- lib/rubocop/plugin/configuration_integrator.rb
|
@@ -1080,11 +1092,12 @@ licenses:
|
|
1080
1092
|
- MIT
|
1081
1093
|
metadata:
|
1082
1094
|
homepage_uri: https://rubocop.org/
|
1083
|
-
changelog_uri: https://github.com/rubocop/rubocop/releases/tag/v1.
|
1095
|
+
changelog_uri: https://github.com/rubocop/rubocop/releases/tag/v1.81.1
|
1084
1096
|
source_code_uri: https://github.com/rubocop/rubocop/
|
1085
|
-
documentation_uri: https://docs.rubocop.org/rubocop/1.
|
1097
|
+
documentation_uri: https://docs.rubocop.org/rubocop/1.81/
|
1086
1098
|
bug_tracker_uri: https://github.com/rubocop/rubocop/issues
|
1087
1099
|
rubygems_mfa_required: 'true'
|
1100
|
+
post_install_message:
|
1088
1101
|
rdoc_options: []
|
1089
1102
|
require_paths:
|
1090
1103
|
- lib
|
@@ -1099,7 +1112,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
1099
1112
|
- !ruby/object:Gem::Version
|
1100
1113
|
version: '0'
|
1101
1114
|
requirements: []
|
1102
|
-
rubygems_version: 3.
|
1115
|
+
rubygems_version: 3.3.7
|
1116
|
+
signing_key:
|
1103
1117
|
specification_version: 4
|
1104
1118
|
summary: Automatic Ruby code style checking tool.
|
1105
1119
|
test_files: []
|