123456789_123456789_123456789_123456789_123456789_

Class: RuboCop::MCP::AutocorrectionRequest Private

Relationships & Source Files
Inherits: Object
Defined in: lib/rubocop/mcp/autocorrection_request.rb

Overview

What an autocorrection request asks for, shared by every file it corrects. The keywords are the tool’s arguments, so an unknown one is refused.

Constant Summary

Class Method Summary

Instance Attribute Summary

Instance Method Summary

  • #format_options Internal use only

    The options LSP::Runtime#format takes to apply the corrections safety and contextual allow, from the cops the scope selects.

  • #runtime_options Internal use only

    The options the LSP runtime takes for each call the request makes.

Constructor Details

.new(scope, safety: true, contextual: false, dry_run: false, max_offenses_per_cop: DEFAULT_MAX_OFFENSES_PER_COP) ⇒ AutocorrectionRequest

[ GitHub ]

  
# File 'lib/rubocop/mcp/autocorrection_request.rb', line 23

def initialize(scope, safety: true, contextual: false, dry_run: false,
               max_offenses_per_cop: DEFAULT_MAX_OFFENSES_PER_COP)
  @scope = scope
  @safety = safety
  @contextual = contextual
  @dry_run = dry_run
  @limit = OffenseLimit.new(max_offenses_per_cop)
end

Instance Attribute Details

#dry_run? ⇒ Boolean (readonly)

[ GitHub ]

  
# File 'lib/rubocop/mcp/autocorrection_request.rb', line 32

def dry_run?
  @dry_run
end

#limit (readonly)

[ GitHub ]

  
# File 'lib/rubocop/mcp/autocorrection_request.rb', line 21

attr_reader :scope, :limit

#scope (readonly)

[ GitHub ]

  
# File 'lib/rubocop/mcp/autocorrection_request.rb', line 21

attr_reader :scope, :limit

Instance Method Details

#format_options

The options LSP::Runtime#format takes to apply the corrections safety and contextual allow, from the cops the scope selects.

[ GitHub ]

  
# File 'lib/rubocop/mcp/autocorrection_request.rb', line 38

def format_options
  command = @safety ? 'rubocop.formatAutocorrects' : 'rubocop.formatAutocorrectsAll'
  { command: command, options: runtime_options }
end

#runtime_options

The options the LSP runtime takes for each call the request makes. Cops with AutoCorrect: contextual hold back corrections that get in the way of code still being written, such as removing a variable that is about to be used, so an agent that is done editing has to ask for them.

[ GitHub ]

  
# File 'lib/rubocop/mcp/autocorrection_request.rb', line 47

def runtime_options
  { **@scope.cop_options, editing: !@contextual }
end