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.
Files changed (49) hide show
  1. data/.gemtest +0 -0
  2. data/.gitignore +7 -0
  3. data/.infinity_test +4 -0
  4. data/.rspec +1 -0
  5. data/ChangeLog.rdoc +48 -0
  6. data/Gemfile +2 -0
  7. data/Gemfile.lock +107 -0
  8. data/README.rdoc +9 -4
  9. data/Rakefile +16 -81
  10. data/bin/tailor +41 -10
  11. data/features/step_definitions/spacing_steps.rb +1 -1
  12. data/features/support/1_file_with_bad_curly_brace_spacing/bad_curly_brace_spacing.rb +1 -1
  13. data/features/support/1_file_with_bad_square_brackets/bad_square_brackets.rb +1 -1
  14. data/features/support/1_long_file_with_indentation/my_project.rb +1 -1
  15. data/features/support/env.rb +1 -1
  16. data/lib/tailor.rb +7 -8
  17. data/lib/tailor/file_line.rb +23 -27
  18. data/lib/tailor/indentation.rb +19 -25
  19. data/lib/tailor/spacing.rb +13 -19
  20. data/lib/tailor/version.rb +3 -0
  21. data/spec/file_line_spec.rb +2 -2
  22. data/spec/indentation_spec.rb +10 -10
  23. data/spec/spacing/colon_spacing_spec.rb +1 -1
  24. data/spec/spacing/comma_spacing_spec.rb +1 -1
  25. data/spec/spacing/curly_brace_spacing_spec.rb +2 -3
  26. data/spec/spacing/parentheses_spacing_spec.rb +2 -2
  27. data/spec/spacing/square_bracket_spacing_spec.rb +2 -2
  28. data/spec/spacing_spec.rb +1 -1
  29. data/spec/spec_helper.rb +1 -8
  30. data/spec/tailor_spec.rb +2 -2
  31. data/tailor.gemspec +45 -0
  32. data/{lib/tasks → tasks}/metrics.rake +0 -0
  33. data/{lib/tasks → tasks}/stats.rake +3 -2
  34. metadata +130 -195
  35. data/.autotest +0 -24
  36. data/History.txt +0 -40
  37. data/Manifest.txt +0 -61
  38. data/PostInstall.txt +0 -10
  39. data/features/development.feature +0 -13
  40. data/features/step_definitions/common_steps.rb +0 -175
  41. data/lib/tailor/grammars/bad_comma_style.citrus +0 -53
  42. data/logic.txt +0 -30
  43. data/output.txt +0 -6577
  44. data/ruby-style-checker.rb +0 -167
  45. data/script/console +0 -10
  46. data/script/destroy +0 -14
  47. data/script/generate +0 -14
  48. data/spec/spec.opts +0 -1
  49. data/tasks/rspec.rake +0 -21
@@ -7,12 +7,12 @@ require 'term/ansicolor'
7
7
  module Tailor
8
8
 
9
9
  # Calling modules will get the Ruby file to check, then read by line. This
10
- # class allows for checking of line-specific style by Represents a single
11
- # line of a file of Ruby code. Inherits from String so "self" can be used.
10
+ # class allows for checking of line-specific style by Represents a single
11
+ # line of a file of Ruby code. Inherits from String so "self" can be used.
12
12
  #
13
13
  # Methods are named such that they check for bad style conditions, and return
14
- # true and print the associated error message when the bad style condition
15
- # is discovered in the file line.
14
+ # true and print the associated error message when the bad style condition
15
+ # is discovered in the file line.
16
16
  class FileLine < String
17
17
  include Tailor::Spacing
18
18
  include Tailor::Indentation
@@ -21,7 +21,7 @@ module Tailor
21
21
  LINE_LENGTH_MAX = 80
22
22
 
23
23
  # This passes the line of code to String (the parent) so that it can act
24
- # like a standard string.
24
+ # like a standard string.
25
25
  #
26
26
  # @param [String] line_of_code Line from a Ruby file that will be checked
27
27
  # for styling.
@@ -30,7 +30,7 @@ module Tailor
30
30
  # line.
31
31
  # @return [String] Returns a String that includes all of the methods
32
32
  # defined here.
