rubocop 1.75.8 → 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 +20 -16
- data/config/default.yml +142 -33
- data/config/obsoletion.yml +10 -3
- data/exe/rubocop +1 -8
- data/lib/rubocop/cli/command/auto_generate_config.rb +2 -2
- data/lib/rubocop/cli.rb +20 -4
- data/lib/rubocop/comment_config.rb +62 -17
- data/lib/rubocop/config_loader.rb +6 -40
- 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 +2 -3
- data/lib/rubocop/cop/correctors/alignment_corrector.rb +8 -7
- 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 +2 -3
- data/lib/rubocop/cop/gemspec/require_mfa.rb +15 -1
- data/lib/rubocop/cop/gemspec/ruby_version_globals_usage.rb +10 -5
- data/lib/rubocop/cop/internal_affairs/example_description.rb +1 -1
- data/lib/rubocop/cop/internal_affairs/location_exists.rb +28 -2
- data/lib/rubocop/cop/internal_affairs/node_matcher_directive.rb +4 -4
- data/lib/rubocop/cop/internal_affairs/node_pattern_groups/ast_processor.rb +1 -1
- 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_after_guard_clause.rb +3 -0
- 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/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 +43 -10
- 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 +8 -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 +7 -2
- 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/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/duplicate_methods.rb +25 -4
- data/lib/rubocop/cop/lint/duplicate_regexp_character_class_element.rb +5 -42
- data/lib/rubocop/cop/lint/else_layout.rb +19 -0
- data/lib/rubocop/cop/lint/empty_interpolation.rb +14 -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 +38 -28
- data/lib/rubocop/cop/lint/literal_in_interpolation.rb +1 -1
- data/lib/rubocop/cop/lint/missing_cop_enable_directive.rb +17 -8
- data/lib/rubocop/cop/lint/no_return_in_begin_end_blocks.rb +4 -0
- data/lib/rubocop/cop/lint/numeric_operation_with_constant_result.rb +1 -0
- data/lib/rubocop/cop/lint/redundant_cop_disable_directive.rb +23 -9
- data/lib/rubocop/cop/lint/redundant_regexp_quantifiers.rb +1 -1
- data/lib/rubocop/cop/lint/redundant_require_statement.rb +4 -2
- data/lib/rubocop/cop/lint/redundant_safe_navigation.rb +101 -2
- data/lib/rubocop/cop/lint/redundant_splat_expansion.rb +7 -1
- 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_exception.rb +1 -4
- 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 +39 -5
- 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/unreachable_code.rb +5 -3
- 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_assignment.rb +44 -16
- 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 +111 -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/metrics/utils/abc_size_calculator.rb +4 -3
- 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/check_single_line_suitability.rb +2 -4
- data/lib/rubocop/cop/mixin/code_length.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/hash_shorthand_syntax.rb +1 -1
- data/lib/rubocop/cop/mixin/line_length_help.rb +45 -10
- 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/ordered_gem_node.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/file_name.rb +2 -2
- data/lib/rubocop/cop/naming/method_name.rb +129 -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/json_load.rb +33 -11
- 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 +99 -35
- 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/bitwise_predicate.rb +8 -1
- data/lib/rubocop/cop/style/block_delimiters.rb +1 -1
- data/lib/rubocop/cop/style/case_equality.rb +11 -13
- data/lib/rubocop/cop/style/case_like_if.rb +1 -1
- data/lib/rubocop/cop/style/class_and_module_children.rb +1 -0
- data/lib/rubocop/cop/style/collection_querying.rb +167 -0
- data/lib/rubocop/cop/style/conditional_assignment.rb +12 -16
- data/lib/rubocop/cop/style/constant_visibility.rb +17 -12
- 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_method.rb +0 -6
- data/lib/rubocop/cop/style/empty_string_inside_interpolation.rb +100 -0
- 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/exponential_notation.rb +3 -2
- data/lib/rubocop/cop/style/fetch_env_var.rb +32 -6
- 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_conversion.rb +16 -8
- data/lib/rubocop/cop/style/hash_syntax.rb +1 -1
- data/lib/rubocop/cop/style/if_unless_modifier.rb +16 -9
- 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/require_parentheses.rb +12 -1
- data/lib/rubocop/cop/style/method_call_with_args_parentheses.rb +33 -4
- data/lib/rubocop/cop/style/min_max_comparison.rb +13 -5
- 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 +34 -22
- data/lib/rubocop/cop/style/redundant_argument.rb +2 -0
- 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 +26 -5
- data/lib/rubocop/cop/style/redundant_freeze.rb +1 -1
- data/lib/rubocop/cop/style/redundant_interpolation.rb +12 -3
- 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_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_self.rb +8 -5
- data/lib/rubocop/cop/style/redundant_sort.rb +7 -7
- data/lib/rubocop/cop/style/safe_navigation.rb +44 -12
- data/lib/rubocop/cop/style/semicolon.rb +23 -7
- data/lib/rubocop/cop/style/single_line_methods.rb +7 -4
- data/lib/rubocop/cop/style/sole_nested_conditional.rb +40 -3
- 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/super_arguments.rb +2 -2
- 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/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/cop/variable_force/variable.rb +1 -1
- data/lib/rubocop/cop/variable_force.rb +25 -8
- data/lib/rubocop/cops_documentation_generator.rb +5 -4
- data/lib/rubocop/directive_comment.rb +46 -3
- data/lib/rubocop/formatter/disabled_config_formatter.rb +19 -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 +14 -18
- data/lib/rubocop/lsp/routes.rb +35 -6
- data/lib/rubocop/lsp/stdin_runner.rb +0 -16
- data/lib/rubocop/magic_comment.rb +20 -0
- data/lib/rubocop/pending_cops_reporter.rb +56 -0
- data/lib/rubocop/rake_task.rb +1 -1
- data/lib/rubocop/remote_config.rb +7 -8
- data/lib/rubocop/result_cache.rb +51 -38
- data/lib/rubocop/rspec/expect_offense.rb +9 -3
- data/lib/rubocop/rspec/shared_contexts.rb +2 -2
- data/lib/rubocop/rspec/support.rb +1 -1
- data/lib/rubocop/runner.rb +10 -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 +11 -2
- data/lib/rubocop/version.rb +1 -1
- data/lib/rubocop.rb +13 -1
- data/lib/ruby_lsp/rubocop/addon.rb +25 -10
- data/lib/ruby_lsp/rubocop/runtime_adapter.rb +49 -15
- metadata +20 -8
data/lib/rubocop/result_cache.rb
CHANGED
|
@@ -9,7 +9,7 @@ module RuboCop
|
|
|
9
9
|
# Provides functionality for caching RuboCop runs.
|
|
10
10
|
# @api private
|
|
11
11
|
class ResultCache
|
|
12
|
-
NON_CHANGING = %i[color format formatters out debug fail_level
|
|
12
|
+
NON_CHANGING = %i[color format formatters out debug display_time fail_level
|
|
13
13
|
fix_layout autocorrect safe_autocorrect autocorrect_all
|
|
14
14
|
cache fail_fast stdin parallel].freeze
|
|
15
15
|
|
|
@@ -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,34 +194,37 @@ 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
|
-
content = if path.end_with?(*DL_EXTENSIONS)
|
|
191
|
-
# Shared libraries often contain timestamps of when
|
|
192
|
-
# they were compiled and other non-stable data.
|
|
193
|
-
File.basename(path)
|
|
194
|
-
else
|
|
195
|
-
File.binread(path) # mtime not reliable
|
|
196
|
-
end
|
|
197
|
-
Zlib.crc32(content).to_s
|
|
198
|
-
end
|
|
199
|
+
private
|
|
199
200
|
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
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
|
|
203
211
|
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
212
|
+
def rubocop_extra_features
|
|
213
|
+
lib_root = File.join(File.dirname(__FILE__), '..')
|
|
214
|
+
exe_root = File.join(lib_root, '..', 'exe')
|
|
207
215
|
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
source_files = $LOADED_FEATURES + Find.find(exe_root).to_a
|
|
212
|
-
source_files -= ResultCache.rubocop_required_features # Rely on gem versions
|
|
216
|
+
# Make sure to use an absolute path to prevent errors on Windows
|
|
217
|
+
# when traversing the relative paths with symlinks.
|
|
218
|
+
exe_root = File.absolute_path(exe_root)
|
|
213
219
|
|
|
214
|
-
|
|
220
|
+
# These are all the files we have `require`d plus everything in the
|
|
221
|
+
# exe directory. A change to any of them could affect the cop output
|
|
222
|
+
# so we include them in the cache hash.
|
|
223
|
+
source_files = $LOADED_FEATURES + Find.find(exe_root).to_a
|
|
224
|
+
source_files -= ResultCache.rubocop_required_features # Rely on gem versions
|
|
225
|
+
|
|
226
|
+
source_files
|
|
227
|
+
end
|
|
215
228
|
end
|
|
216
229
|
|
|
217
230
|
# Return a hash of the options given at invocation, minus the ones that have
|
|
@@ -72,9 +72,15 @@ module RuboCop
|
|
|
72
72
|
#
|
|
73
73
|
# expect_no_corrections
|
|
74
74
|
#
|
|
75
|
-
# If your code has variables of different lengths, you can use
|
|
76
|
-
#
|
|
77
|
-
#
|
|
75
|
+
# If your code has variables of different lengths, you can use the
|
|
76
|
+
# following markers to format your template by passing the variables as a
|
|
77
|
+
# keyword arguments:
|
|
78
|
+
#
|
|
79
|
+
# - `%{foo}`: Interpolates `foo`
|
|
80
|
+
# - `^{foo}`: Inserts `'^' * foo.size` for dynamic offense range length
|
|
81
|
+
# - `_{foo}`: Inserts `' ' * foo.size` for dynamic offense range indentation
|
|
82
|
+
#
|
|
83
|
+
# You can also abbreviate offense messages with `[...]`.
|
|
78
84
|
#
|
|
79
85
|
# %w[raise fail].each do |keyword|
|
|
80
86
|
# expect_offense(<<~RUBY, keyword: keyword)
|
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)
|
|
@@ -273,7 +277,8 @@ module RuboCop
|
|
|
273
277
|
end
|
|
274
278
|
|
|
275
279
|
def do_inspection_loop(file)
|
|
276
|
-
|
|
280
|
+
# We can reuse the prism result since the source did not change yet.
|
|
281
|
+
processed_source = get_processed_source(file, @prism_result)
|
|
277
282
|
# This variable is 2d array used to track corrected offenses after each
|
|
278
283
|
# inspection iteration. This is used to output meaningful infinite loop
|
|
279
284
|
# error message.
|
|
@@ -295,7 +300,8 @@ module RuboCop
|
|
|
295
300
|
# loop if we find any.
|
|
296
301
|
break unless updated_source_file
|
|
297
302
|
|
|
298
|
-
|
|
303
|
+
# Autocorrect has happened, don't use the prism result since it is stale.
|
|
304
|
+
processed_source = get_processed_source(file, nil)
|
|
299
305
|
end
|
|
300
306
|
|
|
301
307
|
# Return summary of corrected offenses after all iterations
|
|
@@ -482,7 +488,7 @@ module RuboCop
|
|
|
482
488
|
end
|
|
483
489
|
|
|
484
490
|
# rubocop:disable Metrics/MethodLength
|
|
485
|
-
def get_processed_source(file)
|
|
491
|
+
def get_processed_source(file, prism_result)
|
|
486
492
|
config = @config_store.for_file(file)
|
|
487
493
|
ruby_version = config.target_ruby_version
|
|
488
494
|
parser_engine = config.parser_engine
|
|
@@ -493,7 +499,7 @@ module RuboCop
|
|
|
493
499
|
ruby_version,
|
|
494
500
|
file,
|
|
495
501
|
parser_engine: parser_engine,
|
|
496
|
-
prism_result:
|
|
502
|
+
prism_result: prism_result
|
|
497
503
|
)
|
|
498
504
|
else
|
|
499
505
|
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
|
@@ -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
|
@@ -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'
|
|
@@ -599,11 +608,13 @@ require_relative 'rubocop/cop/style/map_to_set'
|
|
|
599
608
|
require_relative 'rubocop/cop/style/method_call_without_args_parentheses'
|
|
600
609
|
require_relative 'rubocop/cop/style/method_call_with_args_parentheses'
|
|
601
610
|
require_relative 'rubocop/cop/style/min_max_comparison'
|
|
611
|
+
require_relative 'rubocop/cop/style/module_member_existence_check'
|
|
602
612
|
require_relative 'rubocop/cop/style/multiline_in_pattern_then'
|
|
603
613
|
require_relative 'rubocop/cop/style/numbered_parameters'
|
|
604
614
|
require_relative 'rubocop/cop/style/open_struct_use'
|
|
605
615
|
require_relative 'rubocop/cop/style/operator_method_call'
|
|
606
616
|
require_relative 'rubocop/cop/style/redundant_array_constructor'
|
|
617
|
+
require_relative 'rubocop/cop/style/redundant_array_flatten'
|
|
607
618
|
require_relative 'rubocop/cop/style/redundant_assignment'
|
|
608
619
|
require_relative 'rubocop/cop/style/redundant_constant_base'
|
|
609
620
|
require_relative 'rubocop/cop/style/redundant_current_directory_in_path'
|
|
@@ -805,6 +816,7 @@ require_relative 'rubocop/options'
|
|
|
805
816
|
require_relative 'rubocop/remote_config'
|
|
806
817
|
require_relative 'rubocop/target_ruby'
|
|
807
818
|
require_relative 'rubocop/yaml_duplication_checker'
|
|
819
|
+
require_relative 'rubocop/pending_cops_reporter'
|
|
808
820
|
|
|
809
821
|
# rubocop:enable Style/RequireOrder
|
|
810
822
|
|
|
@@ -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)
|