Skip to content

progrhyme/ruby-align

Repository files navigation

ruby-align Build Status

A code formatter for Ruby to make alignment.

Usage

ruby-align your_program.rb
ruby-align --[f]ile=your_program.rb

Or it can receive input from STDIN and output formatted code.

How this works?

This script provides functionality of aligning code elements such as variable assignments or hash declarations.

Here's an example:

## before
a = 1
dddd ||= (1..3)
bb -= 20
e = { foo: 1, bar: 'Bar' }

stash = {
  foo: 123,
  'bar' => 'Bar',
  "bazz" => %w[ x y z ]
}

## after
a      = 1
dddd ||= (1..3)
bb    -= 20
e      = { foo: 1, bar: 'Bar' }

stash = {
  foo:      123,
  'bar'  => 'Bar',
  "bazz" => %w[ x y z ]
}

If you are curious, you can see formatting examples under spec/ directory. In spec/subjects/ directory, there are some unformatted code snippets. And formatted results of them are in spec/expects/ directory.

Call ruby-align in Text Editors

Because I am a vimmer, here is only example of .vimrc.

" == ruby-align ==
" set your favorite leader key
let mapleader = ","
noremap <Leader>ra <Esc>:%! /path/to/ruby-align<Return>
noremap <Leader>rav <Esc>:'<,'>! /path/to/ruby-align<Return>

If you add this into your .vimrc, you can call ruby-align to whole your buffer by typing ,ra. Or you can partially apply it by ,rav for selected area in visual mode.

Settings for other editors are welcome.

CAUTION

This program might have bugs.
Please take a backup before you apply this to your code.

For known issues, see the issue list in this project.

LICENSE

The MIT License (MIT)

Copyright (c) 2016 IKEDA Kiyoshi

About

Code Alignment Tool for Ruby

Resources

License

Stars

Watchers

Forks

Packages

No packages published