rubocop 1.75.8 → 1.81.7
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 +121 -28
 - 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_loader_resolver.rb +5 -4
 - 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/hash_alignment.rb +2 -5
 - 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/constant_overwritten_in_rescue.rb +3 -2
 - data/lib/rubocop/cop/lint/cop_directive_syntax.rb +13 -7
 - 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_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 +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 +34 -28
 - data/lib/rubocop/cop/lint/missing_cop_enable_directive.rb +17 -8
 - 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_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 +31 -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/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 +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/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 +11 -5
 - data/lib/rubocop/cop/style/constant_visibility.rb +14 -9
 - 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/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/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/one_line_conditional.rb +17 -9
 - 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 +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_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/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/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 +5 -4
 - 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 +18 -7
 
| 
         @@ -0,0 +1,56 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            # frozen_string_literal: true
         
     | 
| 
      
 2 
     | 
    
         
            +
             
     | 
| 
      
 3 
     | 
    
         
            +
            module RuboCop
         
     | 
| 
      
 4 
     | 
    
         
            +
              # Reports information about pending cops that are not explicitly configured.
         
     | 
| 
      
 5 
     | 
    
         
            +
              #
         
     | 
| 
      
 6 
     | 
    
         
            +
              # This class is responsible for displaying warnings when new cops have been added to RuboCop
         
     | 
| 
      
 7 
     | 
    
         
            +
              # but have not yet been enabled or disabled in the user's configuration.
         
     | 
| 
      
 8 
     | 
    
         
            +
              # It provides a centralized way to determine whether such warnings should be shown,
         
     | 
| 
      
 9 
     | 
    
         
            +
              # based on global flags or configuration settings.
         
     | 
| 
      
 10 
     | 
    
         
            +
              class PendingCopsReporter
         
     | 
| 
      
 11 
     | 
    
         
            +
                class << self
         
     | 
| 
      
 12 
     | 
    
         
            +
                  PENDING_BANNER = <<~BANNER
         
     | 
| 
      
 13 
     | 
    
         
            +
                    The following cops were added to RuboCop, but are not configured. Please set Enabled to either `true` or `false` in your `.rubocop.yml` file.
         
     | 
| 
      
 14 
     | 
    
         
            +
             
     | 
| 
      
 15 
     | 
    
         
            +
                    Please also note that you can opt-in to new cops by default by adding this to your config:
         
     | 
| 
      
 16 
     | 
    
         
            +
                      AllCops:
         
     | 
| 
      
 17 
     | 
    
         
            +
                        NewCops: enable
         
     | 
| 
      
 18 
     | 
    
         
            +
                  BANNER
         
     | 
| 
      
 19 
     | 
    
         
            +
             
     | 
| 
      
 20 
     | 
    
         
            +
                  attr_accessor :disable_pending_cops, :enable_pending_cops
         
     | 
| 
      
 21 
     | 
    
         
            +
             
     | 
| 
      
 22 
     | 
    
         
            +
                  def warn_if_needed(config)
         
     | 
| 
      
 23 
     | 
    
         
            +
                    return if possible_new_cops?(config)
         
     | 
| 
      
 24 
     | 
    
         
            +
             
     | 
| 
      
 25 
     | 
    
         
            +
                    pending_cops = pending_cops_only_qualified(config.pending_cops)
         
     | 
| 
      
 26 
     | 
    
         
            +
                    warn_on_pending_cops(pending_cops) unless pending_cops.empty?
         
     | 
| 
      
 27 
     | 
    
         
            +
                  end
         
     | 
| 
      
 28 
     | 
    
         
            +
             
     | 
| 
      
 29 
     | 
    
         
            +
                  private
         
     | 
| 
      
 30 
     | 
    
         
            +
             
     | 
| 
      
 31 
     | 
    
         
            +
                  def pending_cops_only_qualified(pending_cops)
         
     | 
| 
      
 32 
     | 
    
         
            +
                    pending_cops.select { |cop| Cop::Registry.qualified_cop?(cop.name) }
         
     | 
| 
      
 33 
     | 
    
         
            +
                  end
         
     | 
| 
      
 34 
     | 
    
         
            +
             
     | 
| 
      
 35 
     | 
    
         
            +
                  def possible_new_cops?(config)
         
     | 
| 
      
 36 
     | 
    
         
            +
                    disable_pending_cops || enable_pending_cops ||
         
     | 
| 
      
 37 
     | 
    
         
            +
                      config.disabled_new_cops? || config.enabled_new_cops?
         
     | 
| 
      
 38 
     | 
    
         
            +
                  end
         
     | 
| 
      
 39 
     | 
    
         
            +
             
     | 
