ruby-beautify 0.95.0 → 0.96.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 795337833ac1e0a311d095cd06e138e090e813e0
4
- data.tar.gz: a24f9b486bca041b900d19d5ca3d72d2857d5d16
3
+ metadata.gz: 13168e4681dafb98dab93fbde6ed6df28bf935fe
4
+ data.tar.gz: 905e6c45a87f5a0c64d6d959fb01095e35196386
5
5
  SHA512:
6
- metadata.gz: 2cc470ec899d8073ba989c921f1025f72a8a2728efc644386441c44df1231615e2c139940d6614d67d5d60dfb71472ab45cc92c219915d265c2d10d003c163c2
7
- data.tar.gz: 1a1821d12d0c711842bc2838e6d1096ebd3a5cd62cff37ec85ca225d123533a7ed707fc7206b0a3ae49a57b85f27fbee04945b7b10ba718bd2c7740f3124f794
6
+ metadata.gz: 5d8c76c28509bf4da9c6e3078039a707a3f4a5c9acba859ac877bb604877dbaeb73292fed65dfc83f89e0d51168570d20d65458e8c03f5a66e91730d2020a91e
7
+ data.tar.gz: 01ff2b88dcd164966f9d3778653e009a8a08cdc51f6f51612efbdea6be7bf763c0171f1c70212d9a8d97620d7c06e25e79e3096e5e7e4fdda92485525f12920a
data/CONTRIB.md ADDED
@@ -0,0 +1,12 @@
1
+ How to contribute to this project.
2
+
3
+ ## Thin rules (to be made into sections)
4
+
5
+ * Work off the dev branch, not master.
6
+ * Pull requests should be named something related to PR, `hotfix-XXX` or `feature-YYY`.
7
+ * Do not edit the `version.rb` or the `gemspec`.
8
+ * All pull requests have to pass tests on `travis-ci` before I'll consider merging them.
9
+
10
+ ## Formatting and style
11
+
12
+ Run all your code through `ruby-beautify` with default settings before committing.
data/Guardfile CHANGED
@@ -4,6 +4,7 @@ guard :bundler do
4
4
  end
5
5
 
6
6
  guard :rspec, cmd: 'rspec' do
7
+ watch('bin/ruby-beautify') { "spec" }
7
8
  watch(%r{^spec/.+_spec\.rb$})
8
9
  watch(%r{^lib/(.+)\.rb$}) { |m| "spec/lib/#{m[1]}_spec.rb" }
9
10
  watch('spec/spec_helper.rb') { "spec" }
data/WHATSNEW.md CHANGED
@@ -1,3 +1,8 @@
1
+ ## 0.96.0
2
+ * Rewrote the syntax checker so that it pipes a string through stdout, doesn't need a temp file.
3
+ * Moved everything into the module to clean up the bin.
4
+ * @Sir-Irk fixed a bug where else and end end up on the same line.
5
+
1
6
  ## 0.95.0
2
7
  * Merged a quick fix from @pkuykendall to catch block assignments with ||=
3
8
  * Added a required version to the gemspec.
data/bin/rbeautify CHANGED
@@ -3,185 +3,39 @@ require 'ruby-beautify'
3
3
  require 'ripper'
4
4
  require 'optparse'
5
5
 
6
+ include RubyBeautify
7
+
6
8
  Options = OptionParser.new do |opts|
7
- opts.on("-V", "--version", "Print version") { |version| puts RBeautify::VERSION;exit 0}
8
- opts.on("-c", "--indent_count [COUNT]", Integer, "Count of characters to use for indenting. (default: 1)") { |count| @indent_count = count}
9
- opts.on("-t", "--tabs", "Use tabs for the indent character (default)") { @indent_token = "\t" }
10
- opts.on("-s", "--spaces", "Use spaces for the indent character") { @indent_token = " " }
11
- opts.banner = "Usage: print ruby into a pretty format, or break trying."
9
+ opts.on("-V", "--version", "Print version") { |version| puts RBeautify::VERSION;exit 0}
10
+ opts.on("-c", "--indent_count [COUNT]", Integer, "Count of characters to use for indenting. (default: 1)") { |count| @indent_count = count}
11
+ opts.on("-t", "--tabs", "Use tabs for the indent character (default)") { @indent_token = "\t" }
12
+ opts.on("-s", "--spaces", "Use spaces for the indent character") { @indent_token = " " }
13
+ opts.banner = "Usage: print ruby into a pretty format, or break trying."
12
14
  end
