Module: Rfmt

Defined in:
lib/rfmt.rb,
lib/rfmt/cli.rb,
lib/rfmt/cache.rb,
lib/rfmt/lsp/uri.rb,
lib/rfmt/version.rb,
lib/rfmt/lsp/server.rb,
lib/rfmt/configuration.rb,
lib/rfmt/lsp/formatter.rb,
lib/rfmt/lsp/workspace.rb,
lib/rfmt/lsp/message_io.rb,
lib/rfmt/lsp/document_store.rb,
lib/rfmt/native_extension_loader.rb

Defined Under Namespace

Modules: Config, LSP, NativeExtensionLoader Classes: CLI, Cache, CacheCommands, Configuration, Error, RfmtError, ValidationError

Constant Summary collapse

VERSION =
'2.0.0.beta1'

Class Method Summary collapse

Class Method Details

.format(source, config_path: nil) ⇒ String

Format Ruby source code Parsing, config resolution, and output validation all happen natively in Rust

Parameters:

  • source (String)

    Ruby source code to format

  • config_path (String, nil) (defaults to: nil)

    Explicit config file path; nil discovers rfmt.yml/.rfmt.yml from the current directory upward (cached per process)

Returns:

  • (String)

    Formatted Ruby code



30
31
32
33
34
35
36
37
38
# File 'lib/rfmt.rb', line 30

def self.format(source, config_path: nil)
  if config_path
    format_code_with_config(source, config_path.to_s)
  else
    format_code(source)
  end
rescue StandardError => e
  raise wrap_native_error(e)
end

.format_file(path) ⇒ String

Format a Ruby file

Parameters:

  • path (String)

    Path to Ruby file

Returns:

  • (String)

    Formatted Ruby code



57
58
59
60
61
62
# File 'lib/rfmt.rb', line 57

def self.format_file(path)
  source = File.read(path)
  format(source)
rescue Errno::ENOENT
  raise Error, "File not found: #{path}"
end

.parse(source) ⇒ String

Parse Ruby code to AST (for debugging)

Parameters:

  • source (String)

    Ruby source code

Returns:

  • (String)

    AST representation



82
83
84
85
86
# File 'lib/rfmt.rb', line 82

def self.parse(source)
  parse_to_json(source)
rescue StandardError => e
  raise wrap_native_error(e)
end

.resolved_config(config_path: nil) ⇒ String

Effective configuration as the Rust formatter resolves it

Parameters:

  • config_path (String, nil) (defaults to: nil)

    Explicit config file path; nil discovers

Returns:

  • (String)

    YAML dump of the resolved configuration



67
68
69
70
71
# File 'lib/rfmt.rb', line 67

def self.resolved_config(config_path: nil)
  resolved_config_yaml(config_path&.to_s)
rescue StandardError => e
  raise wrap_native_error(e)
end

.version_infoString

Get version information

Returns:

  • (String)

    Version string including Ruby and Rust versions



75
76
77
# File 'lib/rfmt.rb', line 75

def self.version_info
  "Ruby: #{VERSION}, Rust: #{rust_version}"
end