tailor 0.0.3 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (44) hide show
  1. data/History.txt +8 -0
  2. data/Manifest.txt +22 -2
  3. data/PostInstall.txt +4 -0
  4. data/README.rdoc +7 -6
  5. data/Rakefile +7 -1
  6. data/bin/tailor +21 -5
  7. data/features/indentation.feature +22 -0
  8. data/features/spacing.feature +13 -18
  9. data/features/spacing/commas.feature +44 -0
  10. data/features/step_definitions/indentation_steps.rb +139 -0
  11. data/features/step_definitions/spacing/commas_steps.rb +14 -0
  12. data/features/step_definitions/spacing_steps.rb +1 -36
  13. data/features/support/1_file_with_bad_comma_spacing/bad_comma_spacing.rb +43 -5
  14. data/features/support/1_file_with_bad_curly_brace_spacing/bad_curly_brace_spacing.rb +60 -0
  15. data/features/support/1_file_with_bad_operator_spacing/bad_op_spacing.rb +31 -0
  16. data/features/support/1_file_with_bad_parenthesis/bad_parenthesis.rb +1 -3
  17. data/features/support/1_file_with_bad_square_brackets/bad_square_brackets.rb +62 -0
  18. data/features/support/1_file_with_bad_ternary_colon_spacing/bad_ternary_colon_spacing.rb +31 -0
  19. data/features/support/1_good_simple_file/simple_project.rb +5 -0
  20. data/features/support/1_long_file_with_indentation/my_project.rb +56 -0
  21. data/features/support/common.rb +74 -1
  22. data/features/support/env.rb +3 -1
  23. data/features/support/world.rb +0 -52
  24. data/lib/tailor.rb +132 -41
  25. data/lib/tailor/file_line.rb +66 -177
  26. data/lib/tailor/indentation.rb +251 -0
  27. data/lib/tailor/spacing.rb +243 -0
  28. data/lib/tasks/metrics.rake +23 -0
  29. data/lib/tasks/stats.rake +11 -0
  30. data/logic.txt +30 -0
  31. data/ruby-style-checker.rb +77 -46
  32. data/spec/file_line_spec.rb +18 -193
  33. data/spec/indentation_spec.rb +259 -0
  34. data/spec/spacing/colon_spacing_spec.rb +71 -0
  35. data/spec/spacing/comma_spacing_spec.rb +159 -0
  36. data/spec/spacing/curly_brace_spacing_spec.rb +258 -0
  37. data/spec/spacing/parentheses_spacing_spec.rb +28 -0
  38. data/spec/spacing/square_bracket_spacing_spec.rb +116 -0
  39. data/spec/spacing_spec.rb +167 -0
  40. data/spec/spec_helper.rb +4 -0
  41. data/spec/tailor_spec.rb +2 -2
  42. metadata +73 -38
  43. data/features/support/1_good_simple_file/my_project.rb +0 -7
  44. data/lib/tailor/indentation_checker.rb +0 -27
@@ -1,3 +1,11 @@
1
+ === 0.1.0 2010-05-21
2
+
3
+ * Added checks for spacing around { and }
4
+ * Added check for spacing around ternary ':'
5
+ * Colorized error messages to be red
6
+ * Problem message are now grouped by file line (when multiple problems per line)
7
+ * Temporarily removed reporting of # of trailing whitespaces
8
+
1
9
  === 0.0.3 2010-04-26
2
10
 
3
11
  * Added checks for spacing around commas
@@ -7,12 +7,20 @@ Rakefile
7
7
  bin/tailor
8
8
  features/case_checking.feature
9
9
  features/development.feature
10
+ features/indentation.feature
10
11
  features/spacing.feature
12
+ features/spacing/commas.feature
11
13
  features/step_definitions/case_checking_steps.rb
12
14
  features/step_definitions/common_steps.rb
15
+ features/step_definitions/indentation_steps.rb
16
+ features/step_definitions/spacing/commas_steps.rb
13
17
  features/step_definitions/spacing_steps.rb
14
18
  features/support/1_file_with_bad_comma_spacing/bad_comma_spacing.rb
19
+ features/support/1_file_with_bad_curly_brace_spacing/bad_curly_brace_spacing.rb
20
+ features/support/1_file_with_bad_operator_spacing/bad_op_spacing.rb
15
21
  features/support/1_file_with_bad_parenthesis/bad_parenthesis.rb
22
+ features/support/1_file_with_bad_square_brackets/bad_square_brackets.rb
23
+ features/support/1_file_with_bad_ternary_colon_spacing/bad_ternary_colon_spacing.rb
16
24
  features/support/1_file_with_camel_case_class/camel_case_class.rb