13
15
  Options.parse!
14
16
 
15
- @open_block_start = ["module", "class", "begin", "def", 'if', 'while', 'unless', 'case']
16
- @both_block = ["else", "elsif", 'rescue', 'when']
17
- @open_block_do = ['do', '{']
18
- @close_block = ['end', '}']
19
-
20
- @open_brackets = [:on_lparen, :on_lbracket, :on_lbrace, :on_embexpr_beg]
21
- @close_brackets = [:on_rparen, :on_rbracket, :on_rbrace, :on_embexpr_end]
22
- @new_lines = [:on_nl, :on_ignored_nl, :on_comment, :on_embdoc_end]
23
-
24
17
  @indent_token = "\t" unless @indent_token
25
18
  @indent_count = 1 unless @indent_count
26
19
 
27
- def puts_indented_line(level, string)
28
- if string =~ /^\n$/
29
- puts
30
- else
31
- indent = (@indent_token * @indent_count) * level
32
- puts "#{indent}#{string.lstrip}"
33
- end
34
- end
35
-
36
- def pretty(content)
37
- begin
38
- lex = Ripper.lex(content)
39
- rescue
40
- exit 255
41
- end
42
-
43
- indent_level = 0
44
- line_lex = []
45
-
46
- # walk through line tokens
47
- lex.each do |token|
48
- line_lex << token
49
- if @new_lines.include? token[1] # if type of this token is a new line
50
-
51
- # did we just close something? if so, lets bring it down a level.
52
- if closing_block?(line_lex) || closing_assignment?(line_lex)
53
- indent_level -= 1 if indent_level > 0
54
- end
55
-
56
- # print our line, in place.
57
- line_string = line_lex.map {|l| l.last}.join
58
- puts_indented_line(indent_level, line_string)
59
-
60
- # oh, we opened something did we? lets indent for the next run.
61
- if opening_block?(line_lex) || opening_assignment?(line_lex)
62
- indent_level += 1
63
- end
64
-
65
- line_lex.clear
66
- end
67
- end
68
-
69
- return nil
70
- end
71
-
72
- # how many times do we open in this line?
73
- def opening_block_count(line_lex)
74
- line_lex.select {|l| l[1] == :on_kw && @open_block_do.include?(l[2])}.count
75
- end
76
-
77
- # how many times do we close?
78
- def closing_block_count(line_lex)
79
- line_lex.select {|l| l[1] == :on_kw && @close_block.include?(l[2])}.count
80
- end
81
-
82
- # is the first word a key word?
83
- def starts_block?(line_lex)
84
- return true if contains_block_assignment? line_lex
85
- line_lex.each do |x|
86
- # search for a first non-space token
87
- if not x[1] == :on_sp
88
- return x[1] == :on_kw && @open_block_start.include?(x[2])
89
- end
90
- end
91
- end
92
-
93
- # is the first word one of our 'both' keywords?
94
- def both_block?(line_lex)
95
- line_lex.each do |x|
96
- # search for a first non-space token
97
- if not x[1] == :on_sp
98
- return x[1] == :on_kw && @both_block.include?(x[2])
99
- end
100
- end
101
- end
102
-
103
- # kinda complex, we count open/close to determine if we ultimately have a
104
- # hanging line. Always true if it's a both_block.
105
- def opening_block?(line_lex)
106
- return true if both_block? line_lex
107
- opens = starts_block?(line_lex) ? 1 : 0
108
- opens += opening_block_count line_lex
109
- closes = closing_block_count line_lex
110
- return false if opens == closes
111
- return true if opens > closes
112
- end
113
-
114
- # kinda complex, we count open/close to determine if we ultimately have close a
115
- # hanging line. Always true if it's a both_block.
116
- def closing_block?(line_lex)
117
- return true if both_block? line_lex
118
- opens = starts_block?(line_lex) ? 1 : 0
119
- opens += opening_block_count line_lex
120
- closes = closing_block_count line_lex
121
- return false if opens == closes
122
- return true if opens < closes
123
- end
124
-
125
- # count the amount of opening assignments.
126
- def opening_assignment_count(line_lex)
127
- line_lex.select {|l| @open_brackets.include? l[1]}.count
128
- end
129
-
130
- # count the amount of closing assignments.
131
- def closing_assignment_count(line_lex)
132
- line_lex.select {|l| @close_brackets.include? l[1]}.count
133
- end
134
-
135
- # same trick as opening_block
136
- def opening_assignment?(line_lex)
137
- opens = opening_assignment_count line_lex
138
- closes = closing_assignment_count line_lex
139
- return false if opens == closes
140
- return true if opens > closes
141
- end
142
-
143
- # ...
144
- def closing_assignment?(line_lex)
145
- opens = opening_assignment_count line_lex
146
- closes = closing_assignment_count line_lex
147
- return false if opens == closes
148
- return true if closes > opens
149
- end
150
-
151
- # test for assignment from a block
152
- def contains_block_assignment?(line_lex)
153
- compacted_line = line_lex.reject{|x| x[1] == :on_sp} #remove spaces
154
- idx = compacted_line.rindex{|x| ['=', '||='].include? x[2]} #find last equal
155
- if idx
156
- return @open_block_start.include?(compacted_line[idx+1][2]) #check for if/begin block
157
- end
158
- return false
159
- end
160
-
161
- # is this ruby file valid syntax?
162
- def valid_syntax?(file)
163
- #ugly but fast, ruby returns stdout if it's ok, and stderr if not.
164
- #if we get anything back, we were ok, else we were not.
165
- r = `ruby -c #{file} 2> /dev/null`
166
- return false if r == ""
167
- return true
168
- end
169
-
170
20
  # no argument, assume we want to open STDIN.
