tailor 1.2.1 → 1.3.0

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 (94) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile.lock +30 -28
  3. data/History.md +257 -0
  4. data/README.md +486 -0
  5. data/Rakefile +1 -9
  6. data/lib/ext/string_ext.rb +1 -1
  7. data/lib/tailor/cli.rb +3 -1
  8. data/lib/tailor/cli/options.rb +59 -39
  9. data/lib/tailor/configuration.rb +8 -5
  10. data/lib/tailor/configuration/file_set.rb +1 -3
  11. data/lib/tailor/configuration/style.rb +2 -0
  12. data/lib/tailor/critic.rb +2 -2
  13. data/lib/tailor/formatters/text.rb +17 -16
  14. data/lib/tailor/lexed_line.rb +2 -4
  15. data/lib/tailor/lexer.rb +9 -9
  16. data/lib/tailor/lexer/lexer_constants.rb +32 -32
  17. data/lib/tailor/lexer/token.rb +8 -10
  18. data/lib/tailor/logger.rb +1 -1
  19. data/lib/tailor/problem.rb +4 -1
  20. data/lib/tailor/rake_task.rb +4 -1
  21. data/lib/tailor/reporter.rb +3 -3
  22. data/lib/tailor/ruler.rb +2 -2
  23. data/lib/tailor/rulers/allow_camel_case_methods_ruler.rb +2 -2
  24. data/lib/tailor/rulers/allow_hard_tabs_ruler.rb +1 -1
  25. data/lib/tailor/rulers/allow_invalid_ruby_ruler.rb +1 -1
  26. data/lib/tailor/rulers/allow_screaming_snake_case_classes_ruler.rb +2 -2
  27. data/lib/tailor/rulers/indentation_spaces_ruler.rb +24 -22
  28. data/lib/tailor/rulers/indentation_spaces_ruler/indentation_manager.rb +13 -13
  29. data/lib/tailor/rulers/max_code_lines_in_class_ruler.rb +2 -2
  30. data/lib/tailor/rulers/max_code_lines_in_method_ruler.rb +2 -2
  31. data/lib/tailor/rulers/spaces_after_comma_ruler.rb +6 -6
  32. data/lib/tailor/rulers/spaces_after_conditional_ruler.rb +48 -0
  33. data/lib/tailor/rulers/spaces_after_lbrace_ruler.rb +8 -8
  34. data/lib/tailor/rulers/spaces_after_lbracket_ruler.rb +6 -6
  35. data/lib/tailor/rulers/spaces_after_lparen_ruler.rb +6 -6
  36. data/lib/tailor/rulers/spaces_before_comma_ruler.rb +2 -2
  37. data/lib/tailor/rulers/spaces_before_lbrace_ruler.rb +4 -4
  38. data/lib/tailor/rulers/spaces_before_rbrace_ruler.rb +9 -9
  39. data/lib/tailor/rulers/spaces_before_rbracket_ruler.rb +6 -6
  40. data/lib/tailor/rulers/spaces_before_rparen_ruler.rb +6 -6
  41. data/lib/tailor/rulers/spaces_in_empty_braces_ruler.rb +1 -1
  42. data/lib/tailor/rulers/trailing_newlines_ruler.rb +2 -2
  43. data/lib/tailor/tailorrc.erb +1 -1
  44. data/lib/tailor/version.rb +1 -1
  45. data/spec/functional/conditional_spacing_spec.rb +149 -0
  46. data/spec/functional/configuration_spec.rb +36 -26
  47. data/spec/functional/horizontal_spacing/braces_spec.rb +1 -1
  48. data/spec/functional/horizontal_spacing/brackets_spec.rb +14 -14
  49. data/spec/functional/horizontal_spacing/comma_spacing_spec.rb +8 -8
  50. data/spec/functional/horizontal_spacing/hard_tabs_spec.rb +13 -13
  51. data/spec/functional/horizontal_spacing/long_lines_spec.rb +6 -6
  52. data/spec/functional/horizontal_spacing/long_methods_spec.rb +55 -0
  53. data/spec/functional/horizontal_spacing/parens_spec.rb +17 -17
  54. data/spec/functional/horizontal_spacing/trailing_whitespace_spec.rb +8 -8
  55. data/spec/functional/horizontal_spacing_spec.rb +11 -11
  56. data/spec/functional/indentation_spacing/bad_indentation_spec.rb +83 -83
  57. data/spec/functional/indentation_spacing_spec.rb +10 -10
  58. data/spec/functional/naming/camel_case_methods_spec.rb +6 -6
  59. data/spec/functional/naming/screaming_snake_case_classes_spec.rb +10 -10
  60. data/spec/functional/naming_spec.rb +3 -3
  61. data/spec/functional/vertical_spacing/class_length_spec.rb +6 -6
  62. data/spec/functional/vertical_spacing/method_length_spec.rb +6 -6
  63. data/spec/functional/vertical_spacing_spec.rb +3 -3
  64. data/spec/support/conditional_spacing_cases.rb +37 -0
  65. data/spec/support/good_indentation_cases.rb +1 -1
  66. data/spec/unit/tailor/cli/options_spec.rb +50 -0
  67. data/spec/unit/tailor/cli_spec.rb +3 -3
  68. data/spec/unit/tailor/composite_observable_spec.rb +8 -8
  69. data/spec/unit/tailor/configuration/file_set_spec.rb +2 -2
  70. data/spec/unit/tailor/configuration/style_spec.rb +30 -29
  71. data/spec/unit/tailor/configuration_spec.rb +39 -24
  72. data/spec/unit/tailor/critic_spec.rb +18 -17
  73. data/spec/unit/tailor/formatter_spec.rb +15 -15
  74. data/spec/unit/tailor/formatters/yaml_spec.rb +1 -1
  75. data/spec/unit/tailor/lexed_line_spec.rb +258 -258
  76. data/spec/unit/tailor/lexer/token_spec.rb +11 -11
  77. data/spec/unit/tailor/lexer_spec.rb +35 -35
  78. data/spec/unit/tailor/problem_spec.rb +13 -13
  79. data/spec/unit/tailor/reporter_spec.rb +19 -18
  80. data/spec/unit/tailor/ruler_spec.rb +15 -15
  81. data/spec/unit/tailor/rulers/indentation_spaces_ruler/indentation_manager_spec.rb +72 -72
  82. data/spec/unit/tailor/rulers/indentation_spaces_ruler_spec.rb +32 -32
  83. data/spec/unit/tailor/rulers/spaces_after_comma_ruler_spec.rb +8 -8
  84. data/spec/unit/tailor/rulers/spaces_after_lbrace_ruler_spec.rb +36 -36
  85. data/spec/unit/tailor/rulers/spaces_before_lbrace_ruler_spec.rb +14 -14
  86. data/spec/unit/tailor/rulers/spaces_before_rbrace_ruler_spec.rb +14 -14
  87. data/spec/unit/tailor/rulers_spec.rb +2 -2
  88. data/spec/unit/tailor/version_spec.rb +1 -1
  89. data/spec/unit/tailor_spec.rb +4 -4
  90. data/tailor.gemspec +1 -1
  91. metadata +16 -9
  92. data/History.rdoc +0 -189
  93. data/README.rdoc +0 -422
  94. data/spec/unit/tailor/options_spec.rb +0 -6
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: d78f4baea607bd6a2a16460196d7af6b5a577539
4
- data.tar.gz: e08db059be465ea1f48db027f77630307b3e3b93
3
+ metadata.gz: 2411f32558fdd8904ff9e3648dd6be200a387fac
4
+ data.tar.gz: 606d2e03b3723944674ca34582d489dd269938dd
5
5
  SHA512:
6
- metadata.gz: 8f32d71d37de47cfc0f29b927e97690f06678f3b3faa07e8be3495c80abc7c4a5fb386adc8edb1eb3215ea3eaf488ea4a45dfe6dbb4088389f823b7cd9e24057
7
- data.tar.gz: 281073c232d7b5e5c98776fef62d529e3953a075e4a907de4f3e9f841879af42cba45663ff17810c47ef225e6fa71e7e772bd372145051ff02ad7dfc201c4970
6
+ metadata.gz: 547b245585cfd32f654a4f81a5abca9be7614bc5a4fed1b1fc46844c8f7b4dd5e67b55ca22822ca428ef5d60e705cc8010c8f800b93c11c0ef88c675f77ad1e2
7
+ data.tar.gz: a5b40783e31278b5b30f2226e1e9f1b97eed0d87fb88e9f1eb01cf6a36ee60b789b5526b010a04477a8818a80df92f7ba7f4fd6b019dc6c0b58123ba25da8c1c
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- tailor (1.2.1)
4
+ tailor (1.3.0)
5
5
  log_switch (>= 0.3.0)
6
6
  term-ansicolor (>= 1.0.5)
7
7
  text-table (>= 1.2.2)
@@ -9,46 +9,48 @@ PATH
9
9
  GEM
10
10
  remote: https://rubygems.org/
11
11
  specs:
12
- aruba (0.5.1)
13
- childprocess (~> 0.3.6)
12
+ aruba (0.5.3)
13
+ childprocess (>= 0.3.6)
14
14
  cucumber (>= 1.1.1)
15
15
  rspec-expectations (>= 2.7.0)
16
- builder (3.2.0)
16
+ builder (3.2.2)
17
17
  childprocess (0.3.9)
18
18
  ffi (~> 1.0, >= 1.0.11)
19
- cucumber (1.2.2)
19
+ cucumber (1.3.8)
20
20
  builder (>= 2.1.2)
21
21
  diff-lcs (>= 1.1.3)
22
- gherkin (~> 2.11.6)
22
+ gherkin (~> 2.12.1)
23
+ multi_json (>= 1.7.5, < 2.0)
24
+ multi_test (>= 0.0.2)
25
+ diff-lcs (1.2.4)
26
+ fakefs (0.4.3)
27
+ ffi (1.9.0)
28
+ ffi (1.9.0-java)
29
+ gherkin (2.12.1)
30
+ multi_json (~> 1.3)
31
+ gherkin (2.12.1-java)
23
32
  multi_json (~> 1.3)
24
- diff-lcs (1.2.1)
25
- fakefs (0.4.2)
26
- ffi (1.4.0)
27
- ffi (1.4.0-java)
28
- gherkin (2.11.6)
29
- json (>= 1.7.6)
30
- gherkin (2.11.6-java)
31
- json (>= 1.7.6)
32
- json (1.7.7)
33
- json (1.7.7-java)
34
33
  log_switch (0.4.0)
35
- multi_json (1.6.1)
36
- rake (10.0.3)
37
- rspec (2.13.0)
38
- rspec-core (~> 2.13.0)
39
- rspec-expectations (~> 2.13.0)
40
- rspec-mocks (~> 2.13.0)
41
- rspec-core (2.13.0)
42
- rspec-expectations (2.13.0)
34
+ multi_json (1.8.0)
35
+ multi_test (0.0.2)
36
+ rake (10.1.0)
37
+ rspec (2.14.1)
38
+ rspec-core (~> 2.14.0)
39
+ rspec-expectations (~> 2.14.0)
40
+ rspec-mocks (~> 2.14.0)
41
+ rspec-core (2.14.5)
42
+ rspec-expectations (2.14.3)
43
43
  diff-lcs (>= 1.1.3, < 2.0)
44
- rspec-mocks (2.13.0)
44
+ rspec-mocks (2.14.3)
45
45
  simplecov (0.7.1)
46
46
  multi_json (~> 1.0)
47
47
  simplecov-html (~> 0.7.1)
48
48
  simplecov-html (0.7.1)
49
- term-ansicolor (1.1.1)
50
- text-table (1.2.2)
51
- yard (0.8.5.2)
49
+ term-ansicolor (1.2.2)
50
+ tins (~> 0.8)
51
+ text-table (1.2.3)
52
+ tins (0.11.0)
53
+ yard (0.8.7.2)
52
54
 
53
55
  PLATFORMS
54
56
  java
@@ -0,0 +1,257 @@
1
+ ### 1.3.0 2013-09-27
2
+
3
+ * Features
4
+ * [gh-91](https://github.com/turboladen/tailor/issues/91) (partial fix)
5
+ * @acrmp added the spaces_after_conditional ruler, which checks for
6
+ conditional keywords that aren't followed with a space.
7
+
8
+ * Bug fixes
9
+ * [gh-116](https://github.com/turboladen/tailor/issues/116) and
10
+ [gh-135](https://github.com/turboladen/tailor/issues/135)
11
+ * Recursive file sets now accept style properly. Thanks, @acrmp!
12
+ * [gh-117](https://github.com/turboladen/tailor/issues/117) and
13
+ [gh-118](https://github.com/turboladen/tailor/issues/118)
14
+ * Command line options can now be turned off using `false` and `off`.
15
+ Thanks, @acrmp!
16
+
17
+
18
+
19
+ ### 1.2.1 2013-03-12
20
+
21
+ * [gh-134](https://github.com/turboladen/tailor/issues/134)
22
+ * Turned logging off by default when using bin/tailor. This was a
23
+ regression introduced in 1.2.0.
24
+
25
+
26
+
27
+ ### 1.2.0 2013-03-06
28
+
29
+ * [gh-119](https://github.com/turboladen/tailor/issues/119)
30
+ * AllowInvalidRubyRuler now uses Gem.ruby to use the ruby that tailor
31
+ was run with.
32
+
33
+ * [gh-130](https://github.com/turboladen/tailor/issues/130)
34
+ * AllowInvalidRubyRuler now handles file names with spaces in them.
35
+
36
+ * [gh-131](https://github.com/turboladen/tailor/issues/131)
37
+ * Added YAML output formatter. Thanks @leandronsp!
38
+
39
+ * [gh-133](https://github.com/turboladen/tailor/issues/133)
40
+ * Added support for Ruby 2.0.0-p0. ...which is actually just accounting
41
+ for a [fix to Ripper](https://bugs.ruby-lang.org/issues/6211) that
42
+ finally got merged in to a Ruby release.
43
+
44
+
45
+ ### 1.1.5 2013-01-30
46
+
47
+ * [gh-127](https://github.com/turboladen/tailor/issues/127)
48
+ * The last fix had SystemExit being displayed to the user at all times
49
+ (since it should've been getting rescued from when the program exits).
50
+ Properly rescuing this now for Rake tasks, so it now behaves just
51
+ like bin/tailor in this respect.
52
+
53
+ ### 1.1.4 2013-01-29
54
+
55
+ * [gh-127](https://github.com/turboladen/tailor/issues/127)
56
+ * RakeTask now actually does something (works).
57
+
58
+ * tailor should now abort (and let you know) when it can't find the config
59
+ file that you told it to use. Previously, it would just fall back to
60
+ default settings.
61
+
62
+
63
+ ### 1.1.3 2013-01-28
64
+
65
+ * [gh-121](https://github.com/turboladen/tailor/issues/121)
66
+ * Camel case methods are now detected properly when used inside of a
67
+ class. Thanks @jasonku!
68
+
69
+
70
+
71
+ ### 1.1.2 2012-06-01
72
+
73
+ * [gh-101](https://github.com/turboladen/tailor/issues/101)
74
+ * Tailor now handles code that uses backslashes to break up statements
75
+ to multiple lines. Note that this is somewhat of a hack, since Ripper
76
+ does not tokenize these backslashes--it actually just treats what we
77
+ see as 2 lines of code as a single line of code. In order to preserve
78
+ line numbering and indentation tracking, tailor replaces the backslash
79
+ with a special comment that it can detect and handle accordingly.
80
+ While this isn't ideal, given the current design, it seemed like the
81
+ way to deal with this.
82
+
83
+ * [gh-103](https://github.com/turboladen/tailor/issues/103)
84
+ * Tailor now properly handles string interpolation inside string
85
+ interpolation.
86
+
87
+
88
+
89
+ ### 1.1.1 2012-05-31
90
+
91
+ * [gh-110](https://github.com/turboladen/tailor/issues/110)
92
+ * Tailor now exits with 0 if non-error problems are found.
93
+
94
+
95
+
96
+ ### 1.1.0 2012-05-07
97
+
98
+ * [gh-89](https://github.com/turboladen/tailor/issues/89)
99
+ * You can now use {Tailor::RakeTask} to create a Rake task.
100
+
101
+ * [gh-100](https://github.com/turboladen/tailor/issues/100)
102
+ * Added {Tailor::Configuration#recursive_file_set}. This lets you do
103
+ the following in your config file, which will recursively match all
104
+ files in your current path that end with '_spec.rb':
105
+
106
+ ```ruby
107
+ Tailor.config do |config|
108
+ config.recursive_file_set '*_spec.rb', :unit_tests do |style|
109
+ style.max_line_length 90, level: :warn
110
+ end
111
+ end
112
+ ```
113
+
114
+ ...which is equivalent to:
115
+
116
+ ```ruby
117
+ Tailor.config do |config|
118
+ config.file_set '*/**/*_spec.rb', :unit_tests do |style|
119
+ style.max_line_length 90, level: :warn
120
+ end
121
+ end
122
+ ```
123
+
124
+
125
+ * [gh-107](https://github.com/turboladen/tailor/issues/107)
126
+ * Fixed --no-color option.
127
+
128
+ * [gh-108](https://github.com/turboladen/tailor/issues/108)
129
+ * Fixed --create-config, which created style level options with a
130
+ missing ':' for the Hash value.
131
+
132
+ * Configuration files now don't force you to use the :default file set. If
133
+ you don't specify any file sets, then the default is used; if you specify
134
+ file sets, it uses what you specify.
135
+ * CLI options now override config file options for all file sets
136
+ (previously, only the :default file set's option would get overridden by
137
+ the CLI option).
138
+
139
+
140
+ ### 1.0.1 2012-04-23
141
+
142
+ * [gh-104](https://github.com/turboladen/tailor/issues/104):
143
+ * Fixed incorrect rendering of config file when using `tailor
144
+ --create-config`.
145
+
146
+
147
+
148
+ ### 1.0.0 2012-04-17
149
+
150
+ * Big update to config file.
151
+ * Fix for indentation checking on nested Hashes.
152
+ * Fix for overriding default style in config files.
153
+ * Fix to exit after --show-config.
154
+ * [gh-99](https://github.com/turboladen/tailor/issues/99)
155
+ * Now warns by default if `ruby -c [file]` fails.
156
+
157
+ * [gh-93](https://github.com/turboladen/tailor/issues/93)
158
+ * 2 'end's on the same line don't cause an indentation error.
159
+
160
+ * [gh-92](https://github.com/turboladen/tailor/issues/92)
161
+ * Users can now turn off a ruler...
162
+ * CLI: `--my-option off`
163
+ * Config file: `my_option 1, level: :off`
164
+
165
+
166
+ * [gh-86](https://github.com/turboladen/tailor/issues/86)
167
+ * Indentation checking implemented.
168
+
169
+ * [gh-68](https://github.com/turboladen/tailor/issues/68)
170
+ * Spaces aren't improperly detected after a token when the line ends
171
+ with a backslash.
172
+
173
+
174
+
175
+ ### 1.0.0.alpha2 2012-04-09
176
+
177
+ * Fix for when not using a config file.
178
+
179
+
180
+ ### 1.0.0.alpha 2012-04-09
181
+
182
+ * Complete rewrite.
183
+ * New style checks:
184
+ * Indentation.
185
+ * LOC count in a class.
186
+ * LOC count in a method.
187
+ * Trailing newlines at EOF.
188
+
189
+ * Other new features:
190
+ * Configuration file use--both .tailor and ~/.tailorrc--lets you specify
191
+ groups of files.
192
+ * Turn checks off via CLI options.
193
+
194
+
195
+
196
+ ### 0.1.5 2011-09-27
197
+
198
+ * Fixed post install message to use heredoc instead of %w (<-wth was I
199
+ thinking?)
200
+
201
+
202
+ ### 0.1.4 2011-09-27
203
+
204
+ * gh-81: Return exit status of 1 if problems were found.
205
+ * Fixed Rakefile and .gemspec. [sergio-fry]
206
+ * Removed dependency on hoe for gem building.
207
+ * Added -v/--version to bin/tailor.
208
+ * Fixed documentation indentation.
209
+
210
+
211
+ ### 0.1.3 2010-12-14
212
+
213
+ * Added check for .erb files.
214
+
215
+
216
+ ### 0.1.2 2010-09-01
217
+
218
+ * Added ability to check a single file.
219
+
220
+
221
+ ### 0.1.0 2010-05-21
222
+
223
+ * Added checks for spacing around { and }.
224
+ * Added check for spacing around ternary ':'.
225
+ * Colorized error messages to be red.
226
+ * Problem message are now grouped by file line (when multiple problems per
227
+ line).
228
+ * Temporarily removed reporting of # of trailing whitespaces.
229
+
230
+
231
+ ### 0.0.3 2010-04-26
232
+
233
+ * Added checks for spacing around commas.
234
+ * Added checks for spacing around open/closed parenthesis/brackets.
235
+
236
+
237
+ ### 0.0.2 2010-04-23
238
+
239
+ * Renamed project from ruby_style_checker to Tailor.
240
+ * Added check for lines > 80 characters.
241
+
242
+
243
+ ### 0.0.1 2010-04-22
244
+
245
+ * Initial release!
246
+ * Command-line executable takes a directory and checks all files,
247
+ recursively.
248
+ * Checks for:
249
+ * Indentation
250
+ * Hard-tabs in indentation
251
+ * Name cases
252
+ * Snake case class & module names
253
+ * Camel case method names
254
+ * Extra whitespace
255
+ * At the end of lines
256
+ * On empty lines
257
+ * After commas
@@ -0,0 +1,486 @@
1
+ # tailor
2
+
3
+ * http://github.com/turboladen/tailor
4
+
5
+
6
+ [<img src="https://secure.travis-ci.org/turboladen/tailor.png?branch=master"
7
+ alt="Build Status" />](http://travis-ci.org/turboladen/tailor) [<img
8
+ src="https://codeclimate.com/badge.png"
9
+ />](https://codeclimate.com/github/turboladen/tailor)
10
+
11
+ ## DESCRIPTION:
12
+
13
+ tailor parses Ruby files and measures them with some style and static analysis
14
+ "rulers". Default values for the Rulers are based on a number of style guides
15
+ in the Ruby community as well as what seems to be common. More on this here
16
+ http://wiki.github.com/turboladen/tailor.
17
+
18
+ tailor's goal is to help you be consistent with your style, throughout your
19
+ project, whatever style that may be.
20
+
21
+ ## FEATURES/PROBLEMS:
22
+
23
+ * Checks for bad style in Ruby files
24
+ * Recursively in a directory, or...
25
+ * A given file, or...
26
+ * A glob ('lib/***/**.rb')
27
+ * Checks for:
28
+ * Horizontal spacing
29
+ * Indentation
30
+ * Use of hard-tabs
31
+ * Line length
32
+ * Trailing spaces at the end of lines
33
+ * Spacing after commas
34
+ * Spacing before commas
35
+ * Spacing around { and before }
36
+ * Spacing after [ and before ]
37
+ * Spacing after ( and before )
38
+ * Spacing after a conditional
39
+ * Vertical spacing
40
+ * Trailing newlines (at the end of the file)
41
+ * Max code lines in a class/module
42
+ * Max code lines in a method
43
+ * Name cases
44
+ * Snake case class & module names
45
+ * Camel case method names
46
+ * Valid Ruby (warns by default)
47
+ * Configurable
48
+ * Specify style in
49
+ * ~./tailorrc
50
+ * PROJECT_ROOT + .tailor
51
+ * as CLI options
52
+ * "File sets" allow for applying different styles to different groups of
53
+ files
54
+ * Set problems to :warn or :off instead of :fail
55
+ * Define custom "Rulers"
56
+ * CI/Build Integration
57
+ * (Well, this may be stretching things a bit, but...) Exit 1 on failures
58
+
59
+
60
+
61
+ ## SYNOPSIS:
62
+
63
+ ### Why style check?
64
+
65
+ If you're reading this, there's a good chance you already have your own
66
+ reasons for doing so. If you're not familiar with static analysis, give
67
+ tailor a go for a few days and see if you think it improves your code's
68
+ readability.
69
+
70
+ ### What's it do?
71
+
72
+ At tailor's inception, there were some other static analysis tools for Ruby,
73
+ but none which checked style stuff; tailor started off as a means to fill this
74
+ gap. Since then, a number of those tools have dropped by the wayside due to
75
+ various Ruby 1.9 incompatibilities, and left a bigger tool gap for Rubyists.
76
+ Right now it's mostly a style-checker, but might into a tool for analyzing
77
+ other aspects of your Ruby code.
78
+
79
+ ### Since 0.x...
80
+
81
+ tailor 1.x is a marked improvment over 0.x. While 0.x provided a few (pretty
82
+ inconsistent) style checks, its design made the code get all spaghetti-like,
83
+ with lots of really gnarly regular expression matching, making it a realy bear
84
+ to add new features and fix bugs. tailor 1.x is completely redesigned to make
85
+ that whole process much easier.
86
+
87
+ ### Measure Stuff
88
+
89
+ Check *all* files in a directory:
90
+
91
+ ```bash
92
+ $ tailor path/to/check/
93
+ ```
94
+
95
+ Check a single file:
96
+
97
+ ```bash
98
+ $ tailor file_to_check.rb
99
+ ```
100
+
101
+ Check only files ending in .rb under the 'test' directory:
102
+
103
+ ```bash
104
+ $ tailor test/**/*.rb
105
+ ```
106
+
107
+ Check defaults (lib/***/**.rb):
108
+
109
+ ```bash
110
+ $ tailor
111
+ ```
112
+
113
+ Printing the results in a output file (if using a formatter that accepts
114
+ output files, like 'yaml'):
115
+
116
+ ```bash
117
+ $ tailor path/to/check --output-file=my-results.yaml
118
+ $ tailor --output-file=my-results-from-defaults.yaml
119
+ ```
120
+
121
+ Use defaults via a Rake task (if you have a .tailor file, it'll use those
122
+ settings):
123
+
124
+ ```ruby
125
+ require 'tailor/rake_task'
126
+
127
+ Tailor::RakeTask.new
128
+ ```
129
+
130
+ #### On style...
131
+
132
+ The features list, above, shows some aspects of style that should be fairly
133
+ straightforward (as to their meaning and reason), however, others make some
134
+ big assumptions--particularly the indentation checking "ruler". There are a
135
+ number of popular indenting conventions... In the case of multi-line
136
+ parameters to a method, some like do this:
137
+
138
+ ```ruby
139
+ def a_really_freakin_long_method_name(my_really_long_first_parameter,
140
+ my_next_param)
141
+ # ...
142
+ end
143
+ ```
144
+
145
+ ...while others prefer:
146
+
147
+ ```ruby
148
+ def a_really_freakin_long_method_name(my_really_long_first_parameter,
149
+ my_next_param)
150
+ # ...
151
+ end
152
+ ```
153
+
154
+ ...and yet some others prefer:
155
+
156
+ ```ruby
157
+ def a_really_freakin_long_method_name(my_really_long_first_parameter,
158
+ my_next_param)
159
+ # ...
160
+ end
161
+ ```
162
+
163
+ At this point, tailor only supports the style used in the first example. If
164
+ this style isn't to your liking, then definitely take a look at the
165
+ Configurable section here to see how to turn this off. Other styles will
166
+ probably be supported in the future.
167
+
168
+ All that to say, though, that this isn't the only case where tailor makes
169
+ style assumptions. Another discrepancy in popular styles is with regard to
170
+ aligning operators in different lines. Some like:
171
+
172
+ ```ruby
173
+ my_hash[:first][:thing] = 1
174
+ my_hash[:eleventy][:thing] = 2
175
+ ```
176
+
177
+ ...while others prefer:
178
+
179
+ ```ruby
180
+ my_hash[:first][:thing] = 1
181
+ my_hash[:eleventy][:thing] = 2
182
+ ```
183
+
184
+ ...and yet some others prefer:
185
+
186
+ ```ruby
187
+ my_hash[:first][:thing] = 1
188
+ my_hash[:eleventy][:thing] = 2
189
+ ```
190
+
191
+ Again, tailor only supports the first example here.
192
+
193
+ The goal is certainly not to force you to use the style that tailor currently
194
+ uses; it just might not support your style yet. If tailor doesn't support
195
+ your style, please feel free to take a look at the issues list and make a
196
+ request. ...or fork away!
197
+
198
+ ### Configurable:
199
+
200
+ Not everyone prefers the same style of, well, anything really. tailor is
201
+ configurable to allow you to check your code against the style measurements
202
+ that you want.
203
+
204
+ It has default values for each of the "rulers" it uses, but if you want to
205
+ customize these, there are a number of ways you can do so.
206
+
207
+ #### CLI
208
+
209
+ At any time, you can tell tailor to show you the configuration that it's going
210
+ to use by doing:
211
+
212
+ ```bash
213
+ $ tailor --show-config
214
+ ```
215
+
216
+ To see, amongst other options, the style options that you can pass in, do
217
+
218
+ ```bash
219
+ $ tailor --help
220
+ ```
221
+
222
+ If, for example, you want to tell tailor to warn you if any of your code lines
223
+ are > 100 chars (instead of the default of 80):
224
+
225
+ ```bash
226
+ $ tailor --max-line-length 100 lib/
227
+ ```
228
+
229
+ If you want to simply disable a ruler, just pass `off` to the option:
230
+
231
+ ```bash
232
+ $ tailor --max-line-length off lib/
233
+ ```
234
+
235
+ #### Configuration File
236
+
237
+ While you can drive most tailor options from the command line, configuration
238
+ files allow for some more flexibility with style rulers, file lists, and
239
+ (eventually) report formatters. To create one with default settings, do:
240
+
241
+ ```bash
242
+ $ tailor --create-config
243
+ ```
244
+
245
+ With the documentation that's provided in the file, the settings should be
246
+ straightforward (if they're not, please let me know!). You don't have to
247
+ specify all of those settings in your config file--those are just rendered so
248
+ you have a starting ground to tweak with. If you only want to override a
249
+ single value, you can delete the rest of the code from your config. This
250
+ would accomplish the same as the `--max-line-length` example above:
251
+
252
+ ```ruby
253
+ # .tailor
254
+ Tailor.config do |config|
255
+ config.file_set 'lib/**/*.rb' do |style|
256
+ style.max_line_length 100
257
+ end
258
+ end
259
+ ```
260
+
261
+ This brings us to the concept of "file sets"...
262
+
263
+ ##### File Sets
264
+
265
+ File sets allow you to use different style rulers against different groups of
266
+ files. You may, for example, want your Rails app code to allow for longer
267
+ lines, or fewer code lines in methods... You may want your RSpec code to be
268
+ more lenient with curly-brace usage... You may just want to specify a few file
269
+ globs to use the default set of rulers... File sets allow for those sorts of
270
+ things.
271
+
272
+ In the default config file, you see a single parameter being passed to
273
+ `config.file_set`--this is the glob that defines the list of files for that
274
+ file set. While you don't see it, `config.file_set` takes a second optional
275
+ parameter that allows you to *label* your style properties, and thus use
276
+ different sets of style properties for differet sets of files. The label is
277
+ simply just a name to refer to that file set by; it will show in your report
278
+ (in the case that problems were found, of course) so you know what set of
279
+ rulers caused the problem to be found.
280
+
281
+ ```ruby
282
+ # .tailor
283
+ Tailor.config do |config|
284
+
285
+ # All defaults; implies "default" label
286
+ config.file_set 'lib/**/*.rb'
287
+
288
+ config.file_set 'app/**/*.rb', :rails_app do |style|
289
+ style.max_line_length 100
290
+ # All other rulers will use default values
291
+ end
292
+
293
+ # Uses default style, but labelled in the report with "features"
294
+ config.file_set 'features/**/*.rb', :features
295
+
296
+ config.file_set 'spec/**/*.rb', :rspec do |style|
297
+ style.spaces_after_lbrace false
298
+ style.spaces_before_lbrace false
299
+ style.spaces_before_rbrace false
300
+ # All other rulers will use default values
301
+ end
302
+ end
303
+ ```
304
+
305
+ If it suits you better, use "recursive file sets" to get all matching files in
306
+ your current path. If you wanted to critique all .rb files:
307
+
308
+ ```ruby
309
+ # .tailor
310
+ Tailor.config do |config|
311
+
312
+ # All defaults; implies "default" label
313
+ config.recursive_file_set '*.rb'
314
+ end
315
+ ```
316
+
317
+ Similarly to the CLI, if you want to turn off a default Ruler, set its problem
318
+ level to `:off`:
319
+
320
+ ```ruby
321
+ # .tailor
322
+ Tailor.config do |config|
323
+ config.file_set 'lib/**/*.rb' do |style|
324
+ style.indentation_spaces 2, level: :off
325
+ end
326
+ end
327
+ ```
328
+
329
+ ##### Formatters
330
+
331
+ By default Tailor uses the text formatter, printing the results on console.
332
+ Tailor also provides a YAML formatter, that accepts an output file if using
333
+ the option --output-file=*.yaml
334
+
335
+ ```ruby
336
+ # .tailor
337
+ Tailor.config do |config|
338
+ config.formatters 'text', 'yaml'
339
+
340
+ # just one
341
+ config.formatters 'text'
342
+ end
343
+ ```
344
+
345
+ ### Define A Custom Ruler
346
+
347
+ While tailor provides a number of Rulers for checking style, it also provides
348
+ a way for you to add your own rulers without having to delve into its innards.
349
+ To do this, you need to do the following.
350
+
351
+ #### Create the Ruler
352
+
353
+ Before jumping in to this, take a look at {Tailor::Ruler} and any of the
354
+ existing Rulers in `lib/tailor/rulers/`. There are some key things a new
355
+ Ruler must have:
356
+
357
+ * the class name ends with "Ruler"
358
+ * it inherits {Tailor::Ruler}
359
+ * it's defined within the {Tailor::Rulers} module
360
+ * `#initialize` defines two parameters:
361
+ 1. `config` sets `@config` to the "golden rule" value for what you're
362
+ measuring
363
+ 2. `options` is a Hash, that should at least be passed the `:level =>` you
364
+ want the problem to be logged as
365
+
366
+ * `#add_lexer_observers` gets passed a list of {Tailor::Lexer} event types
367
+ that the ruler should get notified on
368
+ * it defines call-back methods for {Tailor::Lexer} to call when it comes
369
+ across an event of interest
370
+ * it calls `#measure` to assess if the criteria it's checking has been met
371
+ * it adds a {Tailor::Problem} to +@problems+ when one is found in `#measure`
372
+
373
+
374
+ #### Add the Ruler to the list of Styles
375
+
376
+ Internally, this all happens in `lib/tailor/configuration/style.rb`, but you
377
+ can add infomation about your ruler to your config file. If you created a
378
+ Ruler:
379
+
380
+ ```ruby
381
+ # max_lines_in_block.rb
382
+ class Tailor
383
+ module Rulers
384
+ class MaxLinesInBlockRuler < Tailor::Ruler
385
+ def initialize(config, options)
386
+ super(config, options)
387
+ add_lexer_observers :ignored_nl, :kw
388
+ end
389
+
390
+ def ignored_nl_update(lexed_line, lineno, column)
391
+ # ...
392
+ end
393
+
394
+ def kw_update(token, lexed_line, lineno, column)
395
+ # ...
396
+ end
397
+
398
+ def measure
399
+ # ...
400
+ end
401
+
402
+ # ...
403
+ end
404
+ end
405
+ end
406
+ ```
407
+
408
+ ...then require this and add it to the Style list of properties:
409
+
410
+ ```ruby
411
+ # .tailor
412
+ require 'tailor/configuration/style'
413
+ require 'max_lines_in_block'
414
+
415
+ Tailor::Configuration::Style.define_property :max_lines_in_block
416
+
417
+ Tailor.config do |config|
418
+ config.file_set 'lib/**/*.rb' do |style|
419
+ style.max_lines_in_block 10, level: :error
420
+ end
421
+ end
422
+ ```
423
+
424
+ Next time you run tailor, your Ruler will get initialized and used.
425
+
426
+ ### Using the lib
427
+
428
+ Sometimes you could use tailor as a lib, getting the results as a hash and
429
+ manipulate them according your domain.
430
+
431
+ ```ruby
432
+ require 'tailor/cli'
433
+
434
+ # only results from a specific path
435
+ tailor = Tailor::CLI.new %w(app/controllers)
436
+ tailor.result # result should be a hash {"filename" => [problems]}
437
+
438
+ # using other file config (hiding path, it'll use from default config)
439
+ Tailor::CLI.new %w(--config-file=.other-config)
440
+ Tailor::CLI.new [] # uses file set from .tailor file config
441
+
442
+ # printing the results in a output file
443
+ tailor = Tailor::CLI.new %w(--output-file=results.yaml)
444
+ tailor.execute!
445
+ ```
446
+
447
+ ## REQUIREMENTS:
448
+
449
+ * Rubies (tested)
450
+ * 1.9.3
451
+ * 2.0.0
452
+
453
+ * Gems
454
+ * log_switch
455
+ * term-ansicolor
456
+ * text-table
457
+
458
+
459
+
460
+ ## INSTALL:
461
+
462
+ $ (sudo) gem install tailor
463
+
464
+ ## LICENSE:
465
+
466
+ (The MIT License)
467
+
468
+ Copyright (c) 2010-2013 Steve Loveless
469
+
470
+ Permission is hereby granted, free of charge, to any person obtaining a copy
471
+ of this software and associated documentation files (the 'Software'), to deal
472
+ in the Software without restriction, including without limitation the rights
473
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
474
+ copies of the Software, and to permit persons to whom the Software is
475
+ furnished to do so, subject to the following conditions:
476
+
477
+ The above copyright notice and this permission notice shall be included in all
478
+ copies or substantial portions of the Software.
479
+
480
+ THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
481
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
482
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
483
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
484
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
485
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
486
+ SOFTWARE.