rubyfmt 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +18 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +43 -0
- data/Rakefile +5 -0
- data/TODO.md +4 -0
- data/bin/rubyfmt +5 -0
- data/lib/rubyfmt.rb +38 -0
- data/lib/rubyfmt/version.rb +3 -0
- data/rubyfmt.gemspec +25 -0
- data/test/bin_rubyfmt_test.rb +7 -0
- data/test/fixtures/person.actual.rb +13 -0
- data/test/fixtures/person.expected.rb +11 -0
- data/test/rubyfmt_test.rb +60 -0
- metadata +105 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 77e183ac552728aef1f8a7da113554c2ac981850
|
4
|
+
data.tar.gz: f0c26e6d6871a9442e2f69460c4aa05ab5f78a3d
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: d06eb58469b7dd207b0ed3bf8c872cac1c1fd9b6e1de85f5bdfe646e14c8c33b465c6f848038e3970523d17be0409fe8d168792eb763236951f68b0bfd5258f9
|
7
|
+
data.tar.gz: f1c5d725afe18c3b9e04aad0011bb7c08f02f1913eb656df397d6b57592f9167a475a7acfe149e2f470044c1f068c38573c7460cf97e63732830d441aae72bf6
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2014 Wojtek Mach
|
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.
|
data/README.md
ADDED
@@ -0,0 +1,43 @@
|
|
1
|
+
# Rubyfmt
|
2
|
+
|
3
|
+
Ruby port of gofmt.
|
4
|
+
|
5
|
+
## Usage
|
6
|
+
|
7
|
+
```bash
|
8
|
+
$ echo 'def hello(who="world");puts "Hello #{who}";end' | ./bin/rubyfmt
|
9
|
+
```
|
10
|
+
|
11
|
+
Outputs:
|
12
|
+
|
13
|
+
```ruby
|
14
|
+
def hello(who = "world")
|
15
|
+
puts "Hello #{who}"
|
16
|
+
end
|
17
|
+
```
|
18
|
+
|
19
|
+
## Installation
|
20
|
+
|
21
|
+
Add this line to your application's Gemfile:
|
22
|
+
|
23
|
+
gem 'rubyfmt'
|
24
|
+
|
25
|
+
And then execute:
|
26
|
+
|
27
|
+
$ bundle
|
28
|
+
|
29
|
+
Or install it yourself as:
|
30
|
+
|
31
|
+
$ gem install rubyfmt
|
32
|
+
|
33
|
+
## Credits
|
34
|
+
|
35
|
+
- seattle.rb - for ruby_parser & ruby2ruby which do _all_ of the heavy-lifting.
|
36
|
+
|
37
|
+
## Contributing
|
38
|
+
|
39
|
+
1. Fork it ( http://github.com/<my-github-username>/rubyfmt/fork )
|
40
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
41
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
42
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
43
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
data/TODO.md
ADDED
data/bin/rubyfmt
ADDED
data/lib/rubyfmt.rb
ADDED
@@ -0,0 +1,38 @@
|
|
1
|
+
require 'rubyfmt/version'
|
2
|
+
require 'ruby2ruby'
|
3
|
+
require 'ruby_parser'
|
4
|
+
|
5
|
+
module Rubyfmt
|
6
|
+
def self.format(string)
|
7
|
+
Processor.new.process(RubyParser.new.parse(string)).strip
|
8
|
+
end
|
9
|
+
|
10
|
+
class Processor < Ruby2Ruby
|
11
|
+
def process_class(exp)
|
12
|
+
super + "\n"
|
13
|
+
end
|
14
|
+
|
15
|
+
def process_if(exp)
|
16
|
+
super.sub(/\ then$/, '')
|
17
|
+
end
|
18
|
+
|
19
|
+
def process_while(exp)
|
20
|
+
super.sub(/\ do$/, '')
|
21
|
+
end
|
22
|
+
|
23
|
+
def process_call(exp)
|
24
|
+
methods_without_parens = [:puts]
|
25
|
+
method = exp[1]
|
26
|
+
|
27
|
+
if methods_without_parens.include?(method)
|
28
|
+
super.sub(/^(#{method})\((.*)\)$/, '\1 \2')
|
29
|
+
else
|
30
|
+
super
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
def indent(s)
|
35
|
+
super.split(/\n/).map {|line| line.strip.size == 0 ? '' : line }.join("\n")
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
data/rubyfmt.gemspec
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'rubyfmt/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "rubyfmt"
|
8
|
+
spec.version = Rubyfmt::VERSION
|
9
|
+
spec.authors = ["Wojtek Mach"]
|
10
|
+
spec.email = ["wojtek@wojtekmach.pl"]
|
11
|
+
spec.summary = "Ruby port of gofmt"
|
12
|
+
spec.description = ""
|
13
|
+
spec.homepage = ""
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files`.split($/)
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_dependency "ruby2ruby", "~> 2.0"
|
22
|
+
|
23
|
+
spec.add_development_dependency "bundler", "~> 1.5"
|
24
|
+
spec.add_development_dependency "rake"
|
25
|
+
end
|
@@ -0,0 +1,60 @@
|
|
1
|
+
require 'minitest/autorun'
|
2
|
+
require 'rubyfmt'
|
3
|
+
|
4
|
+
describe "Rubyfmt" do
|
5
|
+
it do
|
6
|
+
assert_fixture 'person'
|
7
|
+
end
|
8
|
+
|
9
|
+
it "adds blank line between class definitions" do
|
10
|
+
assert_code %Q{
|
11
|
+
class Foo
|
12
|
+
end
|
13
|
+
|
14
|
+
class Bar
|
15
|
+
end
|
16
|
+
}, %Q{
|
17
|
+
class Foo; end
|
18
|
+
class Bar; end
|
19
|
+
}
|
20
|
+
end
|
21
|
+
|
22
|
+
it "adds blank line between method definitions" do
|
23
|
+
assert_code %Q{
|
24
|
+
class Foo
|
25
|
+
def foo
|
26
|
+
42
|
27
|
+
end
|
28
|
+
|
29
|
+
def bar
|
30
|
+
42
|
31
|
+
end
|
32
|
+
end
|
33
|
+
}, %Q{
|
34
|
+
class Foo
|
35
|
+
def foo; 42 end
|
36
|
+
def bar; 42 end
|
37
|
+
end
|
38
|
+
}
|
39
|
+
end
|
40
|
+
|
41
|
+
it "does not add parens for puts" do
|
42
|
+
assert_code 'puts 42', 'puts 42'
|
43
|
+
end
|
44
|
+
|
45
|
+
private
|
46
|
+
|
47
|
+
def code(str)
|
48
|
+
str.gsub(/^\ {6}/, '').strip
|
49
|
+
end
|
50
|
+
|
51
|
+
def assert_code(expected, actual)
|
52
|
+
assert_equal code(expected), Rubyfmt.format(code(actual))
|
53
|
+
end
|
54
|
+
|
55
|
+
def assert_fixture(name)
|
56
|
+
expected = File.read("./test/fixtures/#{name}.expected.rb").strip
|
57
|
+
actual = File.read("./test/fixtures/#{name}.actual.rb").strip
|
58
|
+
assert_code expected, actual
|
59
|
+
end
|
60
|
+
end
|
metadata
ADDED
@@ -0,0 +1,105 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: rubyfmt
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Wojtek Mach
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-04-07 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: ruby2ruby
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '2.0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '2.0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: bundler
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '1.5'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '1.5'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rake
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
description: ''
|
56
|
+
email:
|
57
|
+
- wojtek@wojtekmach.pl
|
58
|
+
executables:
|
59
|
+
- rubyfmt
|
60
|
+
extensions: []
|
61
|
+
extra_rdoc_files: []
|
62
|
+
files:
|
63
|
+
- ".gitignore"
|
64
|
+
- Gemfile
|
65
|
+
- LICENSE.txt
|
66
|
+
- README.md
|
67
|
+
- Rakefile
|
68
|
+
- TODO.md
|
69
|
+
- bin/rubyfmt
|
70
|
+
- lib/rubyfmt.rb
|
71
|
+
- lib/rubyfmt/version.rb
|
72
|
+
- rubyfmt.gemspec
|
73
|
+
- test/bin_rubyfmt_test.rb
|
74
|
+
- test/fixtures/person.actual.rb
|
75
|
+
- test/fixtures/person.expected.rb
|
76
|
+
- test/rubyfmt_test.rb
|
77
|
+
homepage: ''
|
78
|
+
licenses:
|
79
|
+
- MIT
|
80
|
+
metadata: {}
|
81
|
+
post_install_message:
|
82
|
+
rdoc_options: []
|
83
|
+
require_paths:
|
84
|
+
- lib
|
85
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
91
|
+
requirements:
|
92
|
+
- - ">="
|
93
|
+
- !ruby/object:Gem::Version
|
94
|
+
version: '0'
|
95
|
+
requirements: []
|
96
|
+
rubyforge_project:
|
97
|
+
rubygems_version: 2.2.2
|
98
|
+
signing_key:
|
99
|
+
specification_version: 4
|
100
|
+
summary: Ruby port of gofmt
|
101
|
+
test_files:
|
102
|
+
- test/bin_rubyfmt_test.rb
|
103
|
+
- test/fixtures/person.actual.rb
|
104
|
+
- test/fixtures/person.expected.rb
|
105
|
+
- test/rubyfmt_test.rb
|