171
21
  if ARGV.empty?
172
- content = $stdin.read
173
- puts pretty content
22
+ content = $stdin.read
174
23
  else
175
- file = ARGV[0]
176
- if File.exist? file
177
- if valid_syntax? file
178
- content = open(file).read
179
- pretty content
180
- else
181
- puts content
182
- exit 127
183
- end
184
- else
185
- puts "No such file: #{file}"
186
- end
24
+ file = ARGV[0]
25
+
26
+ if File.exist? file
27
+ content = open(file).read
28
+ else
29
+ puts "No such file: #{file}"
30
+ exit
31
+ end
32
+ end
33
+
34
+ if content
35
+ if syntax_ok? content
36
+ pretty_string content, indent_token: @indent_token, indent_count: @indent_count
37
+ else
38
+ puts content
39
+ exit 127
40
+ end
187
41
  end
data/bin/ruby-beautify CHANGED
@@ -3,185 +3,39 @@ require 'ruby-beautify'
3
3
  require 'ripper'
4
4
  require 'optparse'
5
5
 
6
+ include RubyBeautify
7
+
6
8
  Options = OptionParser.new do |opts|
7
- opts.on("-V", "--version", "Print version") { |version| puts RBeautify::VERSION;exit 0}
8
- opts.on("-c", "--indent_count [COUNT]", Integer, "Count of characters to use for indenting. (default: 1)") { |count| @indent_count = count}
9
- opts.on("-t", "--tabs", "Use tabs for the indent character (default)") { @indent_token = "\t" }
10
- opts.on("-s", "--spaces", "Use spaces for the indent character") { @indent_token = " " }
11
- opts.banner = "Usage: print ruby into a pretty format, or break trying."
9
+ opts.on("-V", "--version", "Print version") { |version| puts RBeautify::VERSION;exit 0}
10
+ opts.on("-c", "--indent_count [COUNT]", Integer, "Count of characters to use for indenting. (default: 1)") { |count| @indent_count = count}
11
+ opts.on("-t", "--tabs", "Use tabs for the indent character (default)") { @indent_token = "\t" }
12
+ opts.on("-s", "--spaces", "Use spaces for the indent character") { @indent_token = " " }
13
+ opts.banner = "Usage: print ruby into a pretty format, or break trying."
12
14
  end
13
15
  Options.parse!
14
16
 
