tailor 0.1.3 → 0.1.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.gemtest +0 -0
- data/.gitignore +7 -0
- data/.infinity_test +4 -0
- data/.rspec +1 -0
- data/ChangeLog.rdoc +48 -0
- data/Gemfile +2 -0
- data/Gemfile.lock +107 -0
- data/README.rdoc +9 -4
- data/Rakefile +16 -81
- data/bin/tailor +41 -10
- data/features/step_definitions/spacing_steps.rb +1 -1
- data/features/support/1_file_with_bad_curly_brace_spacing/bad_curly_brace_spacing.rb +1 -1
- data/features/support/1_file_with_bad_square_brackets/bad_square_brackets.rb +1 -1
- data/features/support/1_long_file_with_indentation/my_project.rb +1 -1
- data/features/support/env.rb +1 -1
- data/lib/tailor.rb +7 -8
- data/lib/tailor/file_line.rb +23 -27
- data/lib/tailor/indentation.rb +19 -25
- data/lib/tailor/spacing.rb +13 -19
- data/lib/tailor/version.rb +3 -0
- data/spec/file_line_spec.rb +2 -2
- data/spec/indentation_spec.rb +10 -10
- data/spec/spacing/colon_spacing_spec.rb +1 -1
- data/spec/spacing/comma_spacing_spec.rb +1 -1
- data/spec/spacing/curly_brace_spacing_spec.rb +2 -3
- data/spec/spacing/parentheses_spacing_spec.rb +2 -2
- data/spec/spacing/square_bracket_spacing_spec.rb +2 -2
- data/spec/spacing_spec.rb +1 -1
- data/spec/spec_helper.rb +1 -8
- data/spec/tailor_spec.rb +2 -2
- data/tailor.gemspec +45 -0
- data/{lib/tasks → tasks}/metrics.rake +0 -0
- data/{lib/tasks → tasks}/stats.rake +3 -2
- metadata +130 -195
- data/.autotest +0 -24
- data/History.txt +0 -40
- data/Manifest.txt +0 -61
- data/PostInstall.txt +0 -10
- data/features/development.feature +0 -13
- data/features/step_definitions/common_steps.rb +0 -175
- data/lib/tailor/grammars/bad_comma_style.citrus +0 -53
- data/logic.txt +0 -30
- data/output.txt +0 -6577
- data/ruby-style-checker.rb +0 -167
- data/script/console +0 -10
- data/script/destroy +0 -14
- data/script/generate +0 -14
- data/spec/spec.opts +0 -1
- data/tasks/rspec.rake +0 -21
data/ruby-style-checker.rb
DELETED
|
@@ -1,167 +0,0 @@
|
|
|
1
|
-
$tab_size = 2
|
|
2
|
-
$tab_string = " "
|
|
3
|
-
|
|
4
|
-
# indent regexp tests
|
|
5
|
-
|
|
6
|
-
$indent_expression = [
|
|
7
|
-
/^module\b/,
|
|
8
|
-
/(=\s*|^)if\b/,
|
|
9
|
-
/(=\s*|^)until\b/,
|
|
10
|
-
/(=\s*|^)for\b/,
|
|
11
|
-
/(=\s*|^)unless\b/,
|
|
12
|
-
/(=\s*|^)while\b/,
|
|
13
|
-
/(=\s*|^)begin\b/,
|
|
14
|
-
/(=\s*|^)case\b/,
|
|
15
|
-
/\bthen\b/,
|
|
16
|
-
/^class\b/,
|
|
17
|
-
/^rescue\b/,
|
|
18
|
-
/^def\b/,
|
|
19
|
-
/\bdo\b/,
|
|
20
|
-
/^else\b/,
|
|
21
|
-
/^elsif\b/,
|
|
22
|
-
/^ensure\b/,
|
|
23
|
-
/\bwhen\b/,
|
|
24
|
-
/\{[^\}]*$/,
|
|
25
|
-
/\[[^\]]*$/
|
|
26
|
-
]
|
|
27
|
-
|
|
28
|
-
# outdent regexp tests
|
|
29
|
-
|
|
30
|
-
$outdent_expression = [
|
|
31
|
-
/^rescue\b/,
|
|
32
|
-
/^ensure\b/,
|
|
33
|
-
/^elsif\b/,
|
|
34
|
-
/^end\b/,
|
|
35
|
-
/^else\b/,
|
|
36
|
-
/\bwhen\b/,
|
|
37
|
-
/^[^\{]*\}/,
|
|
38
|
-
/^[^\[]*\]/
|
|
39
|
-
]
|
|
40
|
-
|
|
41
|
-
def make_tab(tab)
|
|
42
|
-
# If the tab is negative, don't do anything
|
|
43
|
-
return (tab < 0) ? "" : $tab_string * $tab_size * tab
|
|
44
|
-
end
|
|
45
|
-
|
|
46
|
-
def add_line line, tab
|
|
47
|
-
line.strip!
|
|
48
|
-
line = make_tab(tab) + line if line.length > 0
|
|
49
|
-
return line + "\n"
|
|
50
|
-
end
|
|
51
|
-
|
|
52
|
-
def format_ruby
|
|
53
|
-
comment_block = false
|
|
54
|
-
multi_line_array = Array.new
|
|
55
|
-
multi_line_string = ""
|
|
56
|
-
tab = 0
|
|
57
|
-
############
|
|
58
|
-
#filename entered on command line as argument gets passed in Ruby's
|
|
59
|
-
#special argument array ARGV. The ARGV[0] zeroth element has the filename
|
|
60
|
-
############
|
|
61
|
-
filename = ARGV[0]
|
|
62
|
-
|
|
63
|
-
# Open the file for reading
|
|
64
|
-
source = File.new(filename,'r').read
|
|
65
|
-
new_file = ""
|
|
66
|
-
|
|
67
|
-
# Read each line
|
|
68
|
-
source.split("\n").each do |line|
|
|
69
|
-
# SKIPPING THIS FOR NOW. NOT SURE WHY I'D NEED TO DO THIS YET.
|
|
70
|
-
# Says: if it's not a comment line and has a \ (plus spaces)
|
|
71
|
-
# combine continuing lines
|
|
72
|
-
if(!(line =~ /^\s*#/) && line =~ /[^\\]\\\s*$/)
|
|
73
|
-
multi_line_array.push line
|
|
74
|
-
multi_line_string += line.sub(/^(.*)\\\s*$/,"\\1")
|
|
75
|
-
next
|
|
76
|
-
end
|
|
77
|
-
|
|
78
|
-
# THIS GOES WITH THE PREVIOUS IF STATEMENT; SKIP FOR NOW.
|
|
79
|
-
# add final line
|
|
80
|
-
if(multi_line_string.length > 0)
|
|
81
|
-
multi_line_array.push line
|
|
82
|
-
multi_line_string += line.sub(/^(.*)\\\s*$/,"\\1")
|
|
83
|
-
end
|
|
84
|
-
|
|
85
|
-
# tab_line is really just the line to check
|
|
86
|
-
tab_line = ((multi_line_string.length > 0) ? multi_line_string : line).strip
|
|
87
|
-
|
|
88
|
-
# HE SKIPS CHECKING OF COMMENT BLOCKS; LET'S GO AHEAD AND CHECK THEM
|
|
89
|
-
if(tab_line =~ /^=begin/)
|
|
90
|
-
comment_block = true
|
|
91
|
-
end
|
|
92
|
-
|
|
93
|
-
if(comment_block)
|
|
94
|
-
# add the line unchanged
|
|
95
|
-
new_file += line + "\n"
|
|
96
|
-
# THIS IS WHERE THE MAGIC STARTS
|
|
97
|
-
else
|
|
98
|
-
commentab_line = (tab_line =~ /^#/)
|
|
99
|
-
|
|
100
|
-
#
|
|
101
|
-
if(!commentab_line)
|
|
102
|
-
# throw out sequences that will
|
|
103
|
-
# only sow confusion
|
|
104
|
-
tab_line.gsub!(/\/.*?\//,"") # Subs anything / stuff / with ""
|
|
105
|
-
tab_line.gsub!(/%r\{.*?\}/,"")
|
|
106
|
-
tab_line.gsub!(/%r(.).*?\1/,"")
|
|
107
|
-
tab_line.gsub!(/\\\"/,"'")
|
|
108
|
-
tab_line.gsub!(/".*?"/,"\"\"")
|
|
109
|
-
tab_line.gsub!(/'.*?'/,"''")
|
|
110
|
-
tab_line.gsub!(/#\{.*?\}/,"")
|
|
111
|
-
|
|
112
|
-
$outdent_expression.each do |re|
|
|
113
|
-
# Search each line for an outdent keyword
|
|
114
|
-
# If the line contains one of the keywords, it's indented too far
|
|
115
|
-
# so set it to be out 1 level
|
|
116
|
-
if(tab_line =~ re)
|
|
117
|
-
tab -= 1
|
|
118
|
-
break
|
|
119
|
-
end
|
|
120
|
-
end
|
|
121
|
-
end
|
|
122
|
-
|
|
123
|
-
if (multi_line_array.length > 0)
|
|
124
|
-
# This will:
|
|
125
|
-
# Set lines with indent keywords to not change their indenting.
|
|
126
|
-
# Set lines without indent keywords to not change their indenting
|
|
127
|
-
# since tab is still 0.
|
|
128
|
-
multi_line_array.each do |ml|
|
|
129
|
-
# He adds the line; I'd compare actual vs. proper.
|
|
130
|
-
dest += add_line(ml,tab)
|
|
131
|
-
end
|
|
132
|
-
multi_line_array.clear
|
|
133
|
-
multi_line_string = ""
|
|
134
|
-
else
|
|
135
|
-
dest += add_line(line,tab)
|
|
136
|
-
end
|
|
137
|
-
|
|
138
|
-
if(!commentab_line)
|
|
139
|
-
# Check the line to see if it contains one of the indent keywords
|
|
140
|
-
$indent_expression.each do |re|
|
|
141
|
-
# If it does contain one of the keywords and doesn't contain the
|
|
142
|
-
# 'end' keywords
|
|
143
|
-
if(tab_line =~ re && !(tab_line =~ /\s+end\s*$/))
|
|
144
|
-
# Bump the level up 1
|
|
145
|
-
tab += 1
|
|
146
|
-
break
|
|
147
|
-
end
|
|
148
|
-
end
|
|
149
|
-
end
|
|
150
|
-
end
|
|
151
|
-
|
|
152
|
-
if(tab_line =~ /^=end/)
|
|
153
|
-
comment_block = false
|
|
154
|
-
end
|
|
155
|
-
end
|
|
156
|
-
|
|
157
|
-
#STDOUT.write(dest)
|
|
158
|
-
#File.open(filename, 'w') {|fw| fw.write(dest)}
|
|
159
|
-
puts "File #{ARGV[0]} has been formatted."
|
|
160
|
-
|
|
161
|
-
# uncomment this to complain about mismatched blocks
|
|
162
|
-
if(tab != 0)
|
|
163
|
-
STDERR.puts "Indentation error: #{tab}"
|
|
164
|
-
end
|
|
165
|
-
end
|
|
166
|
-
|
|
167
|
-
format_ruby
|
data/script/console
DELETED
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env ruby
|
|
2
|
-
# File: script/console
|
|
3
|
-
irb = RUBY_PLATFORM =~ /(:?mswin|mingw)/ ? 'irb.bat' : 'irb'
|
|
4
|
-
|
|
5
|
-
libs = " -r irb/completion"
|
|
6
|
-
# Perhaps use a console_lib to store any extra methods I may want available in the cosole
|
|
7
|
-
# libs << " -r #{File.dirname(__FILE__) + '/../lib/console_lib/console_logger.rb'}"
|
|
8
|
-
libs << " -r #{File.dirname(__FILE__) + '/../lib/tailor'}"
|
|
9
|
-
puts "Loading tailor gem"
|
|
10
|
-
exec "#{irb} #{libs} --simple-prompt"
|
data/script/destroy
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env ruby
|
|
2
|
-
APP_ROOT = File.expand_path(File.join(File.dirname(__FILE__), '..'))
|
|
3
|
-
|
|
4
|
-
begin
|
|
5
|
-
require 'rubigen'
|
|
6
|
-
rescue LoadError
|
|
7
|
-
require 'rubygems'
|
|
8
|
-
require 'rubigen'
|
|
9
|
-
end
|
|
10
|
-
require 'rubigen/scripts/destroy'
|
|
11
|
-
|
|
12
|
-
ARGV.shift if ['--help', '-h'].include?(ARGV[0])
|
|
13
|
-
RubiGen::Base.use_component_sources! [:rubygems, :newgem, :newgem_theme, :test_unit]
|
|
14
|
-
RubiGen::Scripts::Destroy.new.run(ARGV)
|
data/script/generate
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env ruby
|
|
2
|
-
APP_ROOT = File.expand_path(File.join(File.dirname(__FILE__), '..'))
|
|
3
|
-
|
|
4
|
-
begin
|
|
5
|
-
require 'rubigen'
|
|
6
|
-
rescue LoadError
|
|
7
|
-
require 'rubygems'
|
|
8
|
-
require 'rubigen'
|
|
9
|
-
end
|
|
10
|
-
require 'rubigen/scripts/generate'
|
|
11
|
-
|
|
12
|
-
ARGV.shift if ['--help', '-h'].include?(ARGV[0])
|
|
13
|
-
RubiGen::Base.use_component_sources! [:rubygems, :newgem, :newgem_theme, :test_unit]
|
|
14
|
-
RubiGen::Scripts::Generate.new.run(ARGV)
|
data/spec/spec.opts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
--colour
|
data/tasks/rspec.rake
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
begin
|
|
2
|
-
require 'spec'
|
|
3
|
-
rescue LoadError
|
|
4
|
-
require 'rubygems' unless ENV['NO_RUBYGEMS']
|
|
5
|
-
require 'spec'
|
|
6
|
-
end
|
|
7
|
-
begin
|
|
8
|
-
require 'spec/rake/spectask'
|
|
9
|
-
rescue LoadError
|
|
10
|
-
puts <<-EOS
|
|
11
|
-
To use rspec for testing you must install rspec gem:
|
|
12
|
-
gem install rspec
|
|
13
|
-
EOS
|
|
14
|
-
exit(0)
|
|
15
|
-
end
|
|
16
|
-
|
|
17
|
-
desc "Run the specs under spec/models"
|
|
18
|
-
Spec::Rake::SpecTask.new do |t|
|
|
19
|
-
t.spec_opts = ['--options', "spec/spec.opts"]
|
|
20
|
-
t.spec_files = FileList['spec/**/*_spec.rb']
|
|
21
|
-
end
|