Michael Durrant
Michael Durrant

Reputation: 96454

Correct Ruby indentation for a bunch of files in one go

I have a lot of ruby files with incorrect indentation.

How can I fix it automatically (with help of some tool) other than manually?

Example:

feature 'HAPPY/3_step_minimal_foundation_no_prefill_HAPPY' do
    visit('http://staging.everquote/url_reset') # should be 2 spaces not 4
    visit('http://staging.everquote/url_3_step_minimal_foundation')
    with_ajax_wait do
      expect(css_zip_code).to be_visible # should be 4 spaces not 6
  end

Upvotes: 1

Views: 1279

Answers (2)

Matt Prelude
Matt Prelude

Reputation: 912

This ruby beautifier contains logic to re-indent your code.

You could either run the script as-is or extract those parts.

Upvotes: 1

Michael Durrant
Michael Durrant

Reputation: 96454

Turns out rubocop, which I was using already to check the format and which is currently maintained (as of September 2015) has a -a option to actually fix the files. Sweet!

https://github.com/bbatsov/rubocop

Upvotes: 0

Related Questions