15
- @open_block_start = ["module", "class", "begin", "def", 'if', 'while', 'unless', 'case']
16
- @both_block = ["else", "elsif", 'rescue', 'when']
17
- @open_block_do = ['do', '{']
18
- @close_block = ['end', '}']
19
-
20
- @open_brackets = [:on_lparen, :on_lbracket, :on_lbrace, :on_embexpr_beg]
21
- @close_brackets = [:on_rparen, :on_rbracket, :on_rbrace, :on_embexpr_end]
22
- @new_lines = [:on_nl, :on_ignored_nl, :on_comment, :on_embdoc_end]
23
-
24
17
  @indent_token = "\t" unless @indent_token
25
18
  @indent_count = 1 unless @indent_count
26
19
 
27
- def puts_indented_line(level, string)
28
- if string =~ /^\n$/
29
- puts
30
- else
31
- indent = (@indent_token * @indent_count) * level
32
- puts "#{indent}#{string.lstrip}"
33
- end
34
- end
35
-
36
- def pretty(content)
37
- begin
38
- lex = Ripper.lex(content)
39
- rescue
40
- exit 255
41
- end
42
-
43
- indent_level = 0
44
- line_lex = []
45
-
46
- # walk through line tokens
47
- lex.each do |token|
48
- line_lex << token
49
- if @new_lines.include? token[1] # if type of this token is a new line
50
-
51
- # did we just close something? if so, lets bring it down a level.
52
- if closing_block?(line_lex) || closing_assignment?(line_lex)
53
- indent_level -= 1 if indent_level > 0
54
- end
55
-
56
- # print our line, in place.
57
- line_string = line_lex.map {|l| l.last}.join
58
- puts_indented_line(indent_level, line_string)
59
-
60
- # oh, we opened something did we? lets indent for the next run.
61
- if opening_block?(line_lex) || opening_assignment?(line_lex)
62
- indent_level += 1
63
- end
64
-
65
- line_lex.clear
66
- end
67
- end
68
-
69
- return nil
70
- end
71
-
72
- # how many times do we open in this line?
73
- def opening_block_count(line_lex)
74
- line_lex.select {|l| l[1] == :on_kw && @open_block_do.include?(l[2])}.count
75
- end
76
-
77
- # how many times do we close?
78
- def closing_block_count(line_lex)
79
- line_lex.select {|l| l[1] == :on_kw && @close_block.include?(l[2])}.count
80
- end
81
-
82
- # is the first word a key word?
83
- def starts_block?(line_lex)
84
- return true if contains_block_assignment? line_lex
85
- line_lex.each do |x|
86
- # search for a first non-space token
87
- if not x[1] == :on_sp
88
- return x[1] == :on_kw && @open_block_start.include?(x[2])
89
- end
90
- end
91
- end
92
-
93
- # is the first word one of our 'both' keywords?
94
- def both_block?(line_lex)
95
- line_lex.each do |x|
96
- # search for a first non-space token
97
- if not x[1] == :on_sp
98
- return x[1] == :on_kw && @both_block.include?(x[2])
99
- end
100
- end
101
- end
102
-
103
- # kinda complex, we count open/close to determine if we ultimately have a
104
- # hanging line. Always true if it's a both_block.
105
- def opening_block?(line_lex)
106
- return true if both_block? line_lex
107
- opens = starts_block?(line_lex) ? 1 : 0
108
- opens += opening_block_count line_lex
109
- closes = closing_block_count line_lex
110
- return false if opens == closes
111
- return true if opens > closes
112
- end
113
-
114
- # kinda complex, we count open/close to determine if we ultimately have close a
115
- # hanging line. Always true if it's a both_block.
116
- def closing_block?(line_lex)
117
- return true if both_block? line_lex
118
- opens = starts_block?(line_lex) ? 1 : 0
119
- opens += opening_block_count line_lex
120
- closes = closing_block_count line_lex
121
- return false if opens == closes
122
- return true if opens < closes
123
- end
124
-
125
- # count the amount of opening assignments.
126
- def opening_assignment_count(line_lex)
127
- line_lex.select {|l| @open_brackets.include? l[1]}.count
128
- end
129
-
130
- # count the amount of closing assignments.
131
- def closing_assignment_count(line_lex)
132
- line_lex.select {|l| @close_brackets.include? l[1]}.count
133
- end
134
-
135
- # same trick as opening_block
136
- def opening_assignment?(line_lex)
137
- opens = opening_assignment_count line_lex
138
- closes = closing_assignment_count line_lex
139
- return false if opens == closes
140
- return true if opens > closes
141
- end
142
-
143
- # ...
144
- def closing_assignment?(line_lex)
145
- opens = opening_assignment_count line_lex
146
- closes = closing_assignment_count line_lex
147
- return false if opens == closes
148
- return true if closes > opens
149
- end
150
-
151
- # test for assignment from a block
152
- def contains_block_assignment?(line_lex)
153
- compacted_line = line_lex.reject{|x| x[1] == :on_sp} #remove spaces
154
- idx = compacted_line.rindex{|x| ['=', '||='].include? x[2]} #find last equal
155
- if idx
156
- return @open_block_start.include?(compacted_line[idx+1][2]) #check for if/begin block
157
- end
158
- return false
159
- end
160
-
161
- # is this ruby file valid syntax?
162
- def valid_syntax?(file)
163
- #ugly but fast, ruby returns stdout if it's ok, and stderr if not.
164
- #if we get anything back, we were ok, else we were not.
165
- r = `ruby -c #{file} 2> /dev/null`
166
- return false if r == ""
167
- return true
168
- end
169
-
170
20
  # no argument, assume we want to open STDIN.
