tailor 1.3.1 → 1.4.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (73) hide show
  1. checksums.yaml +4 -4
  2. data/.travis.yml +1 -0
  3. data/Gemfile.lock +27 -25
  4. data/History.md +36 -0
  5. data/README.md +10 -4
  6. data/Rakefile +6 -6
  7. data/features/support/env.rb +2 -2
  8. data/features/support/legacy/bad_ternary_colon_spacing.rb +1 -1
  9. data/features/support/legacy/long_file_with_indentation.rb +2 -2
  10. data/features/support/world.rb +1 -1
  11. data/features/valid_ruby.feature +1 -1
  12. data/lib/tailor/cli/options.rb +19 -1
  13. data/lib/tailor/configuration.rb +2 -2
  14. data/lib/tailor/configuration/style.rb +6 -0
  15. data/lib/tailor/lexed_line.rb +2 -2
  16. data/lib/tailor/lexer/lexer_constants.rb +1 -0
  17. data/lib/tailor/lexer/token.rb +2 -2
  18. data/lib/tailor/logger.rb +2 -2
  19. data/lib/tailor/rake_task.rb +2 -2
  20. data/lib/tailor/ruler.rb +0 -1
  21. data/lib/tailor/rulers/allow_camel_case_methods_ruler.rb +0 -1
  22. data/lib/tailor/rulers/allow_conditional_parentheses.rb +65 -0
  23. data/lib/tailor/rulers/allow_unnecessary_double_quotes_ruler.rb +61 -0
  24. data/lib/tailor/rulers/allow_unnecessary_interpolation_ruler.rb +87 -0
  25. data/lib/tailor/rulers/indentation_spaces_ruler.rb +40 -50
  26. data/lib/tailor/rulers/indentation_spaces_ruler/argument_alignment.rb +63 -0
  27. data/lib/tailor/rulers/indentation_spaces_ruler/ast_xml.rb +89 -0
  28. data/lib/tailor/rulers/indentation_spaces_ruler/indentation_manager.rb +2 -14
  29. data/lib/tailor/rulers/indentation_spaces_ruler/line_continuations.rb +58 -0
  30. data/lib/tailor/rulers/max_code_lines_in_class_ruler.rb +3 -3
  31. data/lib/tailor/rulers/max_code_lines_in_method_ruler.rb +3 -3
  32. data/lib/tailor/rulers/spaces_after_comma_ruler.rb +3 -3
  33. data/lib/tailor/rulers/spaces_after_conditional_ruler.rb +3 -3
  34. data/lib/tailor/rulers/spaces_after_lbrace_ruler.rb +3 -3
  35. data/lib/tailor/rulers/spaces_after_lbracket_ruler.rb +3 -3
  36. data/lib/tailor/rulers/spaces_after_lparen_ruler.rb +3 -3
  37. data/lib/tailor/rulers/spaces_before_comma_ruler.rb +3 -3
  38. data/lib/tailor/rulers/spaces_before_rbrace_ruler.rb +2 -2
  39. data/lib/tailor/rulers/spaces_in_empty_braces_ruler.rb +2 -2
  40. data/lib/tailor/tailorrc.erb +28 -0
  41. data/lib/tailor/version.rb +1 -1
  42. data/spec/functional/conditional_parentheses_spec.rb +325 -0
  43. data/spec/functional/conditional_spacing_spec.rb +66 -42
  44. data/spec/functional/configuration_spec.rb +1 -1
  45. data/spec/functional/horizontal_spacing/braces_spec.rb +10 -9
  46. data/spec/functional/horizontal_spacing/hard_tabs_spec.rb +4 -4
  47. data/spec/functional/horizontal_spacing_spec.rb +5 -5
  48. data/spec/functional/indentation_spacing/argument_alignment_spec.rb +511 -0
  49. data/spec/functional/indentation_spacing/line_continuations_spec.rb +181 -0
  50. data/spec/functional/indentation_spacing_spec.rb +17 -0
  51. data/spec/functional/string_interpolation_spec.rb +117 -0
  52. data/spec/functional/string_quoting_spec.rb +97 -0
  53. data/spec/functional/vertical_spacing/class_length_spec.rb +1 -1
  54. data/spec/spec_helper.rb +8 -2
  55. data/spec/support/argument_alignment_cases.rb +93 -0
  56. data/spec/support/bad_indentation_cases.rb +20 -20
  57. data/spec/support/conditional_parentheses_cases.rb +60 -0
  58. data/spec/support/good_indentation_cases.rb +31 -31
  59. data/spec/support/horizontal_spacing_cases.rb +1 -1
  60. data/spec/support/line_indentation_cases.rb +71 -0
  61. data/spec/support/string_interpolation_cases.rb +45 -0
  62. data/spec/support/string_quoting_cases.rb +25 -0
  63. data/spec/unit/tailor/configuration/file_set_spec.rb +3 -3
  64. data/spec/unit/tailor/configuration/style_spec.rb +24 -21
  65. data/spec/unit/tailor/configuration_spec.rb +4 -1
  66. data/spec/unit/tailor/formatter_spec.rb +10 -10
  67. data/spec/unit/tailor/reporter_spec.rb +0 -1
  68. data/spec/unit/tailor/rulers/indentation_spaces_ruler/indentation_manager_spec.rb +0 -11
  69. data/spec/unit/tailor/rulers/indentation_spaces_ruler_spec.rb +1 -1
  70. data/spec/unit/tailor/version_spec.rb +1 -1
  71. data/tailor.gemspec +1 -0
  72. metadata +72 -33
  73. data/.infinity_test +0 -4
