A fast, opinionated Ruby formatter written in Rust.
Pronunciation: (en) "Ruby Format", (jp) ルビーフォーマット
# Install
brew install rubyfmt
# Format a file in place
rubyfmt -i myfile.rb
# Format and print to stdout
rubyfmt myfile.rb
brew install rubyfmt
cargo build --releasetarget/release/rubyfmt-main to somewhere on your path as rubyfmt| 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.
Control formatting on a per-file basis with header comments:
rubyfmt --header-opt-in - Only format files with # rubyfmt: true at the toprubyfmt --header-opt-out - Skip files with # rubyfmt: false at the topCreate 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.
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.
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-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.
watchers.xmlSee the File Watchers documentation for more details.
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
}
Install the rubyfmt package from Settings > Packages.
Files format on save or with Cmd + ; (macOS) / Alt + ; (other).
For usage with Rubocop, see the rubocop-rubyfmt gem.
Please check out our contributing guide.
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.
(top 30 of 46)
Rust
54.8%
Ruby
44.0%
A fast, opinionated Ruby formatter written in Rust.
Pronunciation: (en) "Ruby Format", (jp) ルビーフォーマット
# Install
brew install rubyfmt
# Format a file in place
rubyfmt -i myfile.rb
# Format and print to stdout
rubyfmt myfile.rb
brew install rubyfmt
cargo build --releasetarget/release/rubyfmt-main to somewhere on your path as rubyfmt| 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.
Control formatting on a per-file basis with header comments:
rubyfmt --header-opt-in - Only format files with # rubyfmt: true at the toprubyfmt --header-opt-out - Skip files with # rubyfmt: false at the topCreate 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.
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.
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-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.
watchers.xmlSee the File Watchers documentation for more details.
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
}
Install the rubyfmt package from Settings > Packages.
Files format on save or with Cmd + ; (macOS) / Alt + ; (other).
For usage with Rubocop, see the rubocop-rubyfmt gem.
Please check out our contributing guide.
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.
(top 30 of 46)
Rust
54.8%
Ruby
44.0%