171
21
  if ARGV.empty?
172
- content = $stdin.read
173
- puts pretty content
22
+ content = $stdin.read
174
23
  else
175
- file = ARGV[0]
176
- if File.exist? file
177
- if valid_syntax? file
178
- content = open(file).read
179
- pretty content
180
- else
181
- puts content
182
- exit 127
183
- end
184
- else
185
- puts "No such file: #{file}"
186
- end
24
+ file = ARGV[0]
25
+
26
+ if File.exist? file
27
+ content = open(file).read
28
+ else
29
+ puts "No such file: #{file}"
30
+ exit
31
+ end
32
+ end
33
+
34
+ if content
35
+ if syntax_ok? content
36
+ pretty_string content, indent_token: @indent_token, indent_count: @indent_count
37
+ else
38
+ puts content
39
+ exit 127
40
+ end
187
41
  end
data/lib/ruby-beautify.rb CHANGED
@@ -1,20 +1,157 @@
1
- require "ruby-beautify/version"
1
+ require 'open3'
2
+ require 'ruby-beautify/version'
2
3
 
3
- module RBeautify
4
- def self.beautify_string(language, source, use_tabs=false)
5
- dest = ""
6
- block = nil
4
+ module RubyBeautify
5
+ extend self
7
6
 
8
- unless language.is_a? RBeautify::Language
9
- language = RBeautify::Language.language(language)
7
+ OPEN_BLOCK_START = ["module", "class", "begin", "def", 'if', 'while', 'unless', 'case']
8
+ BOTH_BLOCK = ["else", "elsif", 'rescue', 'when']
9
+ OPEN_BLOCK_DO = ['do', '{']
10
+ CLOSE_BLOCK = ['end', '}']
11
+
12
+ OPEN_BRACKETS = [:on_lparen, :on_lbracket, :on_lbrace, :on_embexpr_beg]
13
+ CLOSE_BRACKETS = [:on_rparen, :on_rbracket, :on_rbrace, :on_embexpr_end]
14
+ NEW_LINES = [:on_nl, :on_ignored_nl, :on_comment, :on_embdoc_end]
15
+
16
+ # print an indented line. Requires the leve, token, count, and string.
17
+ def puts_indented_line(level, token = "\t", count = 1, string)
18
+ if string =~ /^\n$/
19
+ puts
20
+ else
21
+ indent = (token * count) * level
22
+ puts "#{indent}#{string.lstrip}"
23
+ end
24
+ end
25
+
26
+ def pretty_string(content, indent_token: "\t", indent_count: 1)
27
+ begin
28
+ lex = Ripper.lex(content)
29
+ rescue
30
+ exit 255
31
+ end
32
+
33
+ indent_level = 0
34
+ line_lex = []
35
+
36
+ # walk through line tokens
37
+ lex.each do |token|
38
+ line_lex << token
39
+ if NEW_LINES.include? token[1] # if type of this token is a new line
40
+
41
+ # did we just close something? if so, lets bring it down a level.
42
+ if closing_block?(line_lex) || closing_assignment?(line_lex)
43
+ indent_level -= 1 if indent_level > 0
44
+ end
45
+
46
+ # print our line, in place.
47
+ line_string = line_lex.map {|l| l.last}.join
48
+ puts_indented_line(indent_level, indent_token, indent_count, line_string)
49
+
50
+ # oh, we opened something did we? lets indent for the next run.
51
+ if opening_block?(line_lex) || opening_assignment?(line_lex)
52
+ indent_level += 1
53
+ end
54
+
55
+ line_lex.clear
56
+ end
57
+ end
58
+
59
+ return nil
60
+ end
61
+
62
+ # how many times do we open in this line?
63
+ def opening_block_count(line_lex)
64
+ line_lex.select {|l| l[1] == :on_kw && OPEN_BLOCK_DO.include?(l[2])}.count
65
+ end
66
+
67
+ # how many times do we close?
68
+ def closing_block_count(line_lex)
69
+ line_lex.select {|l| l[1] == :on_kw && CLOSE_BLOCK.include?(l[2])}.count
70
+ end
71
+
72
+ # count the amount of opening assignments.
73
+ def opening_assignment_count(line_lex)
74
+ line_lex.select {|l| OPEN_BRACKETS.include? l[1]}.count
75
+ end
76
+
77
+ # count the amount of closing assignments.
78
+ def closing_assignment_count(line_lex)
79
+ line_lex.select {|l| CLOSE_BRACKETS.include? l[1]}.count
80
+ end
81
+
82
+ # check the syntax of a string, will pipe it through the ruby bin to see if
83
+ # it has a valid syntax.
84
+ def syntax_ok?(string)
85
+ out, err, status = Open3.capture3("ruby -c -", stdin_data:string )
86
+ return false unless err.empty?
87
+ return true
88
+ end
89
+
90
+ # same trick as opening_block
91
+ def opening_assignment?(line_lex)
92
+ opens = opening_assignment_count line_lex
93
+ closes = closing_assignment_count line_lex
94
+ return false if opens == closes
95
+ return true if opens > closes
96
+ end
97
+
98
+ # ...
99
+ def closing_assignment?(line_lex)
100
+ opens = opening_assignment_count line_lex
101
+ closes = closing_assignment_count line_lex
102
+ return false if opens == closes
103
+ return true if closes > opens
104
+ end
105
+
106
+ # test for assignment from a block
107
+ def contains_block_assignment?(line_lex)
108
+ compacted_line = line_lex.reject{|x| x[1] == :on_sp} #remove spaces
109
+ idx = compacted_line.rindex{|x| ['=', '||='].include? x[2]} #find last equal
110
+ if idx
111
+ return OPEN_BLOCK_START.include?(compacted_line[idx+1][2]) #check for if/begin block
10
112
  end