@@ -28,20 +28,20 @@ INDENT_1['def_indented_end'] =
28
28
 
29
29
  INDENT_1['def_content_indented_end'] =
30
30
  %Q{def a
31
- puts "stuff"
31
+ puts 'stuff'
32
32
  end}
33
33
 
34
34
  INDENT_1['class_def_content_outdented_end'] =
35
35
  %Q{class A
36
36
  def a
37
- puts "stuff"
37
+ puts 'stuff'
38
38
  end
39
39
  end}
40
40
 
41
41
  INDENT_1['class_def_outdented_content'] =
42
42
  %Q{class A
43
43
  def a
44
- puts "stuff"
44
+ puts 'stuff'
45
45
  end
46
46
  end}
47
47
 
@@ -56,9 +56,9 @@ INDENT_1['case_indented_whens_level'] =
56
56
  %Q{def my_method
57
57
  case true
58
58
  when true
59
- puts "stuff"
59
+ puts 'stuff'
60
60
  when false
61
- puts "blah blah"
61
+ puts 'blah blah'
62
62
  end
63
63
  end}
64
64
 
@@ -66,9 +66,9 @@ INDENT_1['case_indented_whens_level_trailing_comment'] =
66
66
  %Q{def my_method
67
67
  case true # comment
68
68
  when true
69
- puts "stuff"
69
+ puts 'stuff'
70
70
  when false
71
- puts "blah blah"
71
+ puts 'blah blah'
72
72
  end
73
73
  end}
74
74
 
@@ -76,9 +76,9 @@ INDENT_1['case_outdented_whens_level'] =
76
76
  %Q{def my_method
77
77
  case true
78
78
  when true
79
- puts "stuff"
79
+ puts 'stuff'
80
80
  when false
81
- puts "blah blah"
81
+ puts 'blah blah'
82
82
  end
83
83
  end}
84
84
 
@@ -86,9 +86,9 @@ INDENT_1['case_when_indented_whens_level'] =
86
86
  %Q{def my_method
87
87
  case true
88
88
  when true
89
- puts "stuff"
89
+ puts 'stuff'
90
90
  when false
91
- puts "blah blah"
91
+ puts 'blah blah'
92
92
  end
93
93
  end}
94
94
 
