rbfmt 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 24552bd849087cb6c92ff52e13bcde680a30b82e
4
+ data.tar.gz: 38717b814e14a9e665a720803440fe4eefc762af
5
+ SHA512:
6
+ metadata.gz: 51db7bb53a9cab231db9f16522e569060f12329ae113161b172a2b275f4124d4c7e5fac0f9a309fd2071204271afc9ccf0e15c75e7fcf32cb5f3c8b3359d250d
7
+ data.tar.gz: 477143398f82a52aaeeff631ce2798bf6378b592b2fe23b7743943512b161d66f1b0f36ea92f3be37295082a86933d87f7325f19f339fcaab90b851639987492
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in rbfmt.gemspec
4
+ gemspec
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Jingwen Owen Ou
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,33 @@
1
+ # rbfmt
2
+
3
+ `rbfmt`, like [`gofmt`](http://golang.org/cmd/go/#hdr-Run_gofmt_on_package_sources) in the Go programming language, formats your Ruby code.
4
+ `rbfmt` is in beta. Use it at your own risk.
5
+
6
+ ## Installation
7
+
8
+ Add this line to your application's Gemfile:
9
+
10
+ gem 'rbfmt'
11
+
12
+ And then execute:
13
+
14
+ $ bundle
15
+
16
+ Or install it yourself as:
17
+
18
+ $ gem install rbfmt
19
+
20
+ ## Usage
21
+
22
+ ```ruby
23
+ $ rbfmt # format all folders recursively
24
+ $ rbfmt folder # format "folder" recursively
25
+ ```
26
+
27
+ ## Contributing
28
+
29
+ 1. Fork it ( http://github.com/<my-github-username>/rbfmt/fork )
30
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
31
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
32
+ 4. Push to the branch (`git push origin my-new-feature`)
33
+ 5. Create new Pull Request
@@ -0,0 +1,7 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new
5
+
6
+ desc "Run specs"
7
+ task :default => :spec
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ $:.unshift File.expand_path("../../lib", __FILE__)
4
+
5
+ require "rbfmt/cli"
6
+
7
+ Rbfmt::CLI.start
@@ -0,0 +1,4 @@
1
+ require "rbfmt/version"
2
+
3
+ module Rbfmt
4
+ end
@@ -0,0 +1,32 @@
1
+ require "rbfmt/formatter"
2
+
3
+ module Rbfmt
4
+ class CLI
5
+ attr_reader :args
6
+
7
+ def initialize(args)
8
+ @args = args
9
+ end
10
+
11
+ def start
12
+ dir = if args.empty?
13
+ File.join("**", "*.rb")
14
+ else
15
+ File.join(args.first, "**", "*.rb")
16
+ end
17
+
18
+ Dir[dir].each do |file|
19
+ source = File.read(file)
20
+ formatted_source = Rbfmt::Formatter.new(source).format
21
+ unless source == formatted_source
22
+ File.write(file, formatted_source)
23
+ puts file
24
+ end
25
+ end
26
+ end
27
+
28
+ def self.start
29
+ new(ARGV).start
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,18 @@
1
+ require "ruby2ruby"
2
+ require "ruby_parser"
3
+
4
+ module Rbfmt
5
+ class Formatter
6
+ def initialize(ruby)
7
+ @ruby = ruby
8
+ end
9
+
10
+ def format
11
+ parser = RubyParser.new
12
+ ruby2ruby = Ruby2Ruby.new
13
+ sexp = parser.process(@ruby)
14
+
15
+ ruby2ruby.process(sexp)
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,3 @@
1
+ module Rbfmt
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,26 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'rbfmt/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "rbfmt"
8
+ spec.version = Rbfmt::VERSION
9
+ spec.authors = ["Jingwen Owen Ou"]
10
+ spec.email = ["jingweno@gmail.com"]
11
+ spec.summary = %q{Format your Ruby code.}
12
+ spec.homepage = "https://github.com/jingweno/rbfmt"
13
+ spec.license = "MIT"
14
+
15
+ spec.files = `git ls-files`.split($/)
16
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
17
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
18
+ spec.require_paths = ["lib"]
19
+
20
+ spec.add_runtime_dependency "ruby_parser"
21
+ spec.add_runtime_dependency "ruby2ruby"
22
+
23
+ spec.add_development_dependency "bundler", "~> 1.5"
24
+ spec.add_development_dependency "rake"
25
+ spec.add_development_dependency "rspec"
26
+ end
@@ -0,0 +1 @@
1
+ def hello(world) "Hello, #{world}!"; end
@@ -0,0 +1,3 @@
1
+ def hello(world)
2
+ "Hello, #{world}!"
3
+ end
@@ -0,0 +1,5 @@
1
+ require "ripper"
2
+
3
+ class Foo
4
+
5
+ end
@@ -0,0 +1,5 @@
1
+ require "ripper"
2
+
3
+ class Foo
4
+
5
+ end
@@ -0,0 +1,18 @@
1
+ require "spec_helper"
2
+ require "rbfmt/formatter"
3
+
4
+ describe Rbfmt::Formatter do
5
+ fixtures = Dir.glob File.join(File.expand_path(File.dirname(__FILE__)), "fixtures", "**", "*.rb")
6
+ formatted_fixtures = fixtures.select { |f| f[/.+_formatted.rb/] }
7
+ source_fixtures = fixtures - formatted_fixtures
8
+
9
+ source_fixtures.each do |s|
10
+ it "formats source in #{s}" do
11
+ filename = File.basename(s, ".rb")
12
+ formatted = formatted_fixtures.detect { |f| f[/#{filename}_formatted.rb/] }
13
+ fail "No formatted fixture for #{s}" unless formatted
14
+ formatter = described_class.new(File.read(s))
15
+ formatter.format.should == File.read(formatted).strip
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,5 @@
1
+ $:.unshift File.expand_path("..", __FILE__)
2
+ $:.unshift File.expand_path("../../lib", __FILE__)
3
+
4
+ require "rspec"
5
+ require "rbfmt"
metadata ADDED
@@ -0,0 +1,138 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rbfmt
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Jingwen Owen Ou
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-03-05 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: ruby_parser
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: ruby2ruby
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: bundler
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '1.5'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '1.5'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rspec
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ description:
84
+ email:
85
+ - jingweno@gmail.com
86
+ executables:
87
+ - rbfmt
88
+ extensions: []
89
+ extra_rdoc_files: []
90
+ files:
91
+ - ".gitignore"
92
+ - Gemfile
93
+ - LICENSE.txt
94
+ - README.md
95
+ - Rakefile
96
+ - bin/rbfmt
97
+ - lib/rbfmt.rb
98
+ - lib/rbfmt/cli.rb
99
+ - lib/rbfmt/formatter.rb
100
+ - lib/rbfmt/version.rb
101
+ - rbfmt.gemspec
102
+ - spec/fixtures/one_liner.rb
103
+ - spec/fixtures/one_liner_formatted.rb
104
+ - spec/fixtures/require.rb
105
+ - spec/fixtures/require_formatted.rb
106
+ - spec/formatter_spec.rb
107
+ - spec/spec_helper.rb
108
+ homepage: https://github.com/jingweno/rbfmt
109
+ licenses:
110
+ - MIT
111
+ metadata: {}
112
+ post_install_message:
113
+ rdoc_options: []
114
+ require_paths:
115
+ - lib
116
+ required_ruby_version: !ruby/object:Gem::Requirement
117
+ requirements:
118
+ - - ">="
119
+ - !ruby/object:Gem::Version
120
+ version: '0'
121
+ required_rubygems_version: !ruby/object:Gem::Requirement
122
+ requirements:
123
+ - - ">="
124
+ - !ruby/object:Gem::Version
125
+ version: '0'
126
+ requirements: []
127
+ rubyforge_project:
128
+ rubygems_version: 2.2.0
129
+ signing_key:
130
+ specification_version: 4
131
+ summary: Format your Ruby code.
132
+ test_files:
133
+ - spec/fixtures/one_liner.rb
134
+ - spec/fixtures/one_liner_formatted.rb
135
+ - spec/fixtures/require.rb
136
+ - spec/fixtures/require_formatted.rb
137
+ - spec/formatter_spec.rb
138
+ - spec/spec_helper.rb