17
25
  features/support/1_file_with_camel_case_method/camel_case_method.rb
18
26
  features/support/1_file_with_hard_tabs/hard_tab.rb
@@ -20,19 +28,31 @@ features/support/1_file_with_long_lines/long_lines.rb
20
28
  features/support/1_file_with_snake_case_class/snake_case_class.rb
21
29
  features/support/1_file_with_snake_case_method/snake_case_method.rb
22
30
  features/support/1_file_with_trailing_whitespace/trailing_whitespace.rb
23
- features/support/1_good_simple_file/my_project.rb
31
+ features/support/1_good_simple_file/simple_project.rb
32
+ features/support/1_long_file_with_indentation/my_project.rb
24
33
  features/support/common.rb
25
34
  features/support/env.rb
26
35
  features/support/matchers.rb
27
36
  features/support/world.rb
28
37
  lib/tailor.rb
29
38
  lib/tailor/file_line.rb
30
- lib/tailor/indentation_checker.rb
39
+ lib/tailor/indentation.rb
40
+ lib/tailor/spacing.rb
41
+ lib/tasks/metrics.rake
42
+ lib/tasks/stats.rake
43
+ logic.txt
31
44
  ruby-style-checker.rb
32
45
  script/console
33
46
  script/destroy
34
47
  script/generate
35
48
  spec/file_line_spec.rb
49
+ spec/indentation_spec.rb
50
+ spec/spacing/colon_spacing_spec.rb
51
+ spec/spacing/comma_spacing_spec.rb
52
+ spec/spacing/curly_brace_spacing_spec.rb
53
+ spec/spacing/parentheses_spacing_spec.rb
54
+ spec/spacing/square_bracket_spacing_spec.rb
55
+ spec/spacing_spec.rb
36
56
  spec/spec.opts
37
57
  spec/spec_helper.rb
38
58
  spec/tailor_spec.rb
@@ -1,2 +1,6 @@
1
1
 
2
+ Thanks for checking out Tailor. To run, simply do:
3
+ # tailor [directory to check]
4
+
5
+
2
6
  For more information on tailor, see http://github.com/turboladen/tailor
@@ -4,9 +4,8 @@
4
4
 
5
5
  == DESCRIPTION:
6
6
 
7
- tailor is an executable that recursively parses Ruby files in a
8
- directory and checks them for bad style. Rules for judging style are based on
9
- a number of style guides that are popular in the Ruby community. More on this
7
+ tailor recursively parses Ruby files in a directory and checks them for bad
8
+ style. Rules for judging style are based on a number of style guides that are popular in the Ruby community. More on this
10
9
  here http://wiki.github.com/turboladen/tailor.
11
10
 
12
11
  == FEATURES/PROBLEMS:
@@ -21,9 +20,11 @@ here http://wiki.github.com/turboladen/tailor.
21
20
  * Extra whitespace
22
21
  * At the end of lines
23
22
  * On empty lines
24
- * Before & after commas
25
- * Before & after open/closed parentheses
26
- * Before & after open/closed square brackets
23
+ * Around commas
24
+ * Around open/closed parentheses
25
+ * Around open/closed square brackets
26
+ * Around open/closed curly braces
27
+ * Around colons in ternary statements
27
28
  * Line length
28
29
  * Should be <= 80 characters
29
30
 
data/Rakefile CHANGED
@@ -4,10 +4,14 @@ require 'hoe'
4
4
  require 'fileutils'
5
5
  require './lib/tailor'
6
6
 
7
+ # Load nsm5200 rakefile extensions
8
+ Dir["#{File.dirname(__FILE__)}/lib/tasks/*.rake"].each { |ext| load ext }
9
+
7
10
  Hoe.plugin :newgem
8
11
  Hoe.plugin :yard
9
12
  # Hoe.plugin :website
10
- # Hoe.plugin :cucumberfeatures
13
+ Hoe.plugin :cucumberfeatures
14
+ Hoe.plugins.delete :rubyforge
11
15
 
12
16
  # Gets the description from the main README file
13
17
  def get_descr_from_readme
@@ -76,3 +80,5 @@ Dir['tasks/**/*.rake'].each { |t| load t }
76
80
  # TODO - want other tests/tasks run by default? Add them to the list
77
81
  # remove_task :default
78
82
  # task :default => [:spec, :features]