@@ -96,9 +96,9 @@ INDENT_1['case_when_outdented_whens_level'] =
96
96
  %Q{def my_method
97
97
  case true
98
98
  when true
99
- puts "stuff"
99
+ puts 'stuff'
100
100
  when false
101
- puts "blah blah"
101
+ puts 'blah blah'
102
102
  end
103
103
  end}
104
104
 
@@ -106,35 +106,35 @@ INDENT_1['case_indented_whens_in'] =
106
106
  %Q{def my_method
107
107
  case true
108
108
  when true
109
- puts "stuff"
109
+ puts 'stuff'
110
110
  when false
111
- puts "blah blah"
111
+ puts 'blah blah'
112
112
  end
113
113
  end}
114
114
 
115
115
  INDENT_1['while_do_indented'] =
116
116
  %Q{ while true do
117
- puts "something"
117
+ puts 'something'
118
118
  end}
119
119
 
120
120
  INDENT_1['while_do_outdented'] =
121
121
  %Q{def my_method
122
122
  while true do
123
- puts "something"
123
+ puts 'something'
124
124
  end
125
125
  end}
126
126
 
127
127
  INDENT_1['while_do_content_outdented'] =
128
128
  %Q{def my_method
129
129
  while true do
130
- puts "something"
130
+ puts 'something'
131
131
  end
132
132
  end}
133
133
 
134
134
  INDENT_1['while_do_content_indented'] =
135
135
  %Q{def my_method
136
136
  while true do
137
- puts "something"
137
+ puts 'something'
138
138
  end
139
139
  end}
140
140
 
@@ -240,7 +240,7 @@ INDENT_1['multi_line_string_concat_with_plus_out'] =
240
240
  '/profiles/DVR5000/ssdp_notification.erb'}
241
241
 
242
242
  INDENT_1['multi_line_method_call_end_in'] =
243
- %Q{def initialize(raw_response)
243
+ %q{def initialize(raw_response)
244
244
  if raw_response.nil? || raw_response.empty?
245
245
  raise RTSP::Error,
246
246
  "#{self.class} received nil string--this shouldn't happen."
@@ -0,0 +1,60 @@
1
+ CONDITIONAL_PARENTHESES = {}
2
+
3
+ CONDITIONAL_PARENTHESES['no_parentheses'] =
4
+ %q{if foo
5
+ end}
6
+
7
+ CONDITIONAL_PARENTHESES['with_parentheses'] =
8
+ %q{if (foo)
9
+ end}
10
+
11
+ CONDITIONAL_PARENTHESES['with_parentheses_no_space'] =
12
+ %q{if(foo)
13
+ end}
14
+
15
+ CONDITIONAL_PARENTHESES['method_call'] =
16
+ %q{if foo(bar)
17
+ end}
18
+
19
+ CONDITIONAL_PARENTHESES['indented_method_call'] =
20
+ %q{foo do
21
+ if foo(bar)
22
+ end
23
+ end}
24
+
25
+ CONDITIONAL_PARENTHESES['method_call_on_parens'] =
26
+ %q{unless (foo & bar).sort
27
+ end
28
+ }
29
+
30
+ CONDITIONAL_PARENTHESES['double_parens'] =
31
+ %q{if ((bar))
32
+ end}
33
+
34
+ CONDITIONAL_PARENTHESES['unless_no_parentheses'] =
35
+ %q{unless bar
36
+ end}
37
+
38
+ CONDITIONAL_PARENTHESES['unless_with_parentheses'] =
39
+ %q{unless (bar)
40
+ end}
41
+
42
+ CONDITIONAL_PARENTHESES['case_no_parentheses'] =
43
+ %q{case bar
44
+ when 1 then 'a'
45
+ when 2 then 'b'
46
+ end}
47
+
48
+ CONDITIONAL_PARENTHESES['case_with_parentheses'] =
49
+ %q{case (bar)
50
+ when 1 then 'a'
51
+ when 2 then 'b'
52
+ end}
53
+
54
+ CONDITIONAL_PARENTHESES['while_no_parentheses'] =
55
+ %q{while bar
56
+ end}
57
+
58
+ CONDITIONAL_PARENTHESES['while_with_parentheses'] =
59
+ %q{while (bar)
60
+ end}
@@ -101,7 +101,7 @@ INDENT_OK['assignment_twolevel_array_multistatement'] =
101
101
  INDENT_OK['assignment_twolevel_paren_multistatement'] =
102
102
  %Q{result = Integer(
103
103
  String.new(
104
- "1"
104
+ '1'
105
105
  ).to_i,
106
106
  16
107
107
  )}
@@ -143,7 +143,7 @@ INDENT_OK['rescue_ending_with_comma'] =
143
143
  rescue SocketError, ArgumentError, SystemCallError,
144
144
  Net::SCP::Exception, Timeout::Error => ex
145
145
  @logger.error "Failed to copy the file \#{source} to \#{dest} due to " +
146
- "\#{ex.message}"
146
+ ex.message
147
147
  end}
148
148
 
149
149
  INDENT_OK['rescue_ending_with_comma_trailing_comment'] =
@@ -154,14 +154,14 @@ INDENT_OK['rescue_ending_with_comma_trailing_comment'] =
154
154
  rescue SocketError, ArgumentError, SystemCallError, # comment
155
155
  Net::SCP::Exception, Timeout::Error => ex
156
156
  @logger.error "Failed to copy the file \#{source} to \#{dest} due to " +
157
- "\#{ex.message}"
157
+ ex.message
158
158
  end}
