Module: RuboCop::MCP::SourceFiles Private

Defined in:
lib/rubocop/mcp/source_files.rb

Overview

This module is part of a private API. You should avoid using this module if possible, as it may be removed or be changed in the future.

Reads and writes the files the tools work on. A file that can't be read or written fails the request with an error the agent can act on.

Class Method Summary collapse

Class Method Details

.read(file, config) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



11
12
13
14
15
16
17
# File 'lib/rubocop/mcp/source_files.rb', line 11

def read(file, config)
  RuboCop::ProcessedSource.from_file(
    file, config.target_ruby_version, parser_engine: config.parser_engine
  ).raw_source
rescue Errno::ENOENT
  raise RuboCop::Error, "No such file or directory: #{file}"
end

.write(file, content) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Writing what a file already holds would only bump its modification time.



20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/rubocop/mcp/source_files.rb', line 20

def write(file, content)
  return if File.file?(file) && File.binread(file) == content.b

  Util.replace_file_contents(file, content)
rescue Errno::EACCES
  raise RuboCop::Error, "Permission denied: #{file}"
rescue Errno::EPERM
  raise RuboCop::Error, "Operation not permitted: #{file}"
rescue Errno::ENOSPC
  raise RuboCop::Error, "No space left on device: #{file}"
rescue Errno::EROFS
  raise RuboCop::Error, "Read-only file system: #{file}"
end