83
+
84
+
data/bin/tailor CHANGED
@@ -1,6 +1,8 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
- $:.unshift File.expand_path(File.dirname(__FILE__) + '/../lib/')
3
+ $:.unshift(File.dirname(__FILE__) + '/../lib/') unless
4
+ $:.include?(File.dirname(__FILE__) + '/../lib/') ||
5
+ $:.include?(File.expand_path(File.dirname(__FILE__) + '/../lib/'))
4
6
 
5
7
  require 'tailor'
6
8
 
@@ -11,8 +13,22 @@ end
11
13
  if ARGV[0].nil?
12
14
  puts usage
13
15
  else
14
- path_to_check = ARGV[0]
15
- files_and_problems = Tailor.check path_to_check
16
- Tailor.print_report files_and_problems
17
- end
16
+ begin
17
+ path_to_check = ARGV[0]
18
+
19
+ # Check to make sure we got a file or directory
20
+ unless File.file?(path_to_check) or File.directory?(path_to_check)
21
+ raise "Invalid file or directory: #{path_to_check}"
22
+ end
23
+
24
+ # Check the requested files/dirs for problems
25
+ files_and_problems = Tailor.check path_to_check
18
26
 
27
+ # Print summary of the problems we found
28
+ Tailor.print_report files_and_problems
29
+ rescue Exception => ex
30
+ puts ex.message
31
+ puts ex.backtrace
32
+ puts
33
+ end
34
+ end
@@ -0,0 +1,22 @@
1
+ Feature: Indentation
2
+
3
+ Scenario: A single file project with every in/outdent expression, indented properly
4
+ Given I have a project directory "1_long_file_with_indentation"
5
+ And I have 1 file in my project
6
+ And that file is indented properly
7
+ When I run the checker on the project
8
+ Then the checker should tell me my indentation is OK
9
+
10
+ Scenario: A single file that's indented properly
11
+ Given I have a project directory "1_good_simple_file"
12
+ And I have 1 file in my project
13
+ And the indentation of that file starts at level 0
14
+ And the line 1 is a "class" statement
15
+ And the line 2 is a "def" statement
16
+ When I run the checker on the project
17
+ Then the level of line 1 should be 0.0
18
+ And the level of line 2 should be 1.0
19
+ And the level of line 3 should be 2.0
20
+ And the level of line 4 should be 1.0
21
+ And the level of line 5 should be 0.0
22
+
@@ -6,15 +6,6 @@ Feature: Spacing
6
6
  which lines those problems occur on,
7
7
  and what type of spacing they're missing
8
8
 
9
- Scenario: A single class-less file in a project; 1 method, indented properly
10
- Given I have a project directory "1_good_simple_file"
11
- And I have "1" file in my project
12
- And that file does not contain any "class" statements
13
- And the file contains only "1" "def" statement
14
- And that file is indented properly
15
- When I run the checker on the project
16
- Then the checker should tell me my indentation is OK
17
-
18
9
  Scenario: A single class-less file with hard tabs
19
10
  Given I have a project directory "1_file_with_hard_tabs"
20
11
  And I have "1" file in my project
@@ -26,21 +17,21 @@ Feature: Spacing
26
17
 
27
18
  Scenario: A single file that has all lines with trailing whitespace
28
19
  Given I have a project directory "1_file_with_trailing_whitespace"
29
- And I have "1" file in my project
20
+ And I have 1 file in my project
30
21
  And that file contains lines with trailing whitespace
31
22
  When I run the checker on the project
32
23
  Then the checker should tell me each line has trailing whitespace
33
24
 
34
25
  Scenario: A single file that has a comment and a code line 90 characters long
35
26
  Given I have a project directory "1_file_with_long_lines"
36
- And I have "1" file in my project
27
+ And I have 1 file in my project
37
28
  And that file contains lines longer than 80 characters
38
29
  When I run the checker on the project
39
30
  Then the checker should tell me each line is too long
40
31
 
41
32
  Scenario: A single file that has a comment, method name, and statement without spaces after the commas
42
33
  Given I have a project directory "1_file_with_bad_comma_spacing"
43
- And I have "1" file in my project
34
+ And I have 1 file in my project
44
35
  And that file contains a "comment" line without spaces after commas
45
36
  And that file contains a "method" line without spaces after commas
46
37
  And that file contains a "statement" line without spaces after commas
@@ -49,7 +40,7 @@ Feature: Spacing
49
40
 
50
41
  Scenario: A single file that has a comment, method name, and statement with > 1 spaces after the commas
51
42
  Given I have a project directory "1_file_with_bad_comma_spacing"
52
- And I have "1" file in my project
43
+ And I have 1 file in my project
53
44
  And that file contains a "comment" line with > 1 spaces after commas
54
45
  And that file contains a "method" line with > 1 spaces after commas