33
- def initialize line_of_code, file_path, line_number
33
+ def initialize(line_of_code, file_path, line_number)
34
34
  super line_of_code
35
35
  @file_path = file_path
36
36
  @line_number = line_number
@@ -59,7 +59,7 @@ module Tailor
59
59
  return true
60
60
  end
61
61
 
62
- return false
62
+ false
63
63
  end
64
64
 
65
65
  # Checks to see if the class name is using snake case.
@@ -81,7 +81,7 @@ module Tailor
81
81
  return true
82
82
  end
83
83
 
84
- return false
84
+ false
85
85
  end
86
86
 
87
87
  # Checks to see if the line is the start of a method's definition.
@@ -93,12 +93,11 @@ module Tailor
93
93
  return true
94
94
  end
95
95
 
96
- return false
96
+ false
97
97
  end
98
98
 
99
- ##
100
99
  # Returns the name of the method if the line is one that contains a method
101
- # definition.
100
+ # definition.
102
101
  #
103
102
  # @return [String] The method name.
104
103
  def method_name
@@ -120,12 +119,11 @@ module Tailor
120
119
  return true
121
120
  end
122
121
 
123
- return false
122
+ false
124
123
  end
125
124
 
126
- ##
127
125
  # Checks to see if the line is a regular statement (not a class, method, or
128
- # comment).
126
+ # comment).
129
127
  #
130
128
  # @return [Boolean] Returns true if the line is not a class, method or
131
129
  # comment.
@@ -134,11 +132,11 @@ module Tailor
134
132
  return false
135
133
  end
136
134
 
137
- return true
135
+ true
138
136
  end
139
137
 
140
138
  # Checks to see if the whole line is a basic comment line. This doesn't
141
- # check for trailing-line comments (@see #trailing_comment?).
139
+ # check for trailing-line comments (@see #trailing_comment?).
142
140
  #
143
141
  # @return [Boolean] Returns true if the line begins with a pound symbol.
144
142
  def comment_line?
@@ -146,10 +144,9 @@ module Tailor
146
144
  return true
147
145
  end
148
146
 
149
- return false
147
+ false
150
148
  end
151
149
 
152
- ##
153
150
  # Checks to see if the whole line is only space characters.
154
151
  #
155
152
  # @return [Boolean] Returns true if the line is only space characters.
@@ -158,12 +155,11 @@ module Tailor
158
155
  return false
159
156
  end
160
157
 
161
- return true
158
+ true
162
159
  end
163
160
 
164
- ##
165
161
  # Checks to see if the line is greater than the defined max (80 chars is
166
- # default).
162
+ # default).
167
163
  #
168
164
  # @return [Boolean] Returns true if the line length exceeds the allowed
169
165
  # length.
@@ -175,7 +171,7 @@ module Tailor
175
171
  return true
176
172
  end
177
173
 
178
- return false
174
+ false
179
175
  end
180
176
 
181
177
  #-----------------------------------------------------------------
@@ -183,8 +179,7 @@ module Tailor
183
179
  #-----------------------------------------------------------------
184
180
  private
185
181
 
186
- ##
187
- # Prints the file name and line number that the problem occured on.
182
+ # Prints the file name and line number that the problem occurred on.
188
183
  #
189
184
  # @param [String] Error message to print.
190
185
  def print_problem message
@@ -196,6 +191,7 @@ module Tailor
196
191
  puts ""
197
192
  puts line_info
198
193
  end
194
+
199
195
  puts red("\t"+ message)
200
196
  end
201
197
 
@@ -207,7 +203,7 @@ module Tailor
207
203
  return true
208
204
  end
209
205
 
210
- return false
206
+ false
211
207
  end
212
208
 
213
209
  # Checks to see if a word begins with an uppercase letter.
@@ -218,7 +214,7 @@ module Tailor
218
214
  return true
219
215
  end
220
216
 
221
- return false
217
+ false
222
218
  end
223
219
  end
224
- end
220
+ end
@@ -48,7 +48,6 @@ module Tailor
48
48
  /^[^\[]*\]/ # matches and end ] when no [ appears
49
49
  ]
50
50
 
51
- ##
52
51
  # Determines the number of spaces the line is indented.
53
52
  #
54
53
  # @return [Number] Returns the number of spaces the line is indented.