113
+ return false
114
+ end
11
115
 
12
- source.lines.each_with_index do |line_content, line_number|
13
- line = RBeautify::Line.new(language, line_content, line_number, block, use_tabs)
14
- dest += line.format + "\n"
15
- block = line.block
116
+ # is the first word a key word?
117
+ def starts_block?(line_lex)
118
+ return true if contains_block_assignment? line_lex
119
+ line_lex.each do |x|
120
+ # search for a first non-space token
121
+ if not x[1] == :on_sp
122
+ return x[1] == :on_kw && OPEN_BLOCK_START.include?(x[2])
123
+ end
16
124
  end
125
+ end
126
+
127
+ # is the first word one of our 'both' keywords?
128
+ def both_block?(line_lex)
129
+ line_lex.each do |x|
130
+ # search for a first non-space token
131
+ if not x[1] == :on_sp
132
+ return x[1] == :on_kw && BOTH_BLOCK.include?(x[2])
133
+ end
134
+ end
135
+ end
136
+
137
+ # kinda complex, we count open/close to determine if we ultimately have a
138
+ # hanging line. Always true if it's a both_block.
139
+ def opening_block?(line_lex)
140
+ opens = (starts_block?(line_lex) || both_block?(line_lex)) ? 1 : 0
141
+ opens += opening_block_count line_lex
142
+ closes = closing_block_count line_lex
143
+ return false if opens == closes
144
+ return true if opens > closes
145
+ end
17
146
 
