rubocop 1.80.1 → 1.82.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 +1 -1
- data/config/default.yml +35 -7
- data/config/obsoletion.yml +4 -0
- data/lib/rubocop/cli/command/auto_generate_config.rb +2 -2
- data/lib/rubocop/cli.rb +3 -3
- data/lib/rubocop/comment_config.rb +62 -17
- data/lib/rubocop/config_loader.rb +5 -2
- data/lib/rubocop/config_loader_resolver.rb +7 -6
- data/lib/rubocop/config_store.rb +5 -0
- data/lib/rubocop/cop/autocorrect_logic.rb +8 -4
- data/lib/rubocop/cop/bundler/ordered_gems.rb +1 -2
- data/lib/rubocop/cop/correctors/alignment_corrector.rb +2 -4
- data/lib/rubocop/cop/gemspec/ordered_dependencies.rb +1 -2
- data/lib/rubocop/cop/gemspec/ruby_version_globals_usage.rb +10 -5
- data/lib/rubocop/cop/internal_affairs/location_exists.rb +28 -2
- data/lib/rubocop/cop/internal_affairs/node_pattern_groups/ast_processor.rb +1 -1
- data/lib/rubocop/cop/internal_affairs/node_pattern_groups.rb +3 -1
- data/lib/rubocop/cop/internal_affairs/on_send_without_on_csend.rb +1 -1
- data/lib/rubocop/cop/layout/class_structure.rb +1 -1
- data/lib/rubocop/cop/layout/dot_position.rb +1 -1
- data/lib/rubocop/cop/layout/empty_line_after_guard_clause.rb +3 -0
- data/lib/rubocop/cop/layout/empty_line_between_defs.rb +30 -12
- data/lib/rubocop/cop/layout/end_alignment.rb +4 -0
- data/lib/rubocop/cop/layout/hash_alignment.rb +2 -5
- data/lib/rubocop/cop/layout/heredoc_argument_closing_parenthesis.rb +2 -2
- data/lib/rubocop/cop/layout/heredoc_indentation.rb +1 -4
- data/lib/rubocop/cop/layout/indentation_style.rb +1 -1
- data/lib/rubocop/cop/layout/indentation_width.rb +12 -1
- data/lib/rubocop/cop/layout/line_continuation_spacing.rb +1 -1
- data/lib/rubocop/cop/layout/line_length.rb +17 -5
- data/lib/rubocop/cop/layout/multiline_block_layout.rb +2 -0
- data/lib/rubocop/cop/layout/multiline_method_call_indentation.rb +5 -1
- data/lib/rubocop/cop/layout/multiline_operation_indentation.rb +6 -4
- data/lib/rubocop/cop/layout/rescue_ensure_alignment.rb +13 -3
- data/lib/rubocop/cop/layout/space_after_comma.rb +2 -10
- data/lib/rubocop/cop/layout/space_after_semicolon.rb +1 -1
- data/lib/rubocop/cop/layout/space_around_keyword.rb +1 -1
- data/lib/rubocop/cop/layout/trailing_whitespace.rb +1 -1
- data/lib/rubocop/cop/lint/circular_argument_reference.rb +47 -3
- data/lib/rubocop/cop/lint/constant_overwritten_in_rescue.rb +3 -2
- data/lib/rubocop/cop/lint/cop_directive_syntax.rb +14 -8
- data/lib/rubocop/cop/lint/debugger.rb +0 -2
- data/lib/rubocop/cop/lint/deprecated_open_ssl_constant.rb +4 -1
- data/lib/rubocop/cop/lint/duplicate_match_pattern.rb +4 -4
- data/lib/rubocop/cop/lint/else_layout.rb +19 -0
- data/lib/rubocop/cop/lint/empty_interpolation.rb +11 -0
- data/lib/rubocop/cop/lint/literal_as_condition.rb +4 -0
- data/lib/rubocop/cop/lint/literal_in_interpolation.rb +1 -1
- data/lib/rubocop/cop/lint/missing_cop_enable_directive.rb +16 -6
- data/lib/rubocop/cop/lint/no_return_in_begin_end_blocks.rb +4 -0
- data/lib/rubocop/cop/lint/redundant_cop_disable_directive.rb +23 -9
- data/lib/rubocop/cop/lint/redundant_require_statement.rb +4 -2
- data/lib/rubocop/cop/lint/redundant_splat_expansion.rb +7 -1
- data/lib/rubocop/cop/lint/rescue_exception.rb +1 -4
- data/lib/rubocop/cop/lint/self_assignment.rb +10 -2
- data/lib/rubocop/cop/lint/shadowed_argument.rb +7 -7
- data/lib/rubocop/cop/lint/unreachable_code.rb +5 -3
- data/lib/rubocop/cop/lint/uri_escape_unescape.rb +2 -0
- data/lib/rubocop/cop/lint/useless_assignment.rb +44 -16
- data/lib/rubocop/cop/lint/useless_or.rb +15 -2
- data/lib/rubocop/cop/lint/utils/nil_receiver_checker.rb +1 -1
- data/lib/rubocop/cop/lint/void.rb +7 -0
- data/lib/rubocop/cop/message_annotator.rb +1 -1
- data/lib/rubocop/cop/metrics/utils/abc_size_calculator.rb +4 -3
- data/lib/rubocop/cop/mixin/check_line_breakable.rb +1 -1
- data/lib/rubocop/cop/mixin/check_single_line_suitability.rb +2 -4
- data/lib/rubocop/cop/mixin/code_length.rb +1 -1
- data/lib/rubocop/cop/mixin/hash_shorthand_syntax.rb +1 -1
- data/lib/rubocop/cop/mixin/line_length_help.rb +21 -2
- data/lib/rubocop/cop/mixin/method_complexity.rb +1 -1
- data/lib/rubocop/cop/mixin/multiline_expression_indentation.rb +1 -1
- data/lib/rubocop/cop/mixin/multiline_literal_brace_layout.rb +1 -1
- data/lib/rubocop/cop/mixin/space_after_punctuation.rb +5 -4
- data/lib/rubocop/cop/mixin/statement_modifier.rb +0 -6
- data/lib/rubocop/cop/mixin/trailing_comma.rb +8 -5
- data/lib/rubocop/cop/naming/method_name.rb +4 -2
- data/lib/rubocop/cop/naming/predicate_method.rb +19 -6
- data/lib/rubocop/cop/security/json_load.rb +33 -11
- data/lib/rubocop/cop/style/array_intersect.rb +2 -2
- data/lib/rubocop/cop/style/array_intersect_with_single_element.rb +47 -0
- data/lib/rubocop/cop/style/bare_percent_literals.rb +1 -2
- data/lib/rubocop/cop/style/case_equality.rb +11 -13
- data/lib/rubocop/cop/style/class_and_module_children.rb +1 -0
- data/lib/rubocop/cop/style/conditional_assignment.rb +8 -14
- data/lib/rubocop/cop/style/constant_visibility.rb +17 -12
- data/lib/rubocop/cop/style/double_negation.rb +1 -1
- data/lib/rubocop/cop/style/empty_method.rb +0 -6
- data/lib/rubocop/cop/style/endless_method.rb +15 -2
- data/lib/rubocop/cop/style/explicit_block_argument.rb +1 -1
- data/lib/rubocop/cop/style/float_division.rb +15 -1
- data/lib/rubocop/cop/style/guard_clause.rb +0 -11
- data/lib/rubocop/cop/style/hash_syntax.rb +1 -1
- data/lib/rubocop/cop/style/if_unless_modifier.rb +3 -3
- data/lib/rubocop/cop/style/method_call_with_args_parentheses/require_parentheses.rb +12 -1
- data/lib/rubocop/cop/style/method_call_with_args_parentheses.rb +17 -4
- data/lib/rubocop/cop/style/module_member_existence_check.rb +74 -0
- data/lib/rubocop/cop/style/multiline_method_signature.rb +2 -4
- data/lib/rubocop/cop/style/nil_comparison.rb +9 -7
- data/lib/rubocop/cop/style/one_line_conditional.rb +17 -9
- data/lib/rubocop/cop/style/operator_method_call.rb +11 -2
- data/lib/rubocop/cop/style/parallel_assignment.rb +2 -2
- data/lib/rubocop/cop/style/redundant_argument.rb +2 -0
- data/lib/rubocop/cop/style/redundant_exception.rb +1 -1
- data/lib/rubocop/cop/style/redundant_format.rb +26 -5
- data/lib/rubocop/cop/style/redundant_interpolation.rb +11 -2
- data/lib/rubocop/cop/style/redundant_parentheses.rb +13 -10
- data/lib/rubocop/cop/style/redundant_percent_q.rb +1 -2
- data/lib/rubocop/cop/style/redundant_regexp_argument.rb +9 -0
- data/lib/rubocop/cop/style/redundant_regexp_escape.rb +8 -0
- data/lib/rubocop/cop/style/redundant_sort.rb +7 -7
- data/lib/rubocop/cop/style/safe_navigation.rb +6 -0
- data/lib/rubocop/cop/style/semicolon.rb +23 -7
- data/lib/rubocop/cop/style/sole_nested_conditional.rb +8 -1
- data/lib/rubocop/cop/style/string_concatenation.rb +16 -12
- data/lib/rubocop/cop/style/super_arguments.rb +2 -2
- data/lib/rubocop/cop/style/trailing_comma_in_arguments.rb +45 -0
- data/lib/rubocop/cop/style/trailing_underscore_variable.rb +11 -11
- data/lib/rubocop/cop/style/unless_else.rb +10 -9
- data/lib/rubocop/cop/util.rb +2 -3
- data/lib/rubocop/cop/utils/format_string.rb +10 -0
- data/lib/rubocop/cops_documentation_generator.rb +4 -4
- data/lib/rubocop/directive_comment.rb +46 -3
- data/lib/rubocop/formatter/disabled_config_formatter.rb +1 -0
- data/lib/rubocop/lsp/diagnostic.rb +10 -14
- data/lib/rubocop/lsp/stdin_runner.rb +0 -16
- data/lib/rubocop/magic_comment.rb +20 -0
- data/lib/rubocop/rake_task.rb +1 -1
- data/lib/rubocop/remote_config.rb +7 -8
- data/lib/rubocop/result_cache.rb +38 -27
- data/lib/rubocop/rspec/shared_contexts.rb +2 -2
- data/lib/rubocop/rspec/support.rb +1 -1
- data/lib/rubocop/runner.rb +4 -0
- data/lib/rubocop/target_ruby.rb +11 -2
- data/lib/rubocop/version.rb +1 -1
- data/lib/rubocop.rb +2 -0
- data/lib/ruby_lsp/rubocop/addon.rb +23 -8
- data/lib/ruby_lsp/rubocop/runtime_adapter.rb +49 -15
- metadata +9 -7
data/lib/rubocop/result_cache.rb
CHANGED
|
@@ -22,7 +22,7 @@ module RuboCop
|
|
|
22
22
|
# Remove old files so that the cache doesn't grow too big. When the
|
|
23
23
|
# threshold MaxFilesInCache has been exceeded, the oldest 50% of all the
|
|
24
24
|
# files in the cache are removed. The reason for removing so much is that
|
|
25
|
-
#
|
|
25
|
+
# removing should be done relatively seldom, since there is a slight risk
|
|
26
26
|
# that some other RuboCop process was just about to read the file, when
|
|
27
27
|
# there's parallel execution and the cache is shared.
|
|
28
28
|
def self.cleanup(config_store, verbose, cache_root_override = nil)
|
|
@@ -31,10 +31,12 @@ module RuboCop
|
|
|
31
31
|
rubocop_cache_dir = cache_root(config_store, cache_root_override)
|
|
32
32
|
return unless File.exist?(rubocop_cache_dir)
|
|
33
33
|
|
|
34
|
-
|
|
34
|
+
# We know the cache entries are 3 level deep, so globing
|
|
35
|
+
# for `*/*/*` only returns files.
|
|
36
|
+
files = Dir[File.join(rubocop_cache_dir, '*/*/*')]
|
|
35
37
|
return unless requires_file_removal?(files.length, config_store)
|
|
36
38
|
|
|
37
|
-
remove_oldest_files(files,
|
|
39
|
+
remove_oldest_files(files, rubocop_cache_dir, verbose)
|
|
38
40
|
end
|
|
39
41
|
|
|
40
42
|
class << self
|
|
@@ -49,26 +51,36 @@ module RuboCop
|
|
|
49
51
|
file_count > 1 && file_count > config_store.for_pwd.for_all_cops['MaxFilesInCache']
|
|
50
52
|
end
|
|
51
53
|
|
|
52
|
-
def remove_oldest_files(files,
|
|
54
|
+
def remove_oldest_files(files, rubocop_cache_dir, verbose)
|
|
53
55
|
# Add 1 to half the number of files, so that we remove the file if
|
|
54
56
|
# there's only 1 left.
|
|
55
57
|
remove_count = (files.length / 2) + 1
|
|
56
58
|
puts "Removing the #{remove_count} oldest files from #{rubocop_cache_dir}" if verbose
|
|
57
59
|
sorted = files.sort_by { |path| File.mtime(path) }
|
|
58
|
-
remove_files(sorted,
|
|
60
|
+
remove_files(sorted, remove_count)
|
|
59
61
|
rescue Errno::ENOENT
|
|
60
62
|
# This can happen if parallel RuboCop invocations try to remove the
|
|
61
63
|
# same files. No problem.
|
|
62
64
|
puts $ERROR_INFO if verbose
|
|
63
65
|
end
|
|
64
66
|
|
|
65
|
-
def remove_files(files,
|
|
67
|
+
def remove_files(files, remove_count)
|
|
66
68
|
# Batch file deletions, deleting over 130,000+ files will crash
|
|
67
69
|
# File.delete.
|
|
68
70
|
files[0, remove_count].each_slice(10_000).each do |files_slice|
|
|
69
71
|
File.delete(*files_slice)
|
|
70
72
|
end
|
|
71
|
-
|
|
73
|
+
|
|
74
|
+
dirs = files.map { |f| File.dirname(f) }.uniq
|
|
75
|
+
until dirs.empty?
|
|
76
|
+
dirs.select! do |dir|
|
|
77
|
+
Dir.rmdir(dir)
|
|
78
|
+
true
|
|
79
|
+
rescue SystemCallError # ENOTEMPTY etc
|
|
80
|
+
false
|
|
81
|
+
end
|
|
82
|
+
dirs = dirs.map { |f| File.dirname(f) }.uniq
|
|
83
|
+
end
|
|
72
84
|
end
|
|
73
85
|
end
|
|
74
86
|
|
|
@@ -90,7 +102,7 @@ module RuboCop
|
|
|
90
102
|
@allow_symlinks_in_cache_location =
|
|
91
103
|
ResultCache.allow_symlinks_in_cache_location?(config_store)
|
|
92
104
|
@path = File.join(rubocop_cache_dir,
|
|
93
|
-
|
|
105
|
+
self.class.source_checksum,
|
|
94
106
|
context_checksum(team, options),
|
|
95
107
|
file_checksum(file, config_store))
|
|
96
108
|
@cached_data = CachedData.new(file)
|
|
@@ -167,13 +179,11 @@ module RuboCop
|
|
|
167
179
|
end
|
|
168
180
|
|
|
169
181
|
class << self
|
|
170
|
-
attr_accessor :
|
|
171
|
-
end
|
|
182
|
+
attr_accessor :inhibit_cleanup
|
|
172
183
|
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
begin
|
|
184
|
+
# The checksum of the RuboCop program running the inspection.
|
|
185
|
+
def source_checksum
|
|
186
|
+
@source_checksum ||= begin
|
|
177
187
|
digest = Digest::SHA1.new
|
|
178
188
|
rubocop_extra_features
|
|
179
189
|
.select { |path| File.file?(path) }
|
|
@@ -184,21 +194,22 @@ module RuboCop
|
|
|
184
194
|
digest << RuboCop::Version::STRING << RuboCop::AST::Version::STRING
|
|
185
195
|
digest.hexdigest
|
|
186
196
|
end
|
|
187
|
-
|
|
197
|
+
end
|
|
188
198
|
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
+
private
|
|
200
|
+
|
|
201
|
+
def digest(path)
|
|
202
|
+
content = if path.end_with?(*DL_EXTENSIONS)
|
|
203
|
+
# Shared libraries often contain timestamps of when
|
|
204
|
+
# they were compiled and other non-stable data.
|
|
205
|
+
File.basename(path)
|
|
206
|
+
else
|
|
207
|
+
File.binread(path) # mtime not reliable
|
|
208
|
+
end
|
|
209
|
+
Zlib.crc32(content).to_s
|
|
210
|
+
end
|
|
199
211
|
|
|
200
|
-
|
|
201
|
-
@rubocop_extra_features ||= begin
|
|
212
|
+
def rubocop_extra_features
|
|
202
213
|
lib_root = File.join(File.dirname(__FILE__), '..')
|
|
203
214
|
exe_root = File.join(lib_root, '..', 'exe')
|
|
204
215
|
|
data/lib/rubocop/runner.rb
CHANGED
|
@@ -65,6 +65,10 @@ module RuboCop
|
|
|
65
65
|
end
|
|
66
66
|
|
|
67
67
|
def run(paths)
|
|
68
|
+
# Compute the cache source checksum once to avoid potential
|
|
69
|
+
# inconsistencies between workers.
|
|
70
|
+
ResultCache.source_checksum
|
|
71
|
+
|
|
68
72
|
target_files = find_target_files(paths)
|
|
69
73
|
if @options[:list_target_files]
|
|
70
74
|
list_files(target_files)
|
data/lib/rubocop/target_ruby.rb
CHANGED
|
@@ -4,7 +4,7 @@ module RuboCop
|
|
|
4
4
|
# The kind of Ruby that code inspected by RuboCop is written in.
|
|
5
5
|
# @api private
|
|
6
6
|
class TargetRuby
|
|
7
|
-
KNOWN_RUBIES = [2.0, 2.1, 2.2, 2.3, 2.4, 2.5, 2.6, 2.7, 3.0, 3.1, 3.2, 3.3, 3.4,
|
|
7
|
+
KNOWN_RUBIES = [2.0, 2.1, 2.2, 2.3, 2.4, 2.5, 2.6, 2.7, 3.0, 3.1, 3.2, 3.3, 3.4, 4.0].freeze
|
|
8
8
|
DEFAULT_VERSION = 2.7
|
|
9
9
|
|
|
10
10
|
OBSOLETE_RUBIES = {
|
|
@@ -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
|
@@ -489,6 +489,7 @@ require_relative 'rubocop/cop/style/arguments_forwarding'
|
|
|
489
489
|
require_relative 'rubocop/cop/style/array_coercion'
|
|
490
490
|
require_relative 'rubocop/cop/style/array_first_last'
|
|
491
491
|
require_relative 'rubocop/cop/style/array_intersect'
|
|
492
|
+
require_relative 'rubocop/cop/style/array_intersect_with_single_element'
|
|
492
493
|
require_relative 'rubocop/cop/style/array_join'
|
|
493
494
|
require_relative 'rubocop/cop/style/ascii_comments'
|
|
494
495
|
require_relative 'rubocop/cop/style/attr'
|
|
@@ -607,6 +608,7 @@ require_relative 'rubocop/cop/style/map_to_set'
|
|
|
607
608
|
require_relative 'rubocop/cop/style/method_call_without_args_parentheses'
|
|
608
609
|
require_relative 'rubocop/cop/style/method_call_with_args_parentheses'
|
|
609
610
|
require_relative 'rubocop/cop/style/min_max_comparison'
|
|
611
|
+
require_relative 'rubocop/cop/style/module_member_existence_check'
|
|
610
612
|
require_relative 'rubocop/cop/style/multiline_in_pattern_then'
|
|
611
613
|
require_relative 'rubocop/cop/style/numbered_parameters'
|
|
612
614
|
require_relative 'rubocop/cop/style/open_struct_use'
|
|
@@ -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
|
|
|
@@ -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
|
]
|
|
@@ -62,13 +69,21 @@ module RubyLsp
|
|
|
62
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,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.82.1
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Bozhidar Batsov
|
|
@@ -9,7 +9,7 @@ authors:
|
|
|
9
9
|
- Yuji Nakayama
|
|
10
10
|
bindir: exe
|
|
11
11
|
cert_chain: []
|
|
12
|
-
date:
|
|
12
|
+
date: 1980-01-02 00:00:00.000000000 Z
|
|
13
13
|
dependencies:
|
|
14
14
|
- !ruby/object:Gem::Dependency
|
|
15
15
|
name: json
|
|
@@ -127,7 +127,7 @@ dependencies:
|
|
|
127
127
|
requirements:
|
|
128
128
|
- - ">="
|
|
129
129
|
- !ruby/object:Gem::Version
|
|
130
|
-
version: 1.
|
|
130
|
+
version: 1.48.0
|
|
131
131
|
- - "<"
|
|
132
132
|
- !ruby/object:Gem::Version
|
|
133
133
|
version: '2.0'
|
|
@@ -137,7 +137,7 @@ dependencies:
|
|
|
137
137
|
requirements:
|
|
138
138
|
- - ">="
|
|
139
139
|
- !ruby/object:Gem::Version
|
|
140
|
-
version: 1.
|
|
140
|
+
version: 1.48.0
|
|
141
141
|
- - "<"
|
|
142
142
|
- !ruby/object:Gem::Version
|
|
143
143
|
version: '2.0'
|
|
@@ -708,6 +708,7 @@ files:
|
|
|
708
708
|
- lib/rubocop/cop/style/array_coercion.rb
|
|
709
709
|
- lib/rubocop/cop/style/array_first_last.rb
|
|
710
710
|
- lib/rubocop/cop/style/array_intersect.rb
|
|
711
|
+
- lib/rubocop/cop/style/array_intersect_with_single_element.rb
|
|
711
712
|
- lib/rubocop/cop/style/array_join.rb
|
|
712
713
|
- lib/rubocop/cop/style/ascii_comments.rb
|
|
713
714
|
- lib/rubocop/cop/style/attr.rb
|
|
@@ -838,6 +839,7 @@ files:
|
|
|
838
839
|
- lib/rubocop/cop/style/mixin_grouping.rb
|
|
839
840
|
- lib/rubocop/cop/style/mixin_usage.rb
|
|
840
841
|
- lib/rubocop/cop/style/module_function.rb
|
|
842
|
+
- lib/rubocop/cop/style/module_member_existence_check.rb
|
|
841
843
|
- lib/rubocop/cop/style/multiline_block_chain.rb
|
|
842
844
|
- lib/rubocop/cop/style/multiline_if_modifier.rb
|
|
843
845
|
- lib/rubocop/cop/style/multiline_if_then.rb
|
|
@@ -1090,9 +1092,9 @@ licenses:
|
|
|
1090
1092
|
- MIT
|
|
1091
1093
|
metadata:
|
|
1092
1094
|
homepage_uri: https://rubocop.org/
|
|
1093
|
-
changelog_uri: https://github.com/rubocop/rubocop/releases/tag/v1.
|
|
1095
|
+
changelog_uri: https://github.com/rubocop/rubocop/releases/tag/v1.82.1
|
|
1094
1096
|
source_code_uri: https://github.com/rubocop/rubocop/
|
|
1095
|
-
documentation_uri: https://docs.rubocop.org/rubocop/1.
|
|
1097
|
+
documentation_uri: https://docs.rubocop.org/rubocop/1.82/
|
|
1096
1098
|
bug_tracker_uri: https://github.com/rubocop/rubocop/issues
|
|
1097
1099
|
rubygems_mfa_required: 'true'
|
|
1098
1100
|
rdoc_options: []
|
|
@@ -1109,7 +1111,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
1109
1111
|
- !ruby/object:Gem::Version
|
|
1110
1112
|
version: '0'
|
|
1111
1113
|
requirements: []
|
|
1112
|
-
rubygems_version: 3.6.
|
|
1114
|
+
rubygems_version: 3.6.9
|
|
1113
1115
|
specification_version: 4
|
|
1114
1116
|
summary: Automatic Ruby code style checking tool.
|
|
1115
1117
|
test_files: []
|