123456789_123456789_123456789_123456789_123456789_

Module: RuboCop::MCP::SourceFiles Private

Relationships & Source Files
Defined in: lib/rubocop/mcp/source_files.rb

Overview

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

Class Method Details

.read(file, config) (mod_func)

[ GitHub ]

  
# 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) (mod_func)

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

[ GitHub ]

  
# 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