@@ -60,13 +59,12 @@ module Tailor
60
59
  return spaces.length
61
60
  end
62
61
 
63
- return 0
62
+ 0
64
63
  end
65
64
 
66
- ##
67
65
  # Determines the level to which the line is indented. For Ruby, this
68
- # should be 2 spaces. Note that this treats lines that are indented an
69
- # odd number of spaces as a multiple of 0.5 levels of indentation.
66
+ # should be 2 spaces. Note that this treats lines that are indented an
67
+ # odd number of spaces as a multiple of 0.5 levels of indentation.
70
68
  #
71
69
  # @return [Float] The level.
72
70
  def is_at_level
@@ -76,10 +74,9 @@ module Tailor
76
74
  return 0.0
77
75
  end
78
76
 
79
- return spaces.to_f / 2.0
77
+ spaces.to_f / 2.0
80
78
  end
81
79
 
82
- ##
83
80
  # Checks to see if the line contains a statement that should be indented.
84
81
  #
85
82
  # @return [Boolean] True if the line contains one of the statements and
@@ -95,10 +92,9 @@ module Tailor
95
92
  end
96
93
  end
97
94
 
98
- return false
95
+ false
99
96
  end
100
97
 
101
- ##
102
98
  # Checks to see if the line contains a statement that should be outdented.
103
99
  #
104
100
  # @return [Boolean] True if the line contains one of the statements.
@@ -114,12 +110,11 @@ module Tailor
114
110
  end
115
111
  end
116
112
 
117
- return false
113
+ false
118
114
  end
119
115
 
120
- ##
121
116
  # Checks to see if the line contains a statement that ends a code chunk:
122
- # end, ], or }.
117
+ # end, ], or }.
123
118
  #
124
119
  # @return [Boolean] True if the line contains one of the statements.
125
120
  def contains_end?
@@ -135,16 +130,15 @@ module Tailor
135
130
  end
136
131
  end
137
132
 
138
- return false
133
+ false
139
134
  end
140
135
 
141
- ##
142
136
  # Simply compares the level the line is at to the parameter that's passed
143
- # in. The proper level is maintained outside of this module.
137
+ # in. The proper level is maintained outside of this module.
144
138
  #
145
139
  # @return [Boolean] True if level of the line doesn't match the level
146
140
  # passed in. Also returns true if the line is an empty line, since that
147
- # line doens't need to be checked.
141
+ # line doesn't need to be checked.
148
142
  def at_improper_level? proper_level
149
143
  current_level = self.is_at_level
150
144
 
@@ -157,7 +151,7 @@ module Tailor
157
151
  @line_problem_count += 1
158
152
  print_problem message
159
153
 
160
- return true
154
+ true
161
155
  end
162
156
 
163
157
  def ends_with_operator?
@@ -181,7 +175,7 @@ module Tailor
181
175
  end
182
176
  end
183
177
 
184
- return result
178
+ result
185
179
  end
186
180
 
187
181
  def ends_with_comma?
@@ -194,7 +188,7 @@ module Tailor
194
188
  return true
195
189
  end
196
190
 
197
- return false
191
+ false
198
192
  end
199
193
 
200
194
  def ends_with_backslash?
@@ -207,7 +201,7 @@ module Tailor
207
201
  return true
208
202
  end
209
203
 
210
- return false
204
+ false
211
205
  end
212
206
 
213
207
  def unclosed_parenthesis?
@@ -216,11 +210,11 @@ module Tailor
216
210
  end
217
211
 
218
212
  unless self.scan(/\([^\)]*(?!=\))\s*$/).empty?
219
- puts "Ends with unclose parenthesis."
213
+ puts "Ends with unclosed parenthesis."
220
214
  return true
221
215
  end
222
216
 
223
- return false
217
+ false
224
218
  end
225
219
 
226
220
  def only_closed_parenthesis?
@@ -232,7 +226,7 @@ module Tailor
232
226
  return true
233
227
  end
234
228
 
235
- return false
229
+ false
236
230
  end
237
231
 
238
232
  def multi_line_statement?
@@ -245,7 +239,7 @@ module Tailor
245
239
  return true
246
240
  end
247
241
 
248
- return false
242
+ false
249
243
  end
250
244
  end
