tailor 0.1.3 → 0.1.4

Sign up to get free protection for your applications and to get access to all the features.
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
data/.gemtest ADDED
File without changes
data/.gitignore ADDED
@@ -0,0 +1,7 @@
1
+ .autotest
2
+ .loadpath
3
+ .project
4
+ .yardoc/
5
+ logic.txt
6
+ output.txt
7
+ tmp/
data/.infinity_test ADDED
@@ -0,0 +1,4 @@
1
+ infinity_test do
2
+ use :rubies => %w(1.8.7 1.9.2 1.9.3), :test_framework => :rspec
3
+ notifications :growl
4
+ end
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --colour --format documentation
data/ChangeLog.rdoc ADDED
@@ -0,0 +1,48 @@
1
+ === 0.1.4 2011-09-27
2
+
3
+ * gh-81: Return exit status of 1 if problems were found.
4
+ * Fixed Rakefile and .gemspec. [sergio-fry]
5
+ * Removed dependency on jeweler for gem building.
6
+ * Added -v/--version to bin/tailor.
7
+ * Fixed documenatation indentation.
8
+
9
+ === 0.1.3 2010-12-14
10
+
11
+ * Added check for .erb files.
12
+
13
+ === 0.1.2 2010-09-01
14
+
15
+ * Added ability to check a single file.
16
+
17
+ === 0.1.0 2010-05-21
18
+
19
+ * Added checks for spacing around { and }.
20
+ * Added check for spacing around ternary ':'.
21
+ * Colorized error messages to be red.
22
+ * Problem message are now grouped by file line (when multiple problems per line).
23
+ * Temporarily removed reporting of # of trailing whitespaces.
24
+
25
+ === 0.0.3 2010-04-26
26
+
27
+ * Added checks for spacing around commas.
28
+ * Added checks for spacing around open/closed parenthesis/brackets.
29
+
30
+ === 0.0.2 2010-04-23
31
+
32
+ * Renamed project from ruby_style_checker to Tailor.
33
+ * Added check for lines > 80 characters.
34
+
35
+ === 0.0.1 2010-04-22
36
+
37
+ * Initial release!
38
+ * Command-line executable takes a directory and checks all files, recursively.
39
+ * Checks for:
40
+ * Indentation
41
+ * Hard-tabs in indentation
42
+ * Name cases
43
+ * Snake case class & module names
44
+ * Camel case method names
45
+ * Extra whitespace
46
+ * At the end of lines
47
+ * On empty lines
48
+ * After commas
data/Gemfile ADDED
@@ -0,0 +1,2 @@
1
+ source :rubygems
2
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,107 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ tailor (0.1.4)
5
+ term-ansicolor (>= 1.0.5)
6
+
7
+ GEM
8
+ remote: http://rubygems.org/
9
+ specs:
10
+ Saikuro (1.1.0)
11
+ activesupport (3.1.0)
12
+ multi_json (~> 1.0)
13
+ builder (3.0.0)
14
+ chronic (0.3.0)
15
+ churn (0.0.13)
16
+ chronic (>= 0.2.3)
17
+ hirb
18
+ json_pure
19
+ main
20
+ ruby_parser (~> 2.0.4)
21
+ sexp_processor (~> 3.0.3)
22
+ code_statistics (0.2.13)
23
+ colored (1.2)
24
+ cucumber (1.1.0)
25
+ builder (>= 2.1.2)
26
+ diff-lcs (>= 1.1.2)
27
+ gherkin (~> 2.5.0)
28
+ json (>= 1.4.6)
29
+ term-ansicolor (>= 1.0.6)
30
+ diff-lcs (1.1.3)
31
+ erubis (2.7.0)
32
+ flay (1.4.3)
33
+ ruby_parser (~> 2.0)
34
+ sexp_processor (~> 3.0)
35
+ flog (2.5.3)
36
+ ruby_parser (~> 2.0)
37
+ sexp_processor (~> 3.0)
38
+ gherkin (2.5.1)
39
+ json (>= 1.4.6)
40
+ haml (3.1.3)
41
+ hirb (0.5.0)
42
+ i18n (0.6.0)
43
+ json (1.6.1)
44
+ json_pure (1.6.1)
45
+ main (4.7.1)
46
+ metric_fu (2.1.1)
47
+ Saikuro (>= 1.1.0)
48
+ activesupport (>= 2.0.0)
49
+ chronic (~> 0.3.0)
50
+ churn (>= 0.0.7)
51
+ flay (>= 1.2.1)
52
+ flog (>= 2.3.0)
53
+ rails_best_practices (>= 0.6.4)
54
+ rcov (>= 0.8.3.3)
55
+ reek (>= 1.2.6)
56
+ roodi (>= 2.1.0)
57
+ syntax
58
+ multi_json (1.0.3)
59
+ rails_best_practices (1.0.1)
60
+ activesupport
61
+ colored
62
+ erubis
63
+ haml
64
+ i18n
65
+ ruby-progressbar
66
+ ruby_parser
67
+ rcov (0.9.10)
68
+ reek (1.2.8)
69
+ ruby2ruby (~> 1.2)
70
+ ruby_parser (~> 2.0)
71
+ sexp_processor (~> 3.0)
72
+ roodi (2.1.0)
73
+ ruby_parser
74
+ rspec (2.6.0)
75
+ rspec-core (~> 2.6.0)
76
+ rspec-expectations (~> 2.6.0)
77
+ rspec-mocks (~> 2.6.0)
78
+ rspec-core (2.6.4)
79
+ rspec-expectations (2.6.0)
80
+ diff-lcs (~> 1.1.2)
81
+ rspec-mocks (2.6.0)
82
+ ruby-progressbar (0.0.10)
83
+ ruby2ruby (1.3.1)
84
+ ruby_parser (~> 2.0)
85
+ sexp_processor (~> 3.0)
86
+ ruby_parser (2.0.6)
87
+ sexp_processor (~> 3.0)
88
+ sexp_processor (3.0.7)
89
+ simplecov (0.5.3)
90
+ multi_json (~> 1.0.3)
91
+ simplecov-html (~> 0.5.3)
92
+ simplecov-html (0.5.3)
93
+ syntax (1.0.0)
94
+ term-ansicolor (1.0.6)
95
+ yard (0.7.2)
96
+
97
+ PLATFORMS
98
+ ruby
99
+
100
+ DEPENDENCIES
101
+ code_statistics (~> 0.2.13)
102
+ cucumber (>= 0.10.2)
103
+ metric_fu (>= 2.0.0)
104
+ rspec (>= 2.5.0)
105
+ simplecov (>= 0.4.0)
106
+ tailor!
107
+ yard (>= 0.6.8)
data/README.rdoc CHANGED
@@ -10,7 +10,7 @@ here http://wiki.github.com/turboladen/tailor.
10
10
 
