Skip to content

markatlish/plugin-ruby

 
 

Repository files navigation

awesomecode-plugin-ruby

This is a fork of prettier plugin-ruby, which is used in Awesome Code

How to use

npm install prettier awesomecode-plugin-ruby
npx prettier *.rb

What changed comparing to the official plugin ruby?

It contains the following changes

do not add line break for aref node (array)

e.g.

hello.foo.bar.hello.foo.bar.hello.foo.bar.hello.foo.bar.hello.foo.bar.hello['test']

won't be transformed to

hello.foo.bar.hello.foo.bar.hello.foo.bar.hello.foo.bar.hello.foo.bar.hello[
  'test'
]

do not transform to ternary operator and vice versa

e.g.

if File.directory? entry
  Dir[File.join(entry, '**', "*.rb")]
else
  entry
end

won't be transformed to

File.directory? entry ? Dir[File.join(entry, '**', "*.rb")] : entry

do not transform multiline if to inline if and vice versa

e.g.

if result
  'foo'
else
  'bar'
end

won't be transformed to

result ? 'foo' : 'bar'

do not transform multiline while to inline while and vice versa

e.g.

while true
  break :value
end

won't be transformed to

break :value while true

do not transform to single line block and vice versa

e.g.

included do
  has_many :build_items, dependent: :destroy
end

won't be transformed to

included { has_many :build_items, dependent: :destroy }

do not transform string_embexpr

"node ./node_modules/prettier/bin-prettier.js --plugin ./node_modules/awesomecode-plugin-ruby --config #{FormatTool::DOCKER_FORMATRC_YAML} --ignore-path #{FormatTool::DOCKER_FORMAT_IGNORE} --write #{FormatTool::DOCKER_INPUT_PATH}/**/*.{rb,rake}"

won't be transformed to

"node ./node_modules/prettier/bin-prettier.js --plugin
./node_modules/awesomecode-plugin-ruby --config #{
  FormatTool::DOCKER_FORMATRC_YAML
} --ignore-path #{FormatTool::DOCKER_FORMAT_IGNORE} --write #{
  FormatTool::DOCKER_INPUT_PATH
}/**/*.{rb,rake}"

do not transform to string or symbol array

['foo']
[:bar]

won't be transformed to

%w[foo]
%i[bar]

do not transform regexp

/abc/

won't be transformed to

%r{abc}

do not transform to to_proc

array.each { |element| element.to_s }

won't be transformed to

array.each(&:to_s)

do not wrap line inside arg_paren for some cases

thereisamethodcall(arg1, arg2).thereisanothermethodcall(arg1, arg2).asimpleone(arg)

won't be transformed to

thereisamethodcall(arg1, arg2).thereisanothermethodcall(arg1, arg2).asimpleone(
  arg
)

do not transform lambda call

json.(:id, :name)

won't be transformed to

json.call(:id, :name)

About

Prettier Ruby Plugin used in awesomecode.io

Resources

License

Code of conduct

Stars

Watchers

Forks

Packages

No packages published

Languages

  • JavaScript 67.7%
  • Ruby 32.1%
  • Shell 0.2%