55
46
  And that file contains a "statement" line with > 1 spaces after commas
@@ -58,7 +49,7 @@ Feature: Spacing
58
49
 
59
50
  Scenario: A single file that has a comment, method name, and statement with spaces before the commas
60
51
  Given I have a project directory "1_file_with_bad_comma_spacing"
61
- And I have "1" file in my project
52
+ And I have 1 file in my project
62
53
  And that file contains a "comment" line with spaces before commas
63
54
  And that file contains a "method" line with spaces before commas
64
55
  And that file contains a "statement" line with spaces before commas
@@ -67,7 +58,7 @@ Feature: Spacing
67
58
 
68
59
  Scenario: A single file that has a comment, method, and statement with spaces after open parentheses
69
60
  Given I have a project directory "1_file_with_bad_parenthesis"
70
- And I have "1" file in my project
61
+ And I have 1 file in my project
71
62
  And that file contains a "comment" line with spaces after an open parenthesis
72
63
  And that file contains a "method" line with spaces after an open parenthesis
73
64
  And that file contains a "statement" line with spaces after an open parenthesis
@@ -76,7 +67,7 @@ Feature: Spacing
76
67
 
77
68
  Scenario: A single file that has a comment, method, and statement with spaces after open brackets
78
69
  Given I have a project directory "1_file_with_bad_parenthesis"
79
- And I have "1" file in my project
70
+ And I have 1 file in my project
80
71
  And that file contains a "comment" line with spaces after an open bracket
81
72
  And that file contains a "method" line with spaces after an open bracket
82
73
  And that file contains a "statement" line with spaces after an open bracket
@@ -85,7 +76,7 @@ Feature: Spacing
85
76
 
86
77
  Scenario: A single file that has a comment, method, and statement with spaces before closed parentheses
87
78
  Given I have a project directory "1_file_with_bad_parenthesis"
88
- And I have "1" file in my project
79
+ And I have 1 file in my project
89
80
  And that file contains a "comment" line with spaces after an open parenthesis
90
81
  And that file contains a "method" line with spaces after an open parenthesis
91
82
  And that file contains a "statement" line with spaces after an open parenthesis
@@ -94,9 +85,13 @@ Feature: Spacing
94
85
 
95
86
  Scenario: A single file that has a comment, method, and statement with spaces before closed brackets
96
87
  Given I have a project directory "1_file_with_bad_parenthesis"
97
- And I have "1" file in my project
88
+ And I have 1 file in my project
98
89
  And that file contains a "comment" line with spaces after an open bracket
99
90
  And that file contains a "method" line with spaces after an open bracket
100
91
  And that file contains a "statement" line with spaces after an open bracket
101
92
  When I run the checker on the project
102
93
  Then the checker should tell me each line has closed brackets with spaces before them
