Sha256: 0636e01752612ee9bdf1fdf068ad1844d020640046ecfeb991b763773bbe0f3f

Contents?: true

Size: 982 Bytes

Versions: 74

Compression:

Stored size: 982 Bytes

Contents

#!/usr/bin/env ruby -i
# encoding: utf-8

# Usage:
# find . | egrep '\.rb$' | egrep -v cleanify.rb | xargs ./bin/cleanify.rb

# \n at the end of the file
# def foo a, b, &block
# no trailing whitespace
# encoding declaration

ENCODING = "utf-8"

while line = ARGF.gets
  # whitespace
  # line.chomp!
  line.gsub!(/\t/, "  ")
  line.rstrip!

  # encoding
  if line.length == (ARGF.pos - 1) && ! line.match(/^#.*coding/)
    puts "# encoding: #{ENCODING}\n\n"
  end

  # def
  regexp = /^(\s*def \w[\w\d]*)\s+(.+)$/
  if line.match(regexp)
    line.gsub!(regexp, '\1(\2)')
  end

  # foo{} => foo {}
  line.gsub!(/([^%][^#( ])(\{)/, '\1 \2')

  # a=foo => a = foo
  line.gsub!(/([^ ])(\+=)/, '\1 \2')
  line.gsub!(/(\+=)([^ ])/, '\1 \2')
  line.gsub!(/([^ :])(<<)/, '\1 \2')
  line.gsub!(/(<<)([^ ])/, '\1 \2')

  # foo=>bar
  line.gsub!(/([^\s])=>/, '\1 =>')
  line.gsub!(/=>([^\s])/, '=> \1')

  line.gsub!(/\{\|/, '{ |')

  line.gsub!(/,\s*/, ', ')
  line.rstrip!

  puts line
end

Version data entries

74 entries across 74 versions & 1 rubygems

Version Path
amqp-0.9.2 bin/cleanify.rb
amqp-0.9.1 bin/cleanify.rb
amqp-0.9.0 bin/cleanify.rb
amqp-0.9.0.pre3 bin/cleanify.rb
amqp-0.9.0.pre2 bin/cleanify.rb
amqp-0.9.0.pre1 bin/cleanify.rb
amqp-0.8.4 bin/cleanify.rb
amqp-0.8.3 bin/cleanify.rb
amqp-0.8.2 bin/cleanify.rb
amqp-0.8.1 bin/cleanify.rb
amqp-0.8.0 bin/cleanify.rb
amqp-0.7.5 bin/cleanify.rb
amqp-0.8.0.rc15 bin/cleanify.rb
amqp-0.7.4 bin/cleanify.rb
amqp-0.8.0.rc14 bin/cleanify.rb
amqp-0.7.3 bin/cleanify.rb
amqp-0.7.2 bin/cleanify.rb
amqp-0.8.0.rc13 bin/cleanify.rb
amqp-0.8.0.rc12 bin/cleanify.rb
amqp-0.8.0.rc11 bin/cleanify.rb