| 
      
 40 
     | 
    
         
            +
                  def warn_on_pending_cops(pending_cops)
         
     | 
| 
      
 41 
     | 
    
         
            +
                    warn Rainbow(PENDING_BANNER).yellow
         
     | 
| 
      
 42 
     | 
    
         
            +
             
     | 
| 
      
 43 
     | 
    
         
            +
                    pending_cops.each { |cop| warn_pending_cop cop }
         
     | 
| 
      
 44 
     | 
    
         
            +
             
     | 
| 
      
 45 
     | 
    
         
            +
                    warn Rainbow('For more information: https://docs.rubocop.org/rubocop/versioning.html').yellow
         
     | 
| 
      
 46 
     | 
    
         
            +
                  end
         
     | 
| 
      
 47 
     | 
    
         
            +
             
     | 
| 
      
 48 
     | 
    
         
            +
                  def warn_pending_cop(cop)
         
     | 
| 
      
 49 
     | 
    
         
            +
                    version = cop.metadata['VersionAdded'] || 'N/A'
         
     | 
| 
      
 50 
     | 
    
         
            +
             
     | 
| 
      
 51 
     | 
    
         
            +
                    warn Rainbow("#{cop.name}: # new in #{version}").yellow
         
     | 
| 
      
 52 
     | 
    
         
            +
                    warn Rainbow('  Enabled: true').yellow
         
     | 
| 
      
 53 
     | 
    
         
            +
                  end
         
     | 
| 
      
 54 
     | 
    
         
            +
                end
         
     | 
| 
      
 55 
     | 
    
         
            +
              end
         
     | 
| 
      
 56 
     | 
    
         
            +
            end
         
     | 
    
        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 
     | 
    
         | 
| 
         @@ -198,20 +198,22 @@ module RuboCop 
     | 
|
| 
       198 
198 
     | 
    
         
             
                end
         
     | 
| 
       199 
199 
     | 
    
         | 
| 
       200 
200 
     | 
    
         
             
                def rubocop_extra_features
         
     | 
| 
       201 
     | 
    
         
            -
                   
     | 
| 
       202 
     | 
    
         
            -
             
     | 
| 
      
 201 
     | 
    
         
            +
                  @rubocop_extra_features ||= begin
         
     | 
| 
      
 202 
     | 
    
         
            +
                    lib_root = File.join(File.dirname(__FILE__), '..')
         
     | 
| 
      
 203 
     | 
    
         
            +
                    exe_root = File.join(lib_root, '..', 'exe')
         
     | 
| 
       203 
204 
     | 
    
         | 
| 
       204 
     | 
    
         
            -
             
     | 
| 
       205 
     | 
    
         
            -
             
     | 
| 
       206 
     | 
    
         
            -
             
     | 
| 
      
 205 
     | 
    
         
            +
                    # Make sure to use an absolute path to prevent errors on Windows
         
     | 
| 
      
 206 
     | 
    
         
            +
                    # when traversing the relative paths with symlinks.
         
     | 
| 
      
 207 
     | 
    
         
            +
                    exe_root = File.absolute_path(exe_root)
         
     | 
| 
       207 
208 
     | 
    
         | 
| 
       208 
     | 
    
         
            -
             
     | 
| 
       209 
     | 
    
         
            -
             
     | 
| 
       210 
     | 
    
         
            -
             
     | 
| 
       211 
     | 
    
         
            -
             
     | 
| 
       212 
     | 
    
         
            -
             
     | 
| 
      
 209 
     | 
    
         
            +
                    # These are all the files we have `require`d plus everything in the
         
     | 
| 
      
 210 
     | 
    
         
            +
                    # exe directory. A change to any of them could affect the cop output
         
     | 
| 
      
 211 
     | 
    
         
            +
                    # so we include them in the cache hash.
         
     | 
| 
      
 212 
     | 
    
         
            +
                    source_files = $LOADED_FEATURES + Find.find(exe_root).to_a
         
     | 
| 
      
 213 
     | 
    
         
            +
                    source_files -= ResultCache.rubocop_required_features # Rely on gem versions
         
     | 
| 
       213 
214 
     | 
    
         | 
| 
       214 
     | 
    
         
            -
             
     | 
| 
      
 215 
     | 
    
         
            +
                    source_files
         
     | 
| 
      
 216 
     | 
    
         
            +
                  end
         
     | 
| 
       215 
217 
     | 
    
         
             
                end
         
     | 
| 
       216 
218 
     | 
    
         | 
| 
       217 
219 
     | 
    
         
             
                # 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
    
    | 
         @@ -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)
         
     |