20

Using Rubyfmt with Atom

 4 years ago
source link: https://schwad.github.io/ruby/rails/tutorials/2019/12/02/using-rubyfmt-on-atom.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

beuYf2Z.png!web

Rubyfmt, the exciting project from @penelope_zone continues to grow by the day. After being a fan of this work for quite a while, I set out to hack together a way to get it running slick on Atom. I’m writing today to share those few steps so that you, too, can enjoy the magic of Rubyfmt on Atom!

What is Rubyfmt?

I reckon 90% of people reading this article will already be intimately familiar with this project. If not, here’s the quick hits.

Rubyfmt is inspired by gofmt . It formats existing Ruby code, and you can set this up as you like (today we will do it after save). It is mature enough to be able to run against all of rspec-core without breaking. You can read more details on the Github README.

I first heard about this when Penelope discussed it with @sgrif on the Yak Shave podcast. The subject came up in multiple episodes, and if I’m honest the technical details of creating this awesome tool likely went over my head. I still recommend taking a listen!

rQJBBfE.png!web

Okay, let’s get this running on Atom

1. Follow initial README instructions

At time of writing these are:

git init
git clone https://github.com/penelopezone/rubyfmt.git
make
make install

2. Set up Atom ‘after-save’ listener.

  • Install Atom package save-commands
  • add the following to your save-commands.json in your directory:
  • "**/*.rb": "ruby --disable=gems path/to/bin/rubyfmt.rb -i {absPath}{filename}"

Full example:

# save-commands.json
{
	"commands": [
		"**/*.rb : ruby --disable=gems /path/to/bin/rubyfmt.rb -i {absPath}{filename}"
  ]
}

And voila! You should be in business. As a test you can add something unRuby-ish to a Ruby file (or just excess whitespace), save, and it should autoformat!

3. Gotchas:

ruby --disable=gems ~/bin/rubyfmt.rb -i ${file}
realpath rubyfmt.rb

4. Moving forward:

  • I will try to keep this post updated, but following @penelope_zone on Twitter and checking out the README are the current best sources of truth
  • It would be nice to wrap this up automatically in an atom package in future, so these steps aren’t necessary. I’ve started looking into this but it may be more straightforward with someone more familiar with writing Atom package plugin code
  • If you have any “this doesn’t format correctly” feedback, hold fire for the moment as there’s a lot of work happening on this right now

Thanks, Penelope! :heart:


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK