tailor 0.1.5 → 1.0.0.alpha

Sign up to get free protection for your applications and to get access to all the features.
Files changed (124) hide show
  1. data/.gitignore +9 -1
  2. data/.rspec +2 -1
  3. data/.tailor +6 -0
  4. data/Gemfile.lock +47 -78
  5. data/{ChangeLog.rdoc → History.rdoc} +0 -0
  6. data/README.rdoc +157 -24
  7. data/Rakefile +0 -9
  8. data/bin/tailor +16 -69
  9. data/features/configurable.feature +78 -0
  10. data/features/horizontal_spacing.feature +262 -0
  11. data/features/indentation.feature +17 -21
  12. data/features/indentation/bad_files_with_no_trailing_newline.feature +90 -0
  13. data/features/indentation/good_files_with_no_trailing_newline.feature +206 -0
  14. data/features/name_detection.feature +72 -0
  15. data/features/step_definitions/indentation_steps.rb +10 -133
  16. data/features/support/env.rb +7 -15
  17. data/features/support/file_cases/horizontal_spacing_cases.rb +265 -0
  18. data/features/support/file_cases/indentation_cases.rb +972 -0
  19. data/features/support/file_cases/naming_cases.rb +52 -0
  20. data/features/support/file_cases/vertical_spacing_cases.rb +70 -0
  21. data/features/support/hooks.rb +8 -0
  22. data/features/support/{1_file_with_bad_operator_spacing → legacy}/bad_op_spacing.rb +0 -0
  23. data/features/support/{1_file_with_bad_ternary_colon_spacing → legacy}/bad_ternary_colon_spacing.rb +0 -0
  24. data/features/support/{1_long_file_with_indentation/my_project.rb → legacy/long_file_with_indentation.rb} +1 -1
  25. data/features/support/world.rb +14 -0
  26. data/features/vertical_spacing.feature +114 -0
  27. data/lib/ext/string_ext.rb +5 -0
  28. data/lib/tailor.rb +6 -252
  29. data/lib/tailor/cli.rb +49 -0
  30. data/lib/tailor/cli/options.rb +251 -0
  31. data/lib/tailor/composite_observable.rb +56 -0
  32. data/lib/tailor/configuration.rb +263 -0
  33. data/lib/tailor/critic.rb +162 -0
  34. data/lib/tailor/formatters/text.rb +126 -0
  35. data/lib/tailor/lexed_line.rb +246 -0
  36. data/lib/tailor/lexer.rb +428 -0
  37. data/lib/tailor/lexer/token.rb +103 -0
  38. data/lib/tailor/lexer_constants.rb +75 -0
  39. data/lib/tailor/logger.rb +28 -0
  40. data/lib/tailor/problem.rb +100 -0
  41. data/lib/tailor/reporter.rb +48 -0
  42. data/lib/tailor/ruler.rb +39 -0
  43. data/lib/tailor/rulers.rb +7 -0
  44. data/lib/tailor/rulers/allow_camel_case_methods_ruler.rb +30 -0
  45. data/lib/tailor/rulers/allow_hard_tabs_ruler.rb +22 -0
  46. data/lib/tailor/rulers/allow_screaming_snake_case_classes_ruler.rb +32 -0
  47. data/lib/tailor/rulers/allow_trailing_line_spaces_ruler.rb +33 -0
  48. data/lib/tailor/rulers/indentation_spaces_ruler.rb +199 -0
  49. data/lib/tailor/rulers/indentation_spaces_ruler/indentation_manager.rb +362 -0
  50. data/lib/tailor/rulers/max_code_lines_in_class_ruler.rb +84 -0
  51. data/lib/tailor/rulers/max_code_lines_in_method_ruler.rb +84 -0
  52. data/lib/tailor/rulers/max_line_length_ruler.rb +31 -0
  53. data/lib/tailor/rulers/spaces_after_comma_ruler.rb +83 -0
  54. data/lib/tailor/rulers/spaces_after_lbrace_ruler.rb +114 -0
  55. data/lib/tailor/rulers/spaces_after_lbracket_ruler.rb +123 -0
  56. data/lib/tailor/rulers/spaces_after_lparen_ruler.rb +116 -0
  57. data/lib/tailor/rulers/spaces_before_comma_ruler.rb +67 -0
  58. data/lib/tailor/rulers/spaces_before_lbrace_ruler.rb +93 -0
  59. data/lib/tailor/rulers/spaces_before_rbrace_ruler.rb +98 -0
  60. data/lib/tailor/rulers/spaces_before_rbracket_ruler.rb +70 -0
  61. data/lib/tailor/rulers/spaces_before_rparen_ruler.rb +70 -0
  62. data/lib/tailor/rulers/spaces_in_empty_braces_ruler.rb +94 -0
  63. data/lib/tailor/rulers/trailing_newlines_ruler.rb +36 -0
  64. data/lib/tailor/runtime_error.rb +3 -0
  65. data/lib/tailor/tailorrc.erb +88 -0
  66. data/lib/tailor/version.rb +2 -2
  67. data/spec/spec_helper.rb +7 -5
  68. data/spec/tailor/cli_spec.rb +94 -0
  69. data/spec/tailor/configuration_spec.rb +147 -0
  70. data/spec/tailor/critic_spec.rb +63 -0
  71. data/spec/tailor/lexed_line_spec.rb +569 -0
  72. data/spec/tailor/lexer/token_spec.rb +46 -0
  73. data/spec/tailor/lexer_spec.rb +181 -0
  74. data/spec/tailor/options_spec.rb +6 -0
  75. data/spec/tailor/problem_spec.rb +74 -0
  76. data/spec/tailor/reporter_spec.rb +53 -0
  77. data/spec/tailor/ruler_spec.rb +56 -0
  78. data/spec/tailor/rulers/indentation_spaces_ruler/indentation_manager_spec.rb +454 -0
  79. data/spec/tailor/rulers/indentation_spaces_ruler_spec.rb +128 -0
  80. data/spec/tailor/rulers/spaces_after_comma_spec.rb +31 -0
  81. data/spec/tailor/rulers/spaces_after_lbrace_ruler_spec.rb +145 -0
  82. data/spec/tailor/rulers/spaces_before_lbrace_ruler_spec.rb +63 -0
  83. data/spec/tailor/rulers/spaces_before_rbrace_ruler_spec.rb +63 -0
  84. data/spec/tailor/rulers_spec.rb +9 -0
  85. data/spec/tailor/version_spec.rb +6 -0
  86. data/spec/tailor_spec.rb +9 -21
  87. data/tailor.gemspec +22 -35
  88. data/tasks/features.rake +7 -0
  89. data/tasks/roodi.rake +9 -0
  90. data/tasks/roodi_config.yaml +14 -0
  91. data/tasks/spec.rake +16 -0
  92. data/tasks/yard.rake +14 -0
  93. metadata +224 -77
  94. data/features/case_checking.feature +0 -38
  95. data/features/spacing.feature +0 -97
  96. data/features/spacing/commas.feature +0 -44
  97. data/features/step_definitions/case_checking_steps.rb +0 -42
  98. data/features/step_definitions/spacing_steps.rb +0 -156
  99. data/features/support/1_file_with_bad_comma_spacing/bad_comma_spacing.rb +0 -43
  100. data/features/support/1_file_with_bad_curly_brace_spacing/bad_curly_brace_spacing.rb +0 -60
  101. data/features/support/1_file_with_bad_parenthesis/bad_parenthesis.rb +0 -4
  102. data/features/support/1_file_with_bad_square_brackets/bad_square_brackets.rb +0 -62
  103. data/features/support/1_file_with_camel_case_class/camel_case_class.rb +0 -5
  104. data/features/support/1_file_with_camel_case_method/camel_case_method.rb +0 -3
  105. data/features/support/1_file_with_hard_tabs/hard_tab.rb +0 -3
  106. data/features/support/1_file_with_long_lines/long_lines.rb +0 -5
  107. data/features/support/1_file_with_snake_case_class/snake_case_class.rb +0 -5
  108. data/features/support/1_file_with_snake_case_method/snake_case_method.rb +0 -3
  109. data/features/support/1_file_with_trailing_whitespace/trailing_whitespace.rb +0 -5
  110. data/features/support/1_good_simple_file/simple_project.rb +0 -5
  111. data/features/support/common.rb +0 -102
  112. data/features/support/matchers.rb +0 -11
  113. data/lib/tailor/file_line.rb +0 -220
  114. data/lib/tailor/indentation.rb +0 -245
  115. data/lib/tailor/spacing.rb +0 -237
  116. data/spec/file_line_spec.rb +0 -70
  117. data/spec/indentation_spec.rb +0 -259
  118. data/spec/spacing/colon_spacing_spec.rb +0 -71
  119. data/spec/spacing/comma_spacing_spec.rb +0 -159
  120. data/spec/spacing/curly_brace_spacing_spec.rb +0 -257
  121. data/spec/spacing/parentheses_spacing_spec.rb +0 -28
  122. data/spec/spacing/square_bracket_spacing_spec.rb +0 -116
  123. data/spec/spacing_spec.rb +0 -167
  124. data/tasks/metrics.rake +0 -23
data/.gitignore CHANGED
@@ -1,8 +1,16 @@
1
1
  .autotest
2
+ .DS_Store
2
3
  .loadpath
3
4
  .project
4
5
  .yardoc/
5
6
  logic.txt
6
7
  output.txt
8
+
9
+ .bundle/
10
+ .idea/
11
+ coverage/
12
+ doc/
13
+ pkg/
7
14
  tmp/
8
- ruby-style-checker.rb
15
+
16
+ */.DS_Store
data/.rspec CHANGED
@@ -1 +1,2 @@
1
- --colour --format documentation
1
+ --tty
2
+ --color
data/.tailor ADDED
@@ -0,0 +1,6 @@
1
+ Tailor.config do |config|
2
+ config.formatters "text"
3
+ config.file_set 'lib/**/*.rb'
4
+ config.file_set 'spec/**/*.rb'
5
+ config.file_set 'features/**/*.rb'
6
+ end
@@ -1,107 +1,76 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- tailor (0.1.5)
4
+ tailor (1.0.0.alpha)
5
+ log_switch (>= 0.2.0)
5
6
  term-ansicolor (>= 1.0.5)
7
+ text-table (>= 1.2.2)
6
8
 
7
9
  GEM
8
10
  remote: http://rubygems.org/
9
11
  specs:
10
- Saikuro (1.1.0)
11
- activesupport (3.1.0)
12
- multi_json (~> 1.0)
12
+ aruba (0.4.11)
13
+ childprocess (>= 0.2.3)
14
+ cucumber (>= 1.1.1)
15
+ ffi (>= 1.0.11)
16
+ rspec (>= 2.7.0)
13
17
  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)
18
+ childprocess (0.3.1)
19
+ ffi (~> 1.0.6)
22
20
  code_statistics (0.2.13)
23
- colored (1.2)
24
- cucumber (1.1.0)
21
+ cucumber (1.1.9)
25
22
  builder (>= 2.1.2)
26
23
  diff-lcs (>= 1.1.2)
27
- gherkin (~> 2.5.0)
24
+ gherkin (~> 2.9.0)
28
25
  json (>= 1.4.6)
29
26
  term-ansicolor (>= 1.0.6)
30
27
  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)
28
+ fakefs (0.4.0)
29
+ ffi (1.0.11)
30
+ gherkin (2.9.3)
39
31
  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)
32
+ json (1.6.6)
33
+ log_switch (0.3.0)
34
+ multi_json (1.2.0)
35
+ rake (0.9.2.2)
72
36
  roodi (2.1.0)
73
37
  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)
38
+ rspec (2.9.0)
39
+ rspec-core (~> 2.9.0)
40
+ rspec-expectations (~> 2.9.0)
41
+ rspec-mocks (~> 2.9.0)
42
+ rspec-core (2.9.0)
43
+ rspec-expectations (2.9.0)
44
+ diff-lcs (~> 1.1.3)
45
+ rspec-mocks (2.9.0)
46
+ ruby_parser (2.3.1)
87
47
  sexp_processor (~> 3.0)
88
- sexp_processor (3.0.7)
89
- simplecov (0.5.3)
90
- multi_json (~> 1.0.3)
48
+ sexp_processor (3.1.0)
49
+ simplecov (0.6.1)
50
+ multi_json (~> 1.0)
91
51
  simplecov-html (~> 0.5.3)
92
52
  simplecov-html (0.5.3)
93
- syntax (1.0.0)
94
- term-ansicolor (1.0.6)
95
- yard (0.7.2)
53
+ term-ansicolor (1.0.7)
54
+ text-table (1.2.2)
55
+ yard (0.7.5)
56
+ yard-cucumber (2.1.7)
57
+ cucumber (>= 0.7.5)
58
+ gherkin (>= 2.2.9)
59
+ yard (>= 0.7.0)
96
60
 
97
61
  PLATFORMS
98
62
  ruby
99
63
 
100
64
  DEPENDENCIES
101
- code_statistics (~> 0.2.13)
102
- cucumber (>= 0.10.2)
103
- metric_fu (>= 2.0.0)
65
+ aruba
66
+ bundler
67
+ code_statistics
68
+ cucumber (>= 1.0.2)
69
+ fakefs (>= 0.4.0)
70
+ rake
71
+ roodi (>= 2.1.0)
104
72
  rspec (>= 2.5.0)
105
73
  simplecov (>= 0.4.0)
106
74
  tailor!
107
- yard (>= 0.6.8)
75
+ yard (>= 0.7.0)
76
+ yard-cucumber (>= 2.1.7)
File without changes
@@ -5,51 +5,184 @@
5
5
  == DESCRIPTION:
6
6
 
7
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
9
- here http://wiki.github.com/turboladen/tailor.
8
+ style. Rules for judging style are based on a number of style guides that are
9
+ popular in the Ruby community. More on this here
10
+ http://wiki.github.com/turboladen/tailor.
10
11
 
11
12
  == FEATURES/PROBLEMS:
12
13
 
13
- * Checks for bad style in .rb and .erb files
14
+ * Checks for bad style in Ruby files
14
15
  * Recursively in a directory, or...
15
- * A given file
16
+ * A given file, or...
17
+ * A glob ('lib/**/*.rb')
16
18
  * Checks for:
17
- * Indentation
18
- * Hard-tabs in indentation
19
+ * Horizontal spacing
20
+ * Indentation
21
+ * Use of hard-tabs
22
+ * Line length
23
+ * Trailing spaces at the end of lines
24
+ * Spacing after commas
25
+ * Spacing before commas
26
+ * Spacing around { and before }
27
+ * Spacing after [ and before ]
28
+ * Spacing after ( and before )
29
+ * Vertical spacing
30
+ * Trailing newlines (at the end of the file)
31
+ * Max code lines in a class/module
32
+ * Max code lines in a method
19
33
  * Name cases
20
34
  * Snake case class & module names
21
35
  * Camel case method names
22
- * Extra whitespace
23
- * At the end of lines
24
- * On empty lines
25
- * Around commas
26
- * Around open/closed parentheses
27
- * Around open/closed square brackets
28
- * Around open/closed curly braces
29
- * Around colons in ternary statements
30
- * Line length
31
- * Should be <= 80 characters
36
+ * Configurable
37
+ * Specify style in
38
+ * ~./tailorrc
39
+ * PROJECT_ROOT + .tailor
40
+ * as CLI options
41
+ * "File sets" allow for applying different styles to different sets of files
42
+ * CI/Build Integration
43
+ * (Well, this may be stretching things a bit, but...) Exit 1 on failures
32
44
 
33
45
  == SYNOPSIS:
34
46
 
47
+ === Why style check?
48
+
49
+ If you're reading this, there's a good chance you already have your own reasons
50
+ for doing so. If you're not familiar with static analysis, give tailor a go
51
+ for a few days and see if you think it improves your code's readability.
52
+
53
+ === What's it do?
54
+
55
+ At tailor's inception, there were some other static analysis tools for Ruby,
56
+ but none which checked style stuff; tailor started off as a means to fill this
57
+ gap. Since then, a number of those tools have dropped by the wayside due to
58
+ various Ruby 1.9 incompatibilities, and left a bigger tool gap for Rubyists.
59
+ Right now it's mostly a style-checker, but might also have a future role in
60
+ analyzing other aspects of your Ruby code.
61
+
62
+ === Since 0.x...
63
+
64
+ tailor 1.x is a marked improvment over 0.x. While 0.x provided a few (pretty
65
+ inconsistent) style checks, its design made the code get all spaghetti-like,
66
+ with lots of really gnarly regular expression matching, making it a realy bear
67
+ to add new features and fix bugs. tailor 1.x is completely redesigned to make
68
+ that whole process much easier.
69
+
70
+ === Measure Stuff
71
+
35
72
  Run tailor like:
36
73
 
37
74
  $ tailor path/to/check/
75
+
38
76
  ...or...
39
- $ tail file_to_check.rb
40
77
 
41
- There are a number of false-positives and false-negatives in detection of the
42
- above rules, so please don't expect perfection in this detection. :) I'm
43
- working on solving this.
78
+ $ tailor file_to_check.rb
79
+
80
+ ...or...
81
+
82
+ $ tailor test/**/*.rb
83
+
84
+ ...or... (defaults to lib/**/*.rb):
85
+
86
+ $ tailor
87
+
88
+ There are still a number of false-positives and false-negatives in detection of
89
+ the above rules, so please don't expect perfection in this detection. :)
90
+
91
+ === Configurable:
92
+
93
+ Not everyone prefers the same style of, well, anything really. tailor is
94
+ configurable to allow you to check your code against the style measurements
95
+ that you want.
96
+
97
+ It has default values for each of the "rulers" it uses, but if you want to
98
+ customize these, there are a number of ways you can do so.
99
+
100
+ ==== CLI
101
+
102
+ At any time, you can tell tailor to show you the configuration that it's going
103
+ to use by doing:
104
+
105
+ $ tailor --show-config
106
+
107
+ To see, amongst other options, the style options that you can pass in, do
108
+
109
+ $ tailor --help
110
+
111
+ If, for example, you want to tell tailor to warn you if any of your code lines
112
+ are > 100 chars (instead of the default of 80):
113
+
114
+ $ tailor --max-line-length 100 lib/
115
+
116
+ If you want to simply disable a ruler, just pass +false+ to the option:
117
+
118
+ $ tailor --max-line-length false lib/
119
+
120
+ ==== Configuration File
121
+
122
+ Configuration files allow for some more flexibility with style rulers, file
123
+ lists, and (eventually) report formatters. To create one with default
124
+ settings, do:
125
+
126
+ $ tailor --create-config
127
+
128
+ With the documentation that's provided in the file, the settings should be
129
+ straightforward (if they're not, please let me know!). You don't have to specify
130
+ all of those settings in your config file--those are just rendered so you have
131
+ a starting ground to tweak with. If you only want to override a single value,
132
+ you can delete the rest of the code from your config. This would accomplish
133
+ the same as the --max-line-length example above:
134
+
135
+ # .tailor
136
+ Tailor.config do |config|
137
+ config.file_set :default do
138
+ max_line_length 100
139
+ end
140
+ end
141
+
142
+ This brings us to the concept of "file sets"...
143
+
144
+ ===== File Sets
145
+
146
+ File sets allow you to use different style rulers against different groups of
147
+ files. You may, for example, want your Rails app code to allow for longer
148
+ lines, or fewer code lines in methods... You may want your RSpec code to be
149
+ more lenient with curly-brace usage... You may just want to specify a few file
150
+ globs to use the default set of rulers... File sets allow for those sorts of
151
+ things.
152
+
153
+ In the default config file, you see a single parameter being passed to
154
+ <tt>config.file_set</tt>--this is the _label_ for that file set. The label is
155
+ simply just a name to refer to that file set by; it will show in your report
156
+ (in the case that problems were found, of course) so you know what set of
157
+ rulers caused the problem to be found. <tt>config.file_set</tt> also takes
158
+ a second paramter: the file/directory/glob to apply the style to.
159
+
160
+ # .tailor
161
+ Tailor.config do |config|
162
+ config.file_set :rails_app, 'app/**/*.rb' do
163
+ max_line_length 100
164
+ # All other rulers will use default values
165
+ end
166
+
167
+ config.file_set :features, 'features/**/*.rb' # Uses default style
168
+
169
+ config.file_set :rspec, 'spec/**/*.rb' do
170
+ spaces_after_lbrace false
171
+ spaces_before_lbrace false
172
+ spaces_before_rbrace false
173
+ # All other rulers will use default values
174
+ end
175
+ end
44
176
 
45
177
  == REQUIREMENTS:
46
178
 
47
179
  * Rubies (tested)
48
- * 1.8.7
49
- * 1.9.2
50
- * 1.9.3-preview1
180
+ * 1.9.2
181
+ * 1.9.3
51
182
  * Gems
183
+ * log_switch
52
184
  * term-ansicolor
185
+ * text-table
53
186
 
54
187
  == INSTALL:
55
188
 
@@ -59,7 +192,7 @@ working on solving this.
59
192
 
60
193
  (The MIT License)
61
194
 
62
- Copyright (c) 2010-2011 Steve Loveless
195
+ Copyright (c) 2010-2012 Steve Loveless
63
196
 
64
197
  Permission is hereby granted, free of charge, to any person obtaining
65
198
  a copy of this software and associated documentation files (the
data/Rakefile CHANGED
@@ -3,14 +3,5 @@ require 'bundler/gem_tasks'
3
3
  # Load rakefile extensions
4
4
  Dir["tasks/*.rake"].each { |ext| load ext }
5
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
6
  desc "Run RSpec code examples"
16
7
  task :test => :spec
data/bin/tailor CHANGED
@@ -1,72 +1,19 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
- $:.unshift(File.dirname(__FILE__) + '/../lib/') unless
4
- $:.include?(File.dirname(__FILE__) + '/../lib/') ||
5
- $:.include?(File.expand_path(File.dirname(__FILE__) + '/../lib/'))
6
-
7
- require 'tailor'
8
-
9
- def usage
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
-
26
- end
27
-
28
- if ARGV[0].nil?
29
- puts version
30
- puts
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
-
45
- else
46
- begin
47
- path_to_check = ARGV[0]
48
-
49
- # Check to make sure we got a file or directory
50
- unless File.file?(path_to_check) or File.directory?(path_to_check)
51
- raise "Invalid file or directory: #{path_to_check}"
52
- end
53
-
54
- files_and_problems = if File.file?(path_to_check)
55
- Tailor.check_file path_to_check
56
- elsif File.directory?(path_to_check)
57
- # Check the requested files/dirs for problems
58
- Tailor.check path_to_check
59
- end
60
-
61
- problem_count = files_and_problems.values.inject(:+)
62
-
63
- # Print summary of the problems we found
64
- Tailor.print_report files_and_problems
65
- rescue RuntimeError => ex
66
- puts ex.message
67
- puts ex.backtrace
68
- puts
69
- ensure
70
- exit(1) if problem_count > 0
71
- end
3
+ require_relative '../lib/tailor/cli'
4
+ require_relative '../lib/tailor/runtime_error'
5
+
6
+
7
+ begin
8
+ failure = Tailor::CLI.run(ARGV.dup)
9
+ exit(1) if failure
10
+ rescue Tailor::RuntimeError => ex
11
+ STDERR.puts ex.message
12
+ STDERR.puts ex.backtrace.join("\n")
13
+ rescue SystemExit => ex
14
+ exit(ex.status)
15
+ rescue Exception => ex
16
+ STDERR.puts("#{ex.message} (#{ex.class})")
17
+ STDERR.puts(ex.backtrace.join("\n"))
18
+ exit(1)
72
19
  end