251
- end
245
+ end
@@ -9,15 +9,15 @@ module Tailor
9
9
  # TODO: Add skipping of comment lines.
10
10
  SPACING_CONDITIONS = {
11
11
  :more_than_one_space_after_comma => [
12
- /\,\x20{2,}(\w|'|"|:).*((?:(?!#\s*)).)*$/,
12
+ /,\x20{2,}(\w|'|"|:).*((?:(?!#\s*)).)*$/,
13
13
  "[Spacing] Line has a comma with > 1 space after it"
14
14
  ],
15
15
  :no_space_after_comma => [
16
- /\,\x20{0}\S/,
16
+ /,\x20{0}\S/,
17
17
  "[Spacing] Line has a comma with 0 spaces after it"
18
18
  ],
19
19
  :space_before_comma => [
20
- /\S\x20+\,/,
20
+ /\S\x20+,/,
21
21
  "[Spacing] Line has at least one space before a comma"
22
22
  ],
23
23
  :space_after_open_parenthesis => [
@@ -67,7 +67,6 @@ module Tailor
67
67
  ]
68
68
  }
69
69
 
70
- ##
71
70
  # Detect spacing problems around all predefined bad cases.
72
71
  #
73
72
  # @return [Number] The number of problems discovered during detection.
@@ -85,12 +84,12 @@ module Tailor
85
84
  print_problem values[1]
86
85
  end
87
86
  end
87
+
88
88
  problem_count
89
89
  end
90
90
 
91
- ##
92
91
  # Checks to see if there's whitespace at the end of the line. Prints the
93
- # number of whitespaces at the end of the line.
92
+ # number of whitespaces at the end of the line.
94
93
  #
95
94
  # @return [Boolean] Returns true if there's whitespace at the end of the
96
95
  # line.
@@ -107,9 +106,8 @@ module Tailor
107
106
  return false
108
107
  end
109
108
  =end
110
- ##
111
109
  # Checks to see if the line has trailing whitespace at the end of it. Note
112
- # that this excludes empty lines that have spaces on them!
110
+ # that this excludes empty lines that have spaces on them!
113
111
  #
114
112
  # @return [Number] Returns the number of trailing spaces at the end of the
115
113
  # line.
@@ -120,14 +118,13 @@ module Tailor
120
118
  return 0
121
119
  end
122
120
 
123
- return spaces.first.first.length
121
+ spaces.first.first.length
124
122
  end
125
123
  module_function :trailing_whitespace_count
126
124
 
127
- ##
128
125
  # Checks to see if there's no spaces before a given string. If the line
129
- # being checked is a method with a question mark at the end of it, this
130
- # skips checking the line.
126
+ # being checked is a method with a question mark at the end of it, this
127
+ # skips checking the line.
131
128
  #
132
129
  # @param [String] string The string to check for spaces before.
133
130
  # @return [Boolean] True if there are no spaces before the string.
@@ -162,7 +159,6 @@ module Tailor
162
159
  result
163
160
  end
164
161
 
165
- ##
166
162
  # Checks to see if there's no spaces after a given string.
167
163
  #
168
164
  # @param [String] string The string to check for spaces after.
@@ -203,7 +199,6 @@ module Tailor
203
199
  result
204
200
  end
205
201
 
206
- ##
207
202
  # Gets the number of spaces after a string.
208
203
  #
209
204
  # @param [String] string The string to check for spaces after.
@@ -217,10 +212,10 @@ module Tailor
217
212
 
218
213
  right_side_match = Regexp.new(Regexp.escape(string) + '\x20*')
219
214
 
220
- occurences = self.scan(right_side_match)
215
+ occurrences = self.scan(right_side_match)
221
216
 
222
217
  results = []
223
- occurences.each do |o|
218
+ occurrences.each do |o|
224
219
  string_spaces = o.sub(string, '')
225
220
  results << string_spaces.size
226
221
  end
@@ -228,7 +223,6 @@ module Tailor
228
223
  results
229
224
  end
230
225
 
231
- ##
232
226
  # Checks to see if the line contains a method name with a ?.
233
227
  #
234
228
  # @return [Boolean] True if the line contains a method line include?.
@@ -237,7 +231,7 @@ module Tailor
237
231
  return false
238
232
  end
239
233
 
240
- return true
234
+ true
241
235
  end
242
236
  end
243
- end
237
+ end
@@ -0,0 +1,3 @@
1
+ module Tailor
2
+ VERSION = '0.1.4'
3
+ end
@@ -1,4 +1,4 @@
1
- require File.dirname(__FILE__) + '/spec_helper.rb'
1
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
2
  require 'tailor/file_line'
3
3
  require 'pathname'
4
4
 
@@ -67,4 +67,4 @@ describe Tailor::FileLine do
67
67
  line.too_long?.should be_false
68
68
  end
69
69
  end
70
- end
70
+ end
@@ -1,4 +1,4 @@
1
- require File.dirname(__FILE__) + '/spec_helper.rb'
1
+ require_relative 'spec_helper'
2
2
  require 'tailor/file_line'
3
3
  require 'pathname'
4
4
 
@@ -25,7 +25,7 @@ end
25
25
 
26
26
  describe Tailor::Indentation do
27
27
  include Tailor::Indentation
28
-
28
+
29
29
  context "should return the number of leading spaces in a line" do
30
30
  it "when the line is not indented" do
31
31
  line = create_file_line "def do_something", __LINE__
@@ -45,7 +45,7 @@ describe Tailor::Indentation do
45
45
 
46
46
  context "should know what level of indentation a line is at" do
47
47
  context "for indent expressions" do
48
- INDENT_EXPRESSIONS.each do |regexp|
48
+ Tailor::Indentation::INDENT_EXPRESSIONS.each do |regexp|
49
49
  expression = strip_regex(regexp)
50
50
 
51
51
  it "when the '#{expression }' line is not indented" do
@@ -66,7 +66,7 @@ describe Tailor::Indentation do
66
66
  end
67
67
 
68
68
  context "for outdent expressions" do
69
- OUTDENT_EXPRESSIONS.each do |regexp|
69
+ Tailor::Indentation::OUTDENT_EXPRESSIONS.each do |regexp|
70
70
  expression = strip_regex(regexp)
71
71
 
72
72
  it "when the '#{expression }' line is not indented" do
@@ -87,7 +87,7 @@ describe Tailor::Indentation do
87
87
  end
88
88
 
89
89
  context "for end expressions" do
90
- END_EXPRESSIONS.each do |regexp|
90
+ Tailor::Indentation::END_EXPRESSIONS.each do |regexp|
91
91
  expression = strip_regex(regexp)
92
92
 
93
93
  it "when the '#{expression }' line is not indented" do
@@ -109,7 +109,7 @@ describe Tailor::Indentation do
109
109
  end
110
110
 
111
111
  context "#indent?" do
112
- INDENT_EXPRESSIONS.each do |regexp|
112
+ Tailor::Indentation::INDENT_EXPRESSIONS.each do |regexp|
113
113
  expression = strip_regex(regexp)
114
114
 
115
115
  it "should return true if the line contains #{expression}" do
@@ -120,7 +120,7 @@ describe Tailor::Indentation do
120
120
  end
121
121
 
122
122
  context "#outdent?" do
123
- OUTDENT_EXPRESSIONS.each do |regexp|
123
+ Tailor::Indentation::OUTDENT_EXPRESSIONS.each do |regexp|
124
124
  expression = strip_regex(regexp)
125
125
 
126
126
  it "should return true if the line contains #{expression}" do
@@ -131,7 +131,7 @@ describe Tailor::Indentation do
131
131
  end
132
132
 
133
133
  context "#contains_end?" do
134
- END_EXPRESSIONS.each do |regexp|
134
+ Tailor::Indentation::END_EXPRESSIONS.each do |regexp|
135
135
  expression = strip_regex(regexp)
136
136
 
137
137
  it "should return true if the line contains #{expression}" do
@@ -140,7 +140,7 @@ describe Tailor::Indentation do
140
140
  end
141
141
  end
142
142
  end
143
-
143
+
144
144
  context "#at_improper_level?" do
145
145
  it "should return true if the line is at the wrong level" do
146
146
  proper_level = 1.0
@@ -256,4 +256,4 @@ describe Tailor::Indentation do
256
256
  line.unclosed_parenthesis?.should be_false
257
257
  end
258
258
  end
259
- end
259
+ end