{"id":13394923,"url":"https://github.com/ruby-formatter/rufo","last_synced_at":"2025-03-13T20:31:47.123Z","repository":{"id":42203607,"uuid":"97214803","full_name":"ruby-formatter/rufo","owner":"ruby-formatter","description":"The Ruby Formatter","archived":false,"fork":false,"pushed_at":"2024-05-28T09:19:16.000Z","size":11212,"stargazers_count":882,"open_issues_count":26,"forks_count":58,"subscribers_count":12,"default_branch":"master","last_synced_at":"2024-05-29T00:27:54.499Z","etag":null,"topics":["formatter","ruby"],"latest_commit_sha":null,"homepage":"","language":"Ruby","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ruby-formatter.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2017-07-14T09:02:45.000Z","updated_at":"2024-05-30T01:02:12.028Z","dependencies_parsed_at":"2024-05-30T01:02:07.503Z","dependency_job_id":"9f2da0b4-b67c-4a15-b07e-c1c08ddbb14a","html_url":"https://github.com/ruby-formatter/rufo","commit_stats":{"total_commits":772,"total_committers":44,"mean_commits":"17.545454545454547","dds":0.6010362694300518,"last_synced_commit":"dcb0434dcbce77e1c86d74d2f016d2eec917d00f"},"previous_names":[],"tags_count":60,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ruby-formatter%2Frufo","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ruby-formatter%2Frufo/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ruby-formatter%2Frufo/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ruby-formatter%2Frufo/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ruby-formatter","download_url":"https://codeload.github.com/ruby-formatter/rufo/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243478227,"owners_count":20297215,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["formatter","ruby"],"created_at":"2024-07-30T17:01:36.276Z","updated_at":"2025-03-13T20:31:47.103Z","avatar_url":"https://github.com/ruby-formatter.png","language":"Ruby","funding_links":[],"categories":["Ruby","Programming Languages"],"sub_categories":[],"readme":"# Rufo\n\n[![GitHub Actions](https://github.com/ruby-formatter/rufo/workflows/CI/badge.svg)](https://github.com/ruby-formatter/rufo/actions/workflows/ci.yml)\n[![Gem](https://img.shields.io/gem/v/rufo.svg)](https://rubygems.org/gems/rufo)\n\n**Ru**by **fo**rmatter\n\n\nRufo is as an _opinionated_ ruby formatter, intended to be used via the command line as a text-editor plugin, to autoformat files on save or on demand.\n\nUnlike the best known Ruby formatter [RuboCop](https://github.com/bbatsov/rubocop), Rufo offers little in the way of configuration. Like other language formatters such as [gofmt](https://golang.org/cmd/gofmt/), [prettier](https://github.com/prettier/prettier), and [autopep8](https://github.com/hhatto/autopep8), we strive to find a \"one true format\" for Ruby code, and make sure your code adheres to it, with zero config where possible.\n\nRuboCop does much more than just format code though, so feel free to run them both!\n\nRufo supports all Ruby versions \u003e= 3.0.0.\n\n## Installation\n\nAdd this line to your application's Gemfile:\n\n```ruby\ngem 'rufo'\n```\n\nAnd then execute:\n\n    $ bundle\n\nOr install it system wide with:\n\n    $ gem install rufo\n\n## Editor support\n\nOnce the gem is installed, enable format on save integration in your editor of choice with the following libraries:\n\n- Atom: [rufo-atom](https://github.com/bmulvihill/rufo-atom) :construction:\n- Emacs [emacs-rufo](https://github.com/aleandros/emacs-rufo) :construction: or [rufo.el](https://github.com/danielma/rufo.el) or [run rufo with reformatter](https://gist.github.com/kzkn/5c80c24d39e5e7b7881d55ad04605c5b)\n- Sublime Text: [sublime-rufo](https://github.com/ruby-formatter/sublime-rufo)\n- Vim: [rufo-vim](https://github.com/splattael/rufo-vim)\n- Visual Studio Code: [vscode-rufo](https://marketplace.visualstudio.com/items?itemName=mbessey.vscode-rufo) or [rufo-vscode](https://marketplace.visualstudio.com/items?itemName=siliconsenthil.rufo-vscode)\n\nIf you're interested in developing your own plugin check out the [development docs](docs/developing-rufo.md). Did you already write a plugin? That's great! Let us know about it and\nwe will list it here.\n\n\n## Unobtrusive by default\n\nWe Ruby programmers think code beauty and readability is very important. We might align code\nin some ways that a formatter would come and destroy. Many are against automatic code formatters\nfor this reason.\n\nBy default, Rufo is configured in a way that these decisions are preserved. In this way you\ncan start using it in your favorite text editor without forcing your whole team to start using it.\n\nFor example, this code:\n\n```ruby\nclass Foo\n  include Bar\n  extend  Baz\nend\n```\n\nhas an extra space after `extend`, but by doing that `Bar` becomes aligned with `Baz`.\nIt might look better for some, and Rufo preserves this choice by default.\n\nA similar example is aligning call arguments:\n\n```ruby\nregister :command, \"Format\"\nregister :action,  \"Save\"\n```\n\nHere too, an extra space is added to align `\"Format\"` with `\"Save\"`. Again, Rufo will preserve\nthis choice, while still enforcing that truly badly aligned code is formatted.\n\nAnother example is aligning call parameters:\n\n```ruby\n# Align with respect to the first parameter:\nfoo 1, 2,\n    3, 4,\n    5\n\n# Align by regular indent (2 spaces):\nfoo 1, 2,\n  3, 4,\n  5\n\n# Align arrays:\nfoo 1, [\n         2,\n         3,\n       ]\n\n# Don't extra align arrays:\nfoo 1, [\n  2,\n  3,\n]\n\n# Align trailing calls:\nassert foo(\n         1\n       )\n\n# Don't extra align trailing calls:\nassert foo(\n  1\n)\n```\n\nAll of the alignment choices above are fine depending on the context where they are\nused, and Rufo will not destroy that choice. It will, however, keep things aligned\nso they look good.\n\n## Usage\n\n### Format files or directories\n\n```\n# All directories (recursive)\n$ rufo .\n\n# Specific file or directory\n$ rufo [file or directory name]\n```\n\n### Format STDIN\n\n```\n$ cat file.rb | rufo\n```\n\n### Check that no formatting changes are produced\n\n```\n$ rufo --check file names or dir names\n```\n\nThis will print one line for each file that isn't correctly formatted\naccording to **Rufo**, and will exit with exit code 3.\n\n### Exit codes\n\n| Code | Result |\n| ---- | ---- |\n| `0` | No errors, but also no formatting changes |\n| `1` | Error. Either `Ripper` could not parse syntax or input file is missing |\n| `3` | Input changed. Formatted code differs from input |\n\n\n## Configuration\n\nRufo supports limited configuration.\nTo configure Rufo, place a `.rufo` file in your project. Then when you format a file or a directory,\nRufo will look for a `.rufo` file in that directory or parent directories and apply the configuration.\n\nThe `.rufo` file is a Ruby file that is evaluated in the context of the formatter.\nThe available settings are listed [here](docs/settings.md).\n\n## How it works\n\nRufo is a **real** formatter, not a simple find and replace one. It works by employing\na Ruby parser and a Ruby lexer. The parser is used for the shape of the program. The program\nis traversed and the lexer is used to sync this structure to tokens. This is why comments\ncan be handled well, because they are provided by the lexer (comments are not returned by\na parser).\n\nTo parse and lex, [Ripper](https://ruby-doc.org/stdlib-2.4.0/libdoc/ripper/rdoc/Ripper.html) is used.\n\nAs a reference, this was implemented in a similar fashion to [Crystal](https://github.com/crystal-lang/crystal)'s formatter.\n\nAnd as a side note, Rufo has **no dependencies**. To run Rufo's specs you will require [rspec](https://github.com/rspec/rspec), but that's it.\nThis means Rufo loads very fast (no need to read many Ruby files), and since [Ripper](https://ruby-doc.org/stdlib-2.4.0/libdoc/ripper/rdoc/Ripper.html) is mostly written\nin C (uses Ruby's lexer and parser) it formats files pretty fast too.\n\n## Development\n\nAfter checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.\n\nTo install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).\n\n## Contributing\n\nBug reports and pull requests are welcome on GitHub at https://github.com/ruby-formatter/rufo.\n\n## License\n\nThe gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fruby-formatter%2Frufo","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fruby-formatter%2Frufo","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fruby-formatter%2Frufo/lists"}