159
159
 
160
160
  INDENT_OK['def_rescue'] =
161
161
  %Q{def some_method
162
162
  do_something(one, two)
163
163
  rescue => e
164
- log "It didn't work."
164
+ log 'It didn't work.'
165
165
  raise e
166
166
  end}
167
167
 
@@ -189,7 +189,7 @@ end}
189
189
  INDENT_OK['nested_def'] =
190
190
  %Q{def first_method
191
191
  def second_method
192
- puts "hi"
192
+ puts 'hi'
193
193
  end
194
194
  end}
195
195
 
@@ -233,12 +233,12 @@ class MyClass
233
233
  include Stuff
234
234
 
235
235
  def a_method
236
- puts "hello"
236
+ puts 'hello'
237
237
  end
238
238
  end}
239
239
 
240
240
  INDENT_OK['if_modifier'] =
241
- %Q{puts "hi" if nil.nil?}
241
+ %Q{puts 'hi' if nil.nil?}
242
242
 
243
243
  INDENT_OK['if_modifier2'] =
244
244
  %Q{start_key_registration_server if @profiles.values.include? :SM5000}
@@ -249,7 +249,7 @@ INDENT_OK['def_return_if_modifier'] =
249
249
  end}
250
250
 
251
251
  INDENT_OK['unless_modifier'] =
252
- %Q{puts "hi" unless nil.nil?}
252
+ %Q{puts 'hi' unless nil.nil?}
253
253
 
254
254
  INDENT_OK['def_return_unless_modifier'] =
255
255
  %Q{def a_method
@@ -269,9 +269,9 @@ INDENT_OK['case_whens_level'] =
269
269
  %Q{def my_method
270
270
  case true
271
271
  when true
272
- puts "stuff"
272
+ puts 'stuff'
273
273
  when false
274
- puts "blah blah"
274
+ puts 'blah blah'
275
275
  end
276
276
  end}
277
277
 
@@ -297,7 +297,7 @@ end}
297
297
 
298
298
  INDENT_OK['while_do_loop'] =
299
299
  %Q{while true do
300
- puts "something"
300
+ puts 'something'
301
301
  end}
302
302
 
303
303
  INDENT_OK['while_do_loop2'] =
@@ -311,7 +311,7 @@ end}
311
311
 
312
312
  INDENT_OK['until_do_loop'] =
313
313
  %Q{until true do
314
- puts "something"
314
+ puts 'something'
315
315
  end}
316
316
 
317
317
  INDENT_OK['until_do_loop2'] =
@@ -430,22 +430,22 @@ INDENT_OK['braces_combo'] =
430
430
 
