Skip to content

tapn2it/plugin-ruby

Repository files navigation

Prettier Ruby

Prettier for Ruby

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

@prettier/plugin-ruby is a prettier plugin for the Ruby programming language (versions 2.5 and above). 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.

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:

Name Default Description
printWidth 80 Same as in Prettier (see prettier docs).
requirePragma false Same as in Prettier (see prettier docs).
tabWidth 2 Same as in Prettier (see prettier docs).
addTrailingCommas false Adds a trailing comma to array literals, hash literals, and method calls.
inlineConditionals true When it fits on one line, allows if and unless statements to use the modifier form.
inlineLoops true When it fits on one line, allows while and until statements to use the modifier form.
preferHashLabels true When possible, uses the shortened hash key syntax, as opposed to hash rockets.
preferSingleQuotes 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.

License

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

Contributors

Thanks goes to these wonderful people (emoji key):

Kevin Deisz
Kevin Deisz

πŸ’» πŸ“– ⚠️ πŸ›
Alan Foster
Alan Foster

πŸ’» πŸ“– ⚠️ πŸ›
johnschoeman
johnschoeman

⚠️
Aaron Jensen
Aaron Jensen

πŸ“–
Cameron Bothner
Cameron Bothner

πŸ’»
localhost.dev
localhost.dev

πŸ› πŸ’»
David Buchan-Swanson
David Buchan-Swanson

πŸ› πŸ’»
Jordan Pickwell
Jordan Pickwell

πŸ›
Josh Justice
Josh Justice

πŸ›
xipgroc
xipgroc

πŸ›
Gregoire Lejeune
Gregoire Lejeune

πŸ›
Pete Van Klaveren
Pete Van Klaveren

πŸ›
meleyal
meleyal

πŸ“–
Lipis
Lipis

πŸ“–
Jan Piotrowski
Jan Piotrowski

πŸ“–
Andy Waite
Andy Waite

πŸ“–
Jonathan Viney
Jonathan Viney

πŸ›
acrewdson
acrewdson

πŸ›
Louis Orleans
Louis Orleans

πŸ›
Colton Voege
Colton Voege

πŸ›
Stefan Kracht
Stefan Kracht

πŸ›
jakeprime
jakeprime

πŸ›
Mario Mainz
Mario Mainz

πŸ›
CL Web Developers
CL Web Developers

πŸ›

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

About

Prettier Ruby Plugin

Resources

License

Code of conduct

Stars

Watchers

Forks

Packages

No packages published

Languages

  • JavaScript 69.4%
  • Ruby 30.4%
  • Shell 0.2%