All Projects → prettier → Plugin Ruby

prettier / Plugin Ruby

Licence: mit
Prettier Ruby Plugin

Programming Languages

javascript
184084 projects - #8 most used programming language
ruby
36898 projects - #4 most used programming language

Labels

Projects that are alternatives of or similar to Plugin Ruby

Prettier Atom
An atom package for the prettier formatter.
Stars: ✭ 750 (-28.84%)
Mutual labels:  prettier
React Ssr Starter
All have been introduced React environment
Stars: ✭ 20 (-98.1%)
Mutual labels:  prettier
Budgeting
Budgeting - React + Redux + Webpack (tree shaking) Sample App
Stars: ✭ 971 (-7.87%)
Mutual labels:  prettier
Generator Node Module
A Yeoman module to author Node libraries with Prettier, Jest, Flow and Babel.
Stars: ✭ 16 (-98.48%)
Mutual labels:  prettier
Front End Stack
Starter kit for building single-page app using React, Redux, RxJS, Reselect, Material UI, Immer, Prettier and Webpack.
Stars: ✭ 11 (-98.96%)
Mutual labels:  prettier
Prettier Plugin Erb
Prettier ERB plugin
Stars: ✭ 28 (-97.34%)
Mutual labels:  prettier
React Ssr Setup
React Starter Project with Webpack 4, Babel 7, TypeScript, CSS Modules, Server Side Rendering, i18n and some more niceties
Stars: ✭ 678 (-35.67%)
Mutual labels:  prettier
React Boilerplate
⚛ The stable base upon which we build our React projects at Mirego.
Stars: ✭ 39 (-96.3%)
Mutual labels:  prettier
React Mobx React Router Boilerplate
A simple boilerplate based on create-react-app and add mobx, react-router, linter, prettier and so on. 一个简单的 react 脚手架依赖于 create-react-app 新增了 mobx react-router,linter,prettier 等。
Stars: ✭ 12 (-98.86%)
Mutual labels:  prettier
Prettylint
Run Prettier as a linter
Stars: ✭ 33 (-96.87%)
Mutual labels:  prettier
Vim Prettier
Prettier-Eslint-Cli for Vim
Stars: ✭ 17 (-98.39%)
Mutual labels:  prettier
Yarn Package Boilerplate
An Yarn package with babel, jest, flow, prettier and more
Stars: ✭ 10 (-99.05%)
Mutual labels:  prettier
Aurora
📦 A set of configs and rules for Typescript projects.
Stars: ✭ 30 (-97.15%)
Mutual labels:  prettier
Prettier Standard
Formats with Prettier and lints with ESLint+Standard! (✿◠‿◠)
Stars: ✭ 801 (-24%)
Mutual labels:  prettier
Be Pretty
💄 a small CLI utility for every lazy prettier maximalist out there
Stars: ✭ 38 (-96.39%)
Mutual labels:  prettier
Mevn Cli
Light speed setup for MEVN(Mongo Express Vue Node) Apps
Stars: ✭ 696 (-33.97%)
Mutual labels:  prettier
That React App You Want
That react app you always wanted: [email protected], [email protected], postCSS, purifycss, dll's and code splitting examples, bregh. Highly opinionated but you better like it.
Stars: ✭ 27 (-97.44%)
Mutual labels:  prettier
Gatsby Starter Strict
A Gatsby starter with strict linting and auto-formatting rules.
Stars: ✭ 43 (-95.92%)
Mutual labels:  prettier
Eslint Config Kit
A collection of useful eslint configs
Stars: ✭ 39 (-96.3%)
Mutual labels:  prettier
Express React Boilerplate
🚀🚀🚀 This is a tool that helps programmers create Express & React projects easily base on react-cool-starter.
Stars: ✭ 32 (-96.96%)
Mutual labels:  prettier
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.

This plugin currently supports formatting the following kinds of files:

  • All varieties of Ruby source files (e.g., *.rb, *.gemspec, Gemfile, etc.)
  • RBS type language files - requires having the rbs gem in your gem path
  • HAML template language files - requires having the haml gem in your gem path

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 '**/*'

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 '**/*'

Configuration

Below are the options (from src/plugin.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).
rubyArrayLiteral --ruby-array-literal true When possible, favor the use of string and symbol array literals.
rubyHashLabel --ruby-hash-label true When possible, uses the shortened hash key syntax, as opposed to hash rockets.
rubyModifier --ruby-modifier true When it fits on one line, allows while and until statements to use the modifier form.
rubyNetcatCommand --ruby-netcat-command The prefix of the command to execute to communicate between the node.js process and the Ruby process. (For example, "nc -U" or "telnet -u") Normally you should not set this option.
rubySingleQuote --ruby-single-quote true When double quotes are not necessary for interpolation, prefers the use of single quotes for string literals.
rubyToProc --ruby-to-proc false When possible, convert blocks to the more concise Symbol#to_proc syntax.
tabWidth --tab-width 2 Same as in Prettier (see prettier docs).
trailingComma --trailing-comma false Same as in Prettier (see prettier docs). "es5" is equivalent to true.

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

{
  "rubySingleQuote": false
}

Or, they can be passed to prettier as arguments:

prettier --ruby-single-quote false --write '**/*'

Usage with RuboCop

RuboCop and Prettier for Ruby serve different purposes, but there is overlap with some of RuboCop's functionality.

Prettier provides a RuboCop configuration file to disable the rules which clash. To enable, add the following config at the top of your project's .rubocop.yml:

Ruby gem

inherit_gem:
  prettier: rubocop.yml

npm package

inherit_from:
  - node_modules/@prettier/plugin-ruby/rubocop.yml

Contributing

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

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.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].