431
431
  INDENT_OK['deep_hash_with_rockets'] =
432
432
  %Q[im_deep =
433
- { "one" =>
434
- { "1" =>
435
- { "a" => "A",
436
- "b" => "B",
437
- "c" => "C" },
438
- "2" =>
439
- { "d" => "D",
440
- "e" => "E",
441
- "f" => "F" } } }]
433
+ { 'one' =>
434
+ { '1' =>
435
+ { 'a' => 'A',
436
+ 'b' => 'B',
437
+ 'c' => 'C' },
438
+ '2' =>
439
+ { 'd' => 'D',
440
+ 'e' => 'E',
441
+ 'f' => 'F' } } }]
442
442
 
443
443
  INDENT_OK['embedded_strings_in_embedded_strings'] =
444
444
  %q[def friendly_time(time)
445
445
  if hours < 24
446
446
  "#{(hours > 0) ? "#{hours} hour" : '' }#{(hours > 1) ? 's' : ''}" +
447
447
  " #{(mins > 0) ? "#{mins} minute" : '' }#{(mins > 1) ? 's' : ''}" +
448
- " #{seconds} second#{(seconds > 1) ? "s" : ''} ago"
448
+ " #{seconds} second#{(seconds > 1) ? 's' : ''} ago"
449
449
  else
450
450
  time.to_s
451
451
  end
@@ -483,8 +483,8 @@ suckaaaaaa!
483
483
  ]}
484
484
 
485
485
  INDENT_OK['multi_line_brackets_embedded_hashes'] =
486
- %Q{summary_table.rows << [{ value: "File", align: :center },
487
- { value: "Total Problems", align: :center }]}
486
+ %Q{summary_table.rows << [{ value: 'File', align: :center },
487
+ { value: 'Total Problems', align: :center }]}
488
488
 
489
489
  INDENT_OK['brackets_combo'] =
490
490
  %Q{[2]
@@ -634,7 +634,7 @@ INDENT_OK['method_lonely_args'] =
634
634
  %Q{def your_thing(
635
635
  one
636
636
  )
637
- puts "stuff"
637
+ puts 'stuff'
638
638
  end}
639
639
 
640
640
  #------------------------------------------------------------------------------
@@ -688,10 +688,10 @@ INDENT_OK['block_in_block_ends_on_same_line'] =
688
688
  baz
689
689
  }.each do |thing|
690
690
  function thing do
691
- puts "stuff"
691
+ puts 'stuff'
692
692
  end end
693
693
 
694
- puts "post ends"}
694
+ puts 'post ends'}
695
695
 
696
696
  =begin
697
697
  INDENT_OK['rparen_and_do_same_line'] =
@@ -706,8 +706,8 @@ end}
706
706
  #-------------------------------------------------------------------------------
707
707
  INDENT_OK['single_line_begin_rescue_end'] =
708
708
  %Q{def log
709
- l = begin; lineno; rescue; "<EOF>"; end
710
- c = begin; column; rescue; "<EOF>"; end
709
+ l = begin; lineno; rescue; '<EOF>'; end
710
+ c = begin; column; rescue; '<EOF>'; end
711
711
  subclass_name = self.class.to_s.sub(/^Tailor::/, '')
712
712
  args.first.insert(0, "<\#{subclass_name}> \#{l}[\#{c}]: ")
713
713
  Tailor::Logger.log(*args)
@@ -738,7 +738,7 @@ end}
738
738
 
739
739
  INDENT_OK['combo3'] =
