MCPcopy Index your code
hub / github.com/fables-tales/rubyfmt

github.com/fables-tales/rubyfmt @v0.14.2-6

Chat with this repo
repository ↗ · DeepWiki ↗ · release v0.14.2-6 ↗ · + Follow
1,712 symbols 3,726 edges 819 files 310 documented · 18%
What it actually does AI analysis from the code graph — generated when you open this
loading…
README

rubyfmt

A fast, opinionated Ruby formatter written in Rust.

Pronunciation: (en) "Ruby Format", (jp) ルビーフォーマット

Quick Start

# Install
brew install rubyfmt

# Format a file in place
rubyfmt -i myfile.rb

# Format and print to stdout
rubyfmt myfile.rb

Installation

Homebrew

brew install rubyfmt

Build from Source

  1. Make sure you have Cargo installed
  2. Run cargo build --release
  3. Copy target/release/rubyfmt-main to somewhere on your path as rubyfmt

Usage

Command Line

Command Description
rubyfmt file.rb Output formatted code to stdout
rubyfmt -i file.rb Format file in place
rubyfmt -c file.rb Show diff of changes
cat file.rb \| rubyfmt Read from stdin

You can also pass directories to format multiple files at once.

For the full command line interface, see rubyfmt --help.

Header Comments

Control formatting on a per-file basis with header comments:

  • rubyfmt --header-opt-in - Only format files with # rubyfmt: true at the top
  • rubyfmt --header-opt-out - Skip files with # rubyfmt: false at the top

Ignoring Files

Create a .rubyfmtignore file in your project root to exclude files from formatting. It uses the same syntax as .gitignore.

By default, rubyfmt also respects your .gitignore. Use --include-gitignored to format those files anyway.

Editor Integration

Visual Studio Code

The popular ruby-lsp extension has a rubyfmt add-on. Install the extension:

# Add to project
bundle add ruby-lsp-rubyfmt-formatter --group development

# Install globally
gem install ruby-lsp-rubyfmt-formatter

And then add the following to your .vscode/settings.json:

{
  "[ruby]": {
    "editor.defaultFormatter": "Shopify.ruby-lsp",
    "editor.formatOnSave": true
  },
  "rubyLsp.formatter": "rubyfmt"
}

Rubyfmt is also supported by the (now-deprecated) VSCode Ruby extension. Add the following to your settings.json:

{
  "ruby.useLanguageServer": true,
  "ruby.format": "rubyfmt",
  "[ruby]": {
    "editor.formatOnSave": true
  }
}

This is additionally supported by the Formatto for VS Code extension. Use it as your project's formatter by adding this entry to your .vscode/settings.json after installing the extension:

{
  "[ruby]": {
    "editor.defaultFormatter": "damolinx.formatto"
  },
}

Check its README for additional configuration options.

Neovim + null-ls

The null-ls plugin supports rubyfmt out of the box:

null_ls.setup({
  sources = {
    null_ls.builtins.formatting.rubyfmt,
  },
})

See the null-ls documentation for more details.

Vim

vim-plug:

Plug 'fables-tales/rubyfmt', { 'rtp': 'editor_plugins/vim' }

Native packages:

git clone https://github.com/fables-tales/rubyfmt ~/.rubyfmt
ln -s ~/.rubyfmt/editor_plugins/vim ~/.vim/pack/rubyfmt/start/rubyfmt

Set g:rubyfmt_path if rubyfmt is not on your $PATH.

RubyMine (and JetBrains IDEs)

  1. Install the File Watchers plugin
  2. Go to File | Settings | Tools | File Watchers
  3. Import watchers.xml
  4. Optionally set Level to Global for all projects

See the File Watchers documentation for more details.

Sublime Text

Install the rubyfmt plugin via Package Control.

Files format on save or with Cmd + ; (macOS) / Alt + ; (other). Settings:

{
  "ruby_executable": "ruby",
  "rubyfmt_executable": "rubyfmt",
  "format_on_save": true
}

Atom

Install the rubyfmt package from Settings > Packages.

Files format on save or with Cmd + ; (macOS) / Alt + ; (other).

Rubocop

For usage with Rubocop, see the rubocop-rubyfmt gem.

Contributing

Please check out our contributing guide.

Maintenance Status

The original author (fables-tales) is no longer working on open source in their spare time. Other contributors work regularly on rubyfmt, and contributors with commit access are welcome to merge changes that pass CI.

Extension points exported contracts — how you extend this code

Merge (Interface)
(no doc) [2 implementers]
librubyfmt/src/comment_block.rs
AbstractTokenTarget (Interface)
(no doc) [2 implementers]
librubyfmt/src/render_targets.rs

Core symbols most depended-on inside this repo

foo
called by 162
fixtures/small/zsuper_actual.rb
with_start_of_line
called by 148
librubyfmt/src/parser_state.rs
format_node
called by 138
librubyfmt/src/format_prism.rs
new
called by 106
librubyfmt/src/intermediary.rs
path
called by 105
fixtures/small/scoping_actual.rb
push
called by 87
librubyfmt/src/intermediary.rs
emit_ident
called by 84
librubyfmt/src/parser_state.rs
emit_space
called by 78
librubyfmt/src/parser_state.rs

Shape

Method 825
Function 544
Class 324
Enum 17
Interface 2

Languages

Ruby66%
Rust34%

Modules by API surface

librubyfmt/src/format_prism.rs205 symbols
librubyfmt/src/parser_state.rs103 symbols
fixtures/large/rspec_mocks_proxy_expected.rb62 symbols
fixtures/large/rspec_mocks_proxy_actual.rb62 symbols
fixtures/large/rspec_core_notifications_expected.rb58 symbols
fixtures/large/rspec_core_notifications_actual.rb58 symbols
tests/cli_interface_test.rs46 symbols
librubyfmt/src/render_targets.rs44 symbols
librubyfmt/src/string_escape.rs36 symbols
fixtures/large/concurrent-ruby/non_concurrent_map_backend_expected.rb24 symbols
fixtures/large/concurrent-ruby/non_concurrent_map_backend_actual.rb24 symbols
librubyfmt/src/line_tokens.rs20 symbols

For agents

$ claude mcp add rubyfmt \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact