Skip to content
Prettier Ruby Plugin
JavaScript Ruby Shell
Branch: master
Clone or download

Latest commit

kddeisz Merge pull request #570 from prettier/dependabot/npm_and_yarn/all-con…
…tributors-cli-6.15.0

Bump all-contributors-cli from 6.14.2 to 6.15.0
Latest commit ed8b41f May 24, 2020

Files

Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
.github Upgrade node version in test May 24, 2020
bin Print with new prettier Mar 23, 2020
docs [ci skip] Add logo Mar 1, 2019
exe Rename the ruby executable to rbprettier for easier autocomplete Mar 4, 2019
lib Infra for the ruby gem Apr 23, 2019
playground Inline the utils module Mar 10, 2020
src Do not add an empty line after `rescue` when the block is empty May 1, 2020
test Do not add an empty line after `rescue` when the block is empty May 1, 2020
.all-contributorsrc Add @janklimo as a contributor May 1, 2020
.eslintignore Add eslint config Mar 3, 2019
.gitignore Add a GitHub action (#500) Mar 17, 2020
.npmignore Heroku infra for playground Nov 5, 2019
.prettierignore Include test.rb in prettierignore Apr 5, 2020
CHANGELOG.md Increment version May 1, 2020
CODE_OF_CONDUCT.md Run prettier on non-js files Apr 24, 2019
CONTRIBUTING.md Fix typo in contributing doc [ci skip] (#471) Feb 12, 2020
Gemfile Haml support (#432) Nov 12, 2019
LICENSE Update LICENSE Apr 28, 2020
README.md Add @janklimo as a contributor May 1, 2020
Rakefile Fix up ruby tests Apr 14, 2019
package.json Upgrade eslint May 24, 2020
prettier.gemspec Add a GitHub action (#500) Mar 17, 2020
yarn.lock Bump all-contributors-cli from 6.14.2 to 6.15.0 May 24, 2020

README.md

Prettier Ruby

Prettier for Ruby

Gitter GitHub Actions NPM Version code style: prettier Follow+Prettier+on+Twitter

@prettier/plugin-ruby is a prettier plugin for the Ruby programming language and its ecosystem. prettier is an opinionated code formatter that supports multiple languages and integrates with most editors. The idea is to eliminate discussions of style in code review and allow developers to get back to thinking about code design instead.

For example, the below code segment:

        d=[30644250780,9003106878,
    30636278846,66641217692,4501790980,
 671_24_603036,131_61973916,66_606629_920,
   30642677916,30643069058];a,s=[],$*[0]
      s.each_byte{|b|a<<("%036b"%d[b.
         chr.to_i]).scan(/\d{6}/)}
          a.transpose.each{ |a|
            a.join.each_byte{\
             |i|print i==49?\
               ($*[1]||"#")\
                 :32.chr}
                   puts
                    }

when run through @prettier/plugin-ruby will generate:

d = [
  30_644_250_780,
  9_003_106_878,
  30_636_278_846,
  66_641_217_692,
  4_501_790_980,
  671_24_603036,
  131_61973916,
  66_606629_920,
  30_642_677_916,
  30_643_069_058
]
a, s = [], $*[0]
s.each_byte { |b| a << ('%036b' % d[b.chr.to_i]).scan(/\d{6}/) }
a.transpose.each do |a|
  a.join.each_byte { |i| print i == 49 ? ($*[1] || '#') : 32.chr }
  puts
end

Getting started

To run prettier with the Ruby plugin, you're going to need ruby (version 2.5 or newer) and node (version 8.3 or newer). If you're integrating with a project that is not already using prettier, you should use the Ruby gem. Otherwise you can use the npm package directly.

Note that currently the editor integrations work best with the npm package, as most of the major editor plugins expect a node_modules directory. You can get them to work with the Ruby gem, but it requires manually configuring the paths.

Ruby gem

Add this line to your application's Gemfile:

gem 'prettier'

And then execute:

bundle

Or install it yourself as:

gem install prettier

The rbprettier executable is now installed and ready for use:

bundle exec rbprettier --write '**/*.rb'

npm package

If you're using the npm CLI, then add the plugin by:

npm install --save-dev prettier @prettier/plugin-ruby

Or if you're using yarn, then add the plugin by:

yarn add --dev prettier @prettier/plugin-ruby

The prettier executable is now installed and ready for use:

./node_modules/.bin/prettier --write '**/*.rb'

Configuration

Below are the options (from src/ruby.js) that @prettier/plugin-ruby currently supports:

API Option CLI Option Default Description
printWidth --print-width 80 Same as in Prettier (see prettier docs).
requirePragma --require-pragma false Same as in Prettier (see prettier docs).
tabWidth --tab-width 2 Same as in Prettier (see prettier docs).
addTrailingCommas --add-trailing-commas false Adds a trailing comma to array literals, hash literals, and method calls.
inlineConditionals --inline-conditionals true When it fits on one line, allows if and unless statements to use the modifier form.
inlineLoops --inline-loops true When it fits on one line, allows while and until statements to use the modifier form.
preferHashLabels --prefer-hash-labels true When possible, uses the shortened hash key syntax, as opposed to hash rockets.
preferSingleQuotes --prefer-single-quotes true When double quotes are not necessary for interpolation, prefers the use of single quotes for string literals.

Any of these can be added to your existing prettier configuration file. For example:

{
  "preferSingleQuotes": false
}

Or, they can be passed to prettier as arguments:

prettier --prefer-single-quotes false --write '**/*.rb'

Contributing

Check out our contributing guide. Bug reports and pull requests are welcome on GitHub at https://github.com/prettier/plugin-ruby.

Code

Thanks goes to these wonderful people (emoji key):


Kevin Deisz

💻 📖 ⚠️ 🐛

Alan Foster

💻 📖 ⚠️ 🐛

johnschoeman

⚠️

Aaron Jensen

📖

Cameron Bothner

💻

localhost.dev

🐛 💻

David Buchan-Swanson

🐛 💻

Jordan Pickwell

🐛

Josh Justice

🐛

xipgroc

🐛

Gregoire Lejeune

🐛

Pete Van Klaveren

🐛

meleyal

📖

Lipis

📖

Jan Piotrowski

📖

Andy Waite

📖

Jonathan Viney

🐛

acrewdson

🐛

Louis Orleans

🐛

Colton Voege

🐛

Stefan Kracht

🐛

jakeprime

🐛

Mario Mainz

🐛

CL Web Developers

🐛

github0013

🐛

James Costian

🐛

Joe Jackson

🐛

Max Albrecht

🐛

Matt

🐛 💻

Vesa Laakso

📖

jrdioko

🐛

gin0606

🐛 💻

Tobyn

💻

Ian Ker-Seymer

💻

Richard Huang

💻

Patrick Ellis

🐛

Peter De Berdt

🐛

Chris Hafley

🐛

Thomas Frütel

🐛

Alex Serban

💻

Stephanie

💻

Shay Davidson

🐛

Ryan Hunter

💻

Jan Klimo

💻

This project follows the all-contributors specification. Contributions of any kind welcome!

Financial

You can support prettier/plugin-ruby on OpenCollective. Your organization's logo will show up here with a link to your website.

License

The package is available as open source under the terms of the MIT License.

You can’t perform that action at this time.