740
740
  %Q{def report_turducken(results, performance_results)
741
- stuffing[:log_files] = { "\#{File.basename @logger.log_file_location}" =>
741
+ stuffing[:log_files] = { "\#{File.basename @logger.log_file_location}/path" =>
742
742
  File.read(@logger.log_file_location).gsub(/(?<f><)(?<q>\\/)?(?<w>\\w)/,
743
743
  '\\k<f>!\\k<q>\\k<w>') }.merge remote_logs
744
744
 
@@ -747,7 +747,7 @@ INDENT_OK['combo3'] =
747
747
  @config[:turducken_password])
748
748
  suite_result_url = Stuffer.stuff(stuffing)
749
749
  rescue Errno::ECONNREFUSED
750
- @logger.error "Unable to connect to Turducken server!"
750
+ @logger.error 'Unable to connect to Turducken server!'
751
751
  end
752
752
 
753
753
  suite_result_url
@@ -87,7 +87,7 @@ H_SPACING_OK['empty_hash_in_string_in_block'] =
87
87
  %Q{[1].map { |n| { :first => "\#{n}-\#{{}}" } }}
88
88
 
89
89
  H_SPACING_OK['string_interp_with_colonop'] =
90
- %Q{"\#{::Rails.root}"}
90
+ %Q{"\#{::Rails.root + 'file'}"}
91
91
 
92
92
 
93
93
 
@@ -0,0 +1,71 @@
1
+ LINE_INDENT = {}
2
+
3
+ LINE_INDENT['hash_spans_lines'] =
4
+ %q{db_connection = { :host => "localhost", :username => 'root',
5
+ :password => node['db']['password'] }}
6
+
7
+ LINE_INDENT['if_else'] =
8
+ %q{case "foo"
9
+ when "foo"
10
+ if node["foo"]["version"].to_f >= 5.5
11
+ default['foo']['service_name'] = "foo"
12
+ default['foo']['pid_file'] = "/var/run/foo/foo.pid"
13
+ else
14
+ default['foo']['service_name'] = "food"
15
+ default['foo']['pid_file'] = "/var/run/food/food.pid"
16
+ end
17
+ end}
18
+
19
+ LINE_INDENT['line_continues_at_same_indentation'] =
20
+ %q{if someconditional_that == is_really_long.function().stuff() or
21
+ another_condition == some_thing
22
+ puts "boop"
23
+ end}
24
+
25
+ LINE_INDENT['line_continues_further_indented'] =
26
+ %q{if someconditional_that == is_really_long.function().stuff() or
27
+ another_condition == some_thing
28
+ puts "boop"
29
+ end}
30
+
31
+ LINE_INDENT['line_continues_without_nested_statements'] =
32
+ %q{attribute "foo/password",
33
+ :display_name => "Password",
34
+ :description => "Randomly generated password",
35
+ :default => "randomly generated"}
36
+
37
+ LINE_INDENT['minitest_test_cases'] =
38
+ %q{describe "foo" do
39
+ it 'includes the disk_free_limit configuration setting' do
40
+ file("#{node['foo']['config_root']}/foo.config").
41
+ must_match /\{disk_free_limit, \{mem_relative, #{node['foo']['df']}/
42
+ end
43
+ it 'includes the vm_memory_high_watermark configuration setting' do
44
+ file("#{node['foo']['config_root']}/foo.config").
45
+ must_match /\{vm_memory_high_watermark, #{node['foo']['vm']}/
46
+ end
47
+ end}
48
+
49
+ LINE_INDENT['nested_blocks'] =
50
+ %q{node['foo']['client']['packages'].each do |foo_pack|
51
+ package foo_pkg do
52
+ action :install
53
+ end
54
+ end}
55
+
56
+ LINE_INDENT['one_assignment_per_line'] =
57
+ %q{default['foo']['bar']['apt_key_id'] = 'BD2EFD2A'
58
+ default['foo']['bar']['apt_uri'] = "http://repo.example.com/apt"
59
+ default['foo']['bar']['apt_keyserver'] = "keys.example.net"}
60
+
61
+ LINE_INDENT['parameters_continuation_indent_across_lines'] =
62
+ %q{def something(waka, baka, bing,
63
+ bla, goop, foop)
64
+ stuff
65
+ end}
66
+
67
+ LINE_INDENT['parameters_no_continuation_indent_across_lines'] =
68
+ %q{def something(waka, baka, bing,
69
+ bla, goop, foop)
70
+ stuff
71
+ end}