11
11
  == FEATURES/PROBLEMS:
12
12
 
13
- * Checks for bad style in Ruby files
13
+ * Checks for bad style in .rb and .erb files
14
14
  * Recursively in a directory, or...
15
15
  * A given file
16
16
  * Checks for:
@@ -44,7 +44,12 @@ working on solving this.
44
44
 
45
45
  == REQUIREMENTS:
46
46
 
47
- * Ruby 1.8.7 or 1.9.1 (haven't tested on others)
47
+ * Rubies (tested)
48
+ * 1.8.7
49
+ * 1.9.2
50
+ * 1.9.3-preview1
51
+ * Gems
52
+ * term-ansicolor
48
53
 
49
54
  == INSTALL:
50
55
 
@@ -54,7 +59,7 @@ working on solving this.
54
59
 
55
60
  (The MIT License)
56
61
 
57
- Copyright (c) 2010 Steve Loveless
62
+ Copyright (c) 2010-2011 Steve Loveless
58
63
 
59
64
  Permission is hereby granted, free of charge, to any person obtaining
60
65
  a copy of this software and associated documentation files (the
@@ -73,4 +78,4 @@ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
73
78
  IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
74
79
  CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
75
80
  TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
76
- SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
81
+ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/Rakefile CHANGED
@@ -1,81 +1,16 @@
1
- require 'rubygems'
2
- gem 'hoe', '>= 2.1.0'
3
- require 'hoe'
4
- require 'fileutils'
5
- require './lib/tailor'
6
-
7
- # Load rakefile extensions
8
- Dir["#{File.dirname(__FILE__)}/lib/tasks/*.rake"].each { |ext| load ext }
9
-
10
- Hoe.plugin :newgem
11
- Hoe.plugin :yard
12
- # Hoe.plugin :website
13
- Hoe.plugin :cucumberfeatures
14
- Hoe.plugins.delete :rubyforge
15
-
16
- # Gets the description from the main README file
17
- def get_descr_from_readme
18
- paragraph_count = 0
19
- File.readlines('README.rdoc', '').each do |paragraph|
20
- paragraph_count += 1
21
- if paragraph_count == 4
22
- return paragraph
23
- end
24
- end
25
- end
26
-
27
- # Generate all the Rake tasks
28
- # Run 'rake -T' to see list of generated tasks (from gem root directory)
29
- $hoe = Hoe.spec 'tailor' do
30
- self.summary = "Utility for checking style of Ruby files."
31
- self.developer('Steve Loveless', 'steve.loveless@gmail.com')
32
- self.post_install_message = File.readlines 'PostInstall.txt'
33
- self.rubyforge_name = self.name
34
- self.version = Tailor::VERSION
35
- self.url = 'http://github.com/turboladen/tailor'
36
- self.description = get_descr_from_readme
37
- self.readme_file = 'README.rdoc'
38
- self.history_file = 'History.txt'
39
- self.rspec_options += ['--color', '--format', 'specdoc']
40
- self.extra_deps += [
41
- ['term-ansicolor']
42
- ]
43
- self.extra_dev_deps += [
44
- ['rspec'],
45
- ['yard', '>=0.5.3'],
46
- ['hoe-yard', '>=0.1.2'],
47
- ['cucumber', '>=0.6.3']
48
- ]
49
-
50
- self.test_globs = 'spec/*.rb'
51
-
52
- # Extra Yard options
53
- self.yard_title = "#{self.name} Documentation (#{self.version})"
54
- self.yard_markup = :rdoc
55
- self.yard_opts += ['--main', self.readme_file]
56
- self.yard_opts += ['--output-dir', 'doc']
57
- self.yard_opts += ['--private']
58
- self.yard_opts += ['--protected']
59
- self.yard_opts += ['--verbose']
60
- self.yard_opts += ['--files',
61
- ['Manifest.txt', 'History.txt']
62
- ]
63
- end
64
-
65
- #-------------------------------------------------------------------------------
66
- # Overwrite the :clobber_docs Rake task so that it doesn't destroy our docs
67
- # directory.
68
- #-------------------------------------------------------------------------------
69
- class Rake::Task
70
- def overwrite(&block)
71
- @actions.clear
72
- enhance(&block)
73
- end
74
- end
75
-
76
- Rake::Task[:clobber_docs].overwrite do
77
- end
78
-
79
- # Now define the tasks
80
- require 'newgem/tasks'
81
-
1
+ require 'bundler/gem_tasks'
2
+
3
+ # Load rakefile extensions
4
+ Dir["tasks/*.rake"].each { |ext| load ext }
5
+
6
+ require 'cucumber/rake/task'
7
+ Cucumber::Rake::Task.new(:features)
8
+
9
+ require 'yard'
10
+ YARD::Rake::YardocTask.new
11
+
12
+ require 'rspec/core/rake_task'
13
+ RSpec::Core::RakeTask.new
14
+
15
+ desc "Run RSpec code examples"
16
+ task :test => :spec
data/bin/tailor CHANGED
@@ -7,35 +7,66 @@ $:.unshift(File.dirname(__FILE__) + '/../lib/') unless
7
7
  require 'tailor'
8
8
 
9
9
  def usage
10
- puts "Usage:"
11
- puts "\t#{__FILE__} [directory with .rb files]"
12
- puts "\t -OR-"
13
- puts "\t#{__FILE__} [single .rb file]"
10
+ <<USEAGE
11
+ Usage:
12
+ $ #{File.basename(__FILE__)} [directory with .rb files]"
13
+ -OR-
14
+ $ #{File.basename(__FILE__)} [single .rb file]"
15
+
16
+ USEAGE
17
+ end
18
+
19
+ def version
20
+ <<VERSION
21
+ tailor (v#{Tailor::VERSION})
22
+ A Ruby style checker by @turboladen.
23
+ http://github.com/turboladen/tailor
24
+ VERSION
25
+
14
26
  end
15
27
 
16
28
  if ARGV[0].nil?
29
+ puts version
30
+ puts
17
31
  puts usage
32
+ elsif ARGV[0] =~ /^--version|-v$/
33
+ puts <<-VERSION
34
+ #{version}
35
+ _________________________________________________________________________
36
+ | | | | | | | | | | | | | | | | | | | | | | | | |
37
+ | | | | | | | | | | | | |
38
+ | | | | | | |
39
+ | 1 2 3 4 5 |
40
+ | |
41
+ -------------------------------------------------------------------------
42
+
43
+ VERSION
44
+
18
45
  else
19
46
  begin
20
47
  path_to_check = ARGV[0]
21
-
48
+
22
49
  # Check to make sure we got a file or directory
23
50
  unless File.file?(path_to_check) or File.directory?(path_to_check)
24
51
  raise "Invalid file or directory: #{path_to_check}"
25
52
  end
26
53
 
27
- if File.file?(path_to_check)
28
- files_and_problems = Tailor.check_file path_to_check
54
+ files_and_problems = if File.file?(path_to_check)
55
+ Tailor.check_file path_to_check
29
56
  elsif File.directory?(path_to_check)
30
57
  # Check the requested files/dirs for problems
31
- files_and_problems = Tailor.check path_to_check
58
+ Tailor.check path_to_check
32
59
  end
33
60
 
61
+ problem_count = files_and_problems.values.inject(:+)
62
+
34
63
  # Print summary of the problems we found
35
64
  Tailor.print_report files_and_problems
36
- rescue Exception => ex
65
+ rescue RuntimeError => ex
37
66
  puts ex.message
38
67
  puts ex.backtrace
39
68
  puts
69
+ ensure
70
+ exit(1) if problem_count > 0
40
71
  end
41
- end
72
+ end
@@ -153,4 +153,4 @@ end
153
153
  Then /^the checker should tell me each line has closed brackets with spaces before them$/ do
154
154
  message = "Line has a closed bracket with spaces before it"
155
155
  @result.should include(message)
156
- end
156
+ end
@@ -53,7 +53,7 @@ thing ={:one => 1}
53
53
  thing = { :one => 1 }
54
54
 
55
55
  # Skip on default params in methods...
56
- def a_method; one={}; end;
56
+ def a_method; one={}; end
57
57
 
58
58
  # Skip on strings...
59
59
  a_string = "This is a #{thing}..."
@@ -30,7 +30,7 @@ thing [0]
30
30
  # 1 space before ] with element reference
31
31
  thing[0 ]
32
32
 
33
- # Pefect multi-line
33
+ # Perfect multi-line
34
34
  two = 'too'
35
35
  thing = [
36
36
  one,
@@ -45,7 +45,7 @@ module MyModule
45
45
  end
46
46
 
47
47
  # Now how about a block...
48
- 1..10.each do |number|
48
+ 1..10.times do |number|
49
49
  begin
50
50
  rescue
51
51
  ensure
@@ -4,7 +4,7 @@ require "tailor"
4
4
  gem 'cucumber'
5
5
  require 'cucumber'
6
6
  gem 'rspec'
7
- require 'spec'
7
+ require 'rspec'
8
8
 
9
9
  Before do
10
10
  @tmp_root = File.dirname(__FILE__) + "/../../tmp"
data/lib/tailor.rb CHANGED
@@ -4,11 +4,11 @@ $:.unshift(File.dirname(__FILE__)) unless
4
4
 
5
5
  require 'fileutils'
6
6
  require 'pathname'
7
+ require 'tailor/version'
7
8
  require 'tailor/file_line'
8
9
  require 'tailor/spacing'
9
10
 
10
11
  module Tailor
11
- VERSION = '0.1.3'
12
12
 
13
13
  # These operators should always have 1 space around them
14
14
  OPERATORS = {
@@ -23,7 +23,7 @@ module Tailor
23
23
  :ternary => ['?', ':']
24
24
  }
25
25
 
26
- # These operators should never have spaces around them
26
+ # These operators should never have spaces around them.
27
27
  NO_SPACE_AROUND_OPERATORS = {
28
28
  :range => ['..', '...'],
29
29
  :scope_resolution => ['::']
@@ -73,8 +73,8 @@ module Tailor
73
73
  # path in order to alleviate any possible confusion.
74
74
  #
75
75
  # @param [String] base_dir Directory to start recursing from to look for .rb
76
- # files
77
- # @return [Array] Sorted list of absolute file paths in the project
76
+ # files.
77
+ # @return [Array] Sorted list of absolute file paths in the project.
78
78
  def self.project_file_list base_dir
79
79
  if File.directory? base_dir
80
80
  FileUtils.cd base_dir
@@ -104,7 +104,7 @@ module Tailor
104
104
  source = File.open(file_name, 'r')
105
105
  file_path = Pathname.new(file_name)
106
106
 
107
- puts
107
+ puts ""
108
108
  puts "#-------------------------------------------------------------------"
109
109
  puts "# Looking for bad style in:"
110
110
  puts "# \t'#{file_path}'"
@@ -193,7 +193,7 @@ end
193
193
 
194
194
  # If this is the last line of the multi-line statement...
195
195
  if multi_line == true and multi_line_statement
196
- puts "Assinging current (#{current_level}) to multi_next (#{multi_line_next_level})"
196
+ puts "Assigning current (#{current_level}) to multi_next (#{multi_line_next_level})"
197
197
  current_level = multi_line_next_level
198
198
  elsif multi_line == true and !multi_line_statement
199
199
  multi_line = false
@@ -232,13 +232,12 @@ end
232
232
  @problem_count
233
233
  end
234
234
 
235
- ##
236
235
  # Prints a summary report that shows which files had how many problems.
237
236
  #
238
237
  # @param [Hash] files_and_problems Returns a hash that contains
239
238
  # file_name => problem_count.
240
239
  def self.print_report files_and_problems
241
- puts
240
+ puts ""
242
241
  puts "The following files are out of style:"
243
242
 
244
243
  files_and_problems.each_pair do |file, problem_count|