18
- return dest
147
+ # kinda complex, we count open/close to determine if we ultimately have close a
148
+ # hanging line. Always true if it's a both_block.
149
+ def closing_block?(line_lex)
150
+ return true if both_block? line_lex
151
+ opens = starts_block?(line_lex) ? 1 : 0
152
+ opens += opening_block_count line_lex
153
+ closes = closing_block_count line_lex
154
+ return false if opens == closes
155
+ return true if opens < closes
19
156
  end
20
- end # module RBeautify
157
+ end
@@ -1,3 +1,3 @@
1
- module RBeautify
2
- VERSION = "0.95.0"
1
+ module RubyBeautify
2
+ VERSION = "0.96.0"
3
3
  end
@@ -13,7 +13,7 @@ Gem::Specification.new do |gem|
13
13
  gem.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
14
14
  gem.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
15
15
  gem.require_paths = ["lib"]
16
- gem.version = RBeautify::VERSION
16
+ gem.version = RubyBeautify::VERSION
17
17
  gem.add_development_dependency 'rake'
18
18
  gem.add_development_dependency 'bundler'
19
19
  gem.add_development_dependency 'rspec'
data/spec/example.rb CHANGED
@@ -69,6 +69,11 @@ else
69
69
  puts 'not likely.'
70
70
  end
71
71
 
72
+ #Test for different if-statement formatting
73
+ if 1 > 0 then puts 'something'
74
+ else puts 'nothing' end
75
+ puts "This line should stay the same"
76
+
72
77
  # Test for already indented blocks
73
78
  class There2 < There
74
79
  def m1()
@@ -69,6 +69,11 @@ else
69
69
  puts 'not likely.'
70
70
  end
71
71
 
72
+ #Test for different if-statement formatting
73
+ if 1 > 0 then puts 'something'
74
+ else puts 'nothing' end
75
+ puts "This line should stay the same"
76
+
72
77
  # Test for already indented blocks
73
78
  class There2 < There
74
79
  def m1()
metadata CHANGED
@@ -1,55 +1,55 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ruby-beautify
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.95.0
4
+ version: 0.96.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ernie Brodeur
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-01-15 00:00:00.000000000 Z
11
+ date: 2015-01-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - ">="
17
+ - - '>='
18
18
  - !ruby/object:Gem::Version
19
19
  version: '0'
20
20
  type: :development
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - ">="
24
+ - - '>='
25
25
  - !ruby/object:Gem::Version
26
26
  version: '0'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: bundler
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - ">="
31
+ - - '>='
32
32
  - !ruby/object:Gem::Version
33
33
  version: '0'
34
34
  type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - ">="
38
+ - - '>='
39
39
  - !ruby/object:Gem::Version
40
40
  version: '0'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: rspec
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - ">="
45
+ - - '>='
46
46
  - !ruby/object:Gem::Version
47
47
  version: '0'
48
48
  type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - ">="
52
+ - - '>='
53
53
  - !ruby/object:Gem::Version
54
54
  version: '0'
55
55
  description: a cli tool (and module) to beautify ruby code.
@@ -60,9 +60,10 @@ executables:
60
60
  extensions: []
61
61
  extra_rdoc_files: []
62
62
  files:
63
- - ".gitignore"
64
- - ".rspec"
65
- - ".travis.yml"
63
+ - .gitignore
64
+ - .rspec
65
+ - .travis.yml
66
+ - CONTRIB.md
66
67
  - Gemfile
67
68
  - Guardfile
68
69
  - LICENSE
@@ -87,17 +88,17 @@ require_paths:
87
88
  - lib
88
89
  required_ruby_version: !ruby/object:Gem::Requirement
89
90
  requirements:
90
- - - ">="
91
+ - - '>='
91
92
  - !ruby/object:Gem::Version
92
93
  version: '2.0'
93
94
  required_rubygems_version: !ruby/object:Gem::Requirement
94
95
  requirements:
95
- - - ">="
96
+ - - '>='
96
97
  - !ruby/object:Gem::Version
97
98
  version: '0'
98
99
  requirements: []
99
100
  rubyforge_project:
100
- rubygems_version: 2.2.2
101
+ rubygems_version: 2.4.5
101
102
  signing_key:
102
103
  specification_version: 4
103
104
  summary: a cli tool (and module) to beautify ruby code.