94
+
95
+ Scenario: A single file that has a comment, method, and statement with each operator
96
+ Given I have a project directory "1_file_with_bad_operator_spacing"
97
+ And I have 1 file in my project
@@ -0,0 +1,44 @@
1
+ Feature: Detect bad spacing around commas
2
+ As a Ruby developer
3
+ I want to detect bad spacing around commas in my code
4
+ So that it's easy to read and maintain
5
+
6
+ Scenario: More than 1 space after a comma
7
+ Given a file with 1 space after a comma in a:
8
+ | Type |
9
+ | comment |
10
+ | method |
11
+ | Array |
12
+ | Hash |
13
+
14
+ Scenario: 0 spaces after a comma
15
+ Given a file with 0 spaces after a comma in a:
16
+ | Type |
17
+ | comment |
18
+ | method |
19
+ | Array |
20
+ | Hash |
21
+
22
+ Scenario: 1 space after a comma
23
+ Given a file with 1 space after a comma in a:
24
+ | Type |
25
+ | comment |
26
+ | method |
27
+ | Array |
28
+ | Hash |
29
+
30
+ Scenario: More than 0 spaces before a comma
31
+ Given a file with more than 0 spaces before a comma in a:
32
+ | Type |
33
+ | comment |
34
+ | method |
35
+ | Array |
36
+ | Hash |
37
+
38
+ Scenario: 0 spaces before a comma
39
+ Given a file with 0 spaces before a comma in a:
40
+ | Type |
41
+ | comment |
42
+ | method |
43
+ | Array |
44
+ | Hash |
@@ -0,0 +1,139 @@
1
+ require 'tailor/indentation'
2
+ require 'tailor/file_line'
3
+
4
+ Given /^that file is indented properly$/ do
5
+ pending
6
+ current_line = 1
7
+
8
+ file_path = Pathname.new(File.expand_path(@file_list[0]))
9
+
10
+ current_level = 0.0
11
+ problem_count = 0
12
+ next_proper_level = 0.0
13
+
14
+ check_file do |line|
15
+ line = Tailor::FileLine.new(line, file_path, current_line)
16
+
17
+ puts '----'
18
+ puts "line = #{current_line}"
19
+ puts "current = #{current_level}"
20
+ actual_level = line.is_at_level
21
+ puts "actual = #{actual_level}"
22
+ should_be_at = line.should_be_at_level(current_level)
23
+ puts "should = #{should_be_at}"
24
+
25
+ problem_count += 1 if line.at_proper_level?(actual_level, should_be_at)
26
+ next_proper_level = line.next_line_should_be_at_level current_level
27
+ puts "next proper = #{next_proper_level}"
28
+ current_level = next_proper_level
29
+
30
+ current_line += 1
31
+ end
32
+ end
33
+
34
+ Given /^the indentation of that file starts at level (\d*)$/ do |level|
35
+ current_line = 1
36
+ result = nil
37
+
38
+ file_path = Pathname.new(File.expand_path(@file_list[0]))
39
+
40
+ check_file do |line|
41
+ line = FileLine.new(line, file_path, current_line)
42
+ result = line.is_at_level
43
+ break line
44
+ end
45
+
46
+ result.should == 0
47
+ end
48
+
49
+ Given /^the line (\d*) is a "([^\"]*)" statement$/ do |line_num, statement_type|
50
+ current_line = 1
51
+ result = nil
52
+
53
+ check_file do |line|
54
+ result = line.strip =~ /^#{statement_type}/
55
+ current_line == line_num.to_i ? (break line) : current_line += 1
56
+ end
57
+ result.should_not be_nil
58
+ end
59
+
60
+ Then "the checker should tell me my indentation is OK" do
61
+ pending
62
+ end
63
+
64
+ =begin
65
+ Then /^the level of line 1 should be 0.0$/ do
66
+ file_path = Pathname.new(File.expand_path(@file_list[0]))
67
+ @current_level = nil
68
+
69
+ check_file do |line|
70
+ line = FileLine.new(line, file_path, 1)
71
+
72
+ @current_level = line.is_at_level
73
+ @level_change = @current_level + line.next_line_level_change
74
+ break line
75
+ end
76
+ @current_level.should.eql? 0.0
77
+ end
78
+ =end
79
+
80
+
81
+ Then /^the level of line (\d*) should be (\d+\.\d+)$/ do |line_num_to_check, level_to_check|
82
+ file_path = Pathname.new(File.expand_path(@file_list[0]))
83
+ current_line_num = 1
84
+ next_proper_level = 0.0
85
+ current_proper_level = 0.0
86
+
87
+ check_file do |line|
88
+ line = FileLine.new(line, file_path, current_line_num)
89
+
90
+ if current_line_num == line_num_to_check
91
+ line.is_at_level.should == level_to_check.to_f
92
+
93
+ # Determine what the next line's level should be at, based on the current line's
94
+ # level.
95
+ next_proper_level = current_proper_level + line.indent_next_line_by
96
+ end
97
+
98
+ current_line_num += 1
99
+ end
100
+ end
101
+
102
+ =begin
103
+ Then /^the level of line (\d*) should be (\d+\.\d+)$/ do |line_num_to_check, level_to_check|
104
+ file_path = Pathname.new(File.expand_path(@file_list[0]))
105
+ current_line = 1
106
+ actual_level = nil
107
+ current_level = 0.0 # new
108
+ level_change = nil # new
109
+
110
+ check_file do |line|
111
+ line = FileLine.new(line, file_path, current_line)
112
+
113
+ # If the first line of the file,
114
+ if current_line == 1 # new
115
+ level_change = current_level + line.next_line_level_change #new
116
+ break line #new
117
+ else # new
118
+ actual_level = line.is_at_level
119
+ end # new
120
+
121
+ # Only check the line specified; skip if it's the first line.
122
+ if (current_line == line_num_to_check) and (line_num_to_check > 1)
123
+ this_level = current_level + level_change # new
124
+ this_level < 0.0 ? (this_level = 0.0) : this_level # new
125
+ this_level.should == level_to_check # new
126
+ actual_level.should == this_level
127
+ level_change = line.next_line_level_change
128
+ break line
129
+ else
130
+ current_line += 1
131
+ end
132
+ end
133
+ if current_line == 1
134
+ current_level.should.eql? level_to_check
135
+ else
136
+ current_level += level_change #new
137
+ end
138
+ end
139
+ =end