TLDR, we forked prettier ruby plugin to provide a better ruby format tool, https://github.com/xinminlabs/plugin-ruby, plus rubocop-config-prettier and rubocop, it’s a total solution to format and lint ruby code.
is a mature one and is written in pure ruby.
- it’s fast.
- it has some configurations, e.g. single quote vs double quote, align and parentheses, include and exclude some files.
- it doesn’t format long line code yet. (it has been more than 2 years since the author tried to solve it)
- it doesn’t transform some heredoc and indents well
is a young project and is written in
- it’s super fast.
- you have to deal with
- is has no configuration, that means you need to accept all the rules, like only double quote and method call with args parentheses.
- it doesn’t format long line code well.
- it misses some comments.
- some other minor issues, like weird heredoc indent and empty line
prettier ruby plugin
as the name implied, it relies on
- it transforms long line code pretty well, thanks to
- it also has some configurations like quote style and max line length.
- you have to deal with
- it’s too aggressive, it takes some responsibilities which belong to the lint tool.
As you can see, no tool is perfect, we finally decided to choose prettier ruby plugin because it is the only one to format long line code well, but it’s still not good enough for production.
We sent some PRs to improve the prettier official ruby plugin, some are merged, but when we tried to take away some linter’s responsibilities, like do not transform string or symbol array and do not transform to ternary operator, the author doesn’t agree, so we have to maintain our own fork here. It has made the following changes so far.
- do not add line break for aref node (array)
- do not transform to ternary operator and vice versa
- do not transform multiline if to inline if and vice versa
- do not transform multiline while to inline while and vice versa
- do not transform to single line block and vice versa
- do not transform string_embexpr
- do not transform to string or symbol array
- do not transform regexp
- do not transform to to_proc
- do not wrap line inside arg_paren for some cases
- do not transform lambda call
You can get more from the README.
If you don’t want to set up them by yourself, you can try our service https://awesomecode.io