tailor 1.0.1 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (69) hide show
  1. data/.tailor +1 -0
  2. data/Gemfile.lock +1 -1
  3. data/History.rdoc +34 -0
  4. data/README.rdoc +17 -1
  5. data/features/valid_ruby.feature +1 -1
  6. data/lib/ext/string_ext.rb +0 -4
  7. data/lib/tailor/cli/options.rb +9 -2
  8. data/lib/tailor/configuration.rb +103 -150
  9. data/lib/tailor/configuration/file_set.rb +110 -0
  10. data/lib/tailor/formatters/text.rb +108 -79
  11. data/lib/tailor/rake_task.rb +148 -0
  12. data/lib/tailor/tailorrc.erb +1 -1
  13. data/lib/tailor/version.rb +1 -1
  14. data/spec/functional/configuration_spec.rb +244 -0
  15. data/spec/functional/horizontal_spacing/braces_spec.rb +238 -0
  16. data/spec/functional/horizontal_spacing/brackets_spec.rb +88 -0
  17. data/spec/functional/horizontal_spacing/comma_spacing_spec.rb +68 -0
  18. data/spec/functional/horizontal_spacing/hard_tabs_spec.rb +110 -0
  19. data/spec/functional/horizontal_spacing/long_lines_spec.rb +51 -0
  20. data/spec/functional/horizontal_spacing/parens_spec.rb +102 -0
  21. data/spec/functional/horizontal_spacing/trailing_whitespace_spec.rb +66 -0
  22. data/spec/functional/horizontal_spacing_spec.rb +59 -0
  23. data/spec/functional/indentation_spacing/bad_indentation_spec.rb +372 -0
  24. data/spec/functional/indentation_spacing_spec.rb +85 -0
  25. data/spec/functional/naming/camel_case_methods_spec.rb +56 -0
  26. data/spec/functional/naming/screaming_snake_case_classes_spec.rb +83 -0
  27. data/spec/functional/naming_spec.rb +35 -0
  28. data/spec/functional/vertical_spacing/class_length_spec.rb +67 -0
  29. data/spec/functional/vertical_spacing/method_length_spec.rb +61 -0
  30. data/spec/functional/vertical_spacing_spec.rb +35 -0
  31. data/spec/support/bad_indentation_cases.rb +265 -0
  32. data/{features/support/file_cases/indentation_cases.rb → spec/support/good_indentation_cases.rb} +6 -266
  33. data/spec/support/horizontal_spacing_cases.rb +136 -0
  34. data/spec/support/naming_cases.rb +26 -0
  35. data/{features/support/file_cases → spec/support}/vertical_spacing_cases.rb +0 -33
  36. data/spec/{tailor → unit/tailor}/cli_spec.rb +1 -1
  37. data/spec/{tailor → unit/tailor}/composite_observable_spec.rb +1 -1
  38. data/spec/unit/tailor/configuration/file_set_spec.rb +65 -0
  39. data/spec/{tailor → unit/tailor}/configuration/style_spec.rb +1 -1
  40. data/spec/{tailor → unit/tailor}/configuration_spec.rb +1 -59
  41. data/spec/{tailor → unit/tailor}/critic_spec.rb +1 -1
  42. data/spec/{tailor → unit/tailor}/formatter_spec.rb +1 -1
  43. data/spec/{tailor → unit/tailor}/lexed_line_spec.rb +1 -1
  44. data/spec/{tailor → unit/tailor}/lexer/token_spec.rb +1 -1
  45. data/spec/{tailor → unit/tailor}/lexer_spec.rb +1 -2
  46. data/spec/{tailor → unit/tailor}/options_spec.rb +1 -1
  47. data/spec/{tailor → unit/tailor}/problem_spec.rb +1 -1
  48. data/spec/{tailor → unit/tailor}/reporter_spec.rb +1 -1
  49. data/spec/{tailor → unit/tailor}/ruler_spec.rb +1 -1
  50. data/spec/{tailor → unit/tailor}/rulers/indentation_spaces_ruler/indentation_manager_spec.rb +1 -1
  51. data/spec/{tailor → unit/tailor}/rulers/indentation_spaces_ruler_spec.rb +1 -1
  52. data/spec/{tailor → unit/tailor}/rulers/spaces_after_comma_ruler_spec.rb +1 -1
  53. data/spec/{tailor → unit/tailor}/rulers/spaces_after_lbrace_ruler_spec.rb +1 -1
  54. data/spec/{tailor → unit/tailor}/rulers/spaces_before_lbrace_ruler_spec.rb +1 -1
  55. data/spec/{tailor → unit/tailor}/rulers/spaces_before_rbrace_ruler_spec.rb +1 -1
  56. data/spec/{tailor → unit/tailor}/rulers_spec.rb +1 -1
  57. data/spec/unit/tailor/version_spec.rb +6 -0
  58. data/spec/{tailor_spec.rb → unit/tailor_spec.rb} +1 -1
  59. data/tasks/spec.rake +8 -3
  60. metadata +121 -93
  61. data/features/horizontal_spacing.feature +0 -263
  62. data/features/indentation/bad_files_with_no_trailing_newline.feature +0 -91
  63. data/features/indentation/good_files_with_no_trailing_newline.feature +0 -219
  64. data/features/name_detection.feature +0 -72
  65. data/features/support/file_cases/horizontal_spacing_cases.rb +0 -266
  66. data/features/support/file_cases/naming_cases.rb +0 -51
  67. data/features/vertical_spacing.feature +0 -135
  68. data/m.rb +0 -15
  69. data/spec/tailor/version_spec.rb +0 -6
@@ -283,6 +283,7 @@ when :input
283
283
  "Gimme \#{eval('gets')}!"
284
284
  end}
285
285
 
286
+ =begin
286
287
  INDENT_OK[:case_whens_in] =
287
288
  %Q{def my_method
288
289
  case true
@@ -292,6 +293,7 @@ INDENT_OK[:case_whens_in] =
292
293
  puts "blah blah"
293
294
  end
294
295
  end}
296
+ =end
295
297
 
296
298
  INDENT_OK[:while_do_loop] =
297
299
  %Q{while true do
@@ -610,10 +612,12 @@ INDENT_OK[:multi_line_method_call_ends_with_many_periods] =
610
612
  second_level.
611
613
  third_level}
612
614
 
615
+ =begin
613
616
  INDENT_OK[:method_closing_lonely_paren] =
614
617
  %Q{def your_thing(one
615
618
  )
616
619
  end}
620
+ =end
617
621
 
618
622
  INDENT_OK[:method_lonely_args] =
619
623
  %Q{def your_thing(
@@ -678,11 +682,13 @@ INDENT_OK[:block_in_block_ends_on_same_line] =
678
682
 
679
683
  puts "post ends"}
680
684
 
685
+ =begin
681
686
  INDENT_OK[:rparen_and_do_same_line] =
682
687
  %Q{opt.on('-c', '--config-file FILE',
683
688
  "Use a specific config file.") do |config|
684
689
  options.config_file = config
685
690
  end}
691
+ =end
686
692
 
687
693
  #-------------------------------------------------------------------------------
688
694
  # Single-line keywords
@@ -755,269 +761,3 @@ INDENT_OK[:line_ends_with_label] =
755
761
  actual_trailing_spaces:
756
762
  lexed_line.last_non_line_feed_event.last.size
757
763
  }}
758
-
759
- #-------------------------------------------------------------------------------
760
- # INDENT_1 (1 problem)
761
- #-------------------------------------------------------------------------------
762
- INDENT_1 = {}
763
-
764
- INDENT_1[:class_indented_end] =
765
- %Q{class MyClass
766
- end}
767
-
768
- INDENT_1[:class_indented_singlestatement] =
769
- %Q{class MyClass
770
- include Something
771
- end}
772
-
773
- INDENT_1[:class_indented_singlestatement_trailing_comment] =
774
- %Q{class MyClass
775
- include Something # comment
776
- end}
777
-
778
- INDENT_1[:class_outdented_singlestatement] =
779
- %Q{class MyClass
780
- include Something
781
- end}
782
-
783
- INDENT_1[:def_indented_end] =
784
- %Q{def a
785
- end}
786
-
787
- INDENT_1[:def_content_indented_end] =
788
- %Q{def a
789
- puts "stuff"
790
- end}
791
-
792
- INDENT_1[:class_def_content_outdented_end] =
793
- %Q{class A
794
- def a
795
- puts "stuff"
796
- end
797
- end}
798
-
799
- INDENT_1[:class_def_outdented_content] =
800
- %Q{class A
801
- def a
802
- puts "stuff"
803
- end
804
- end}
805
-
806
- INDENT_1[:class_method_def_using_self_outdented] =
807
- %Q{class A
808
- self.my_method
809
- puts 'stuff'
810
- end
811
- end}
812
-
813
- INDENT_1[:case_indented_whens_level] =
814
- %Q{def my_method
815
- case true
816
- when true
817
- puts "stuff"
818
- when false
819
- puts "blah blah"
820
- end
821
- end}
822
-
823
- INDENT_1[:case_indented_whens_level_trailing_comment] =
824
- %Q{def my_method
825
- case true # comment
826
- when true
827
- puts "stuff"
828
- when false
829
- puts "blah blah"
830
- end
831
- end}
832
-
833
- INDENT_1[:case_outdented_whens_level] =
834
- %Q{def my_method
835
- case true
836
- when true
837
- puts "stuff"
838
- when false
839
- puts "blah blah"
840
- end
841
- end}
842
-
843
- INDENT_1[:case_when_indented_whens_level] =
844
- %Q{def my_method
845
- case true
846
- when true
847
- puts "stuff"
848
- when false
849
- puts "blah blah"
850
- end
851
- end}
852
-
853
- INDENT_1[:case_when_outdented_whens_level] =
854
- %Q{def my_method
855
- case true
856
- when true
857
- puts "stuff"
858
- when false
859
- puts "blah blah"
860
- end
861
- end}
862
-
863
- INDENT_1[:case_indented_whens_in] =
864
- %Q{def my_method
865
- case true
866
- when true
867
- puts "stuff"
868
- when false
869
- puts "blah blah"
870
- end
871
- end}
872
-
873
- INDENT_1[:while_do_indented] =
874
- %Q{ while true do
875
- puts "something"
876
- end}
877
-
878
- INDENT_1[:while_do_outdented] =
879
- %Q{def my_method
880
- while true do
881
- puts "something"
882
- end
883
- end}
884
-
885
- INDENT_1[:while_do_content_outdented] =
886
- %Q{def my_method
887
- while true do
888
- puts "something"
889
- end
890
- end}
891
-
892
- INDENT_1[:while_do_content_indented] =
893
- %Q{def my_method
894
- while true do
895
- puts "something"
896
- end
897
- end}
898
-
899
- INDENT_1[:while_do_indented2] =
900
- %Q{i = 0;
901
- num = 5;
902
-
903
- while i < num do
904
- puts("Inside the loop i = \#{i}" );
905
- i +=1;
906
- end}
907
-
908
- INDENT_1[:while_do_indented2_trailing_comment] =
909
- %Q{i = 0;
910
- num = 5;
911
-
912
- while i < num do # comment
913
- puts("Inside the loop i = \#{i}" );
914
- i +=1;
915
- end}
916
-
917
- INDENT_1[:until_do_indented] =
918
- %Q{i = 0;
919
- num = 5;
920
-
921
- until i > num do
922
- puts("Inside the loop i = \#{i}" );
923
- i +=1;
924
- end}
925
-
926
- INDENT_1[:for_do_indented] =
927
- %Q{ for i in 1..100 do
928
- puts i
929
- end}
930
-
931
- INDENT_1[:loop_do_indented] =
932
- %Q{ loop do
933
- puts 'looping'
934
- end}
935
-
936
- INDENT_1[:multi_line_string_first_line_indented] =
937
- %Q{def a_method
938
- if defined? Term::ANSIColor
939
- message << %Q{# \#{(i + 1).to_s.bold}.
940
- # * position: \#{position}
941
- # * type: \#{problem[:type].to_s.red}
942
- # * message: \#{problem[:message].red}
943
- }
944
- else
945
- message << %Q{# \#{(i + 1)}.
946
- # * position: \#{position}
947
- # * type: \#{problem[:type]}
948
- # * message: \#{problem[:message]}
949
- }
950
- end
951
- end}
952
-
953
- INDENT_1[:multi_line_string_first_line_indented_trailing_comment] =
954
- %Q{def a_method
955
- if defined? Term::ANSIColor # comment
956
- message << %Q{# \#{(i + 1).to_s.bold}.
957
- # * position: \#{position}
958
- # * type: \#{problem[:type].to_s.red}
959
- # * message: \#{problem[:message].red}
960
- }
961
- else
962
- message << %Q{# \#{(i + 1)}.
963
- # * position: \#{position}
964
- # * type: \#{problem[:type]}
965
- # * message: \#{problem[:message]}
966
- }
967
- end
968
- end}
969
-
970
- INDENT_1[:multi_line_tstring] =
971
- %Q{INDENT_OK[:class] =
972
- %Q{class MyClass
973
- end}}
974
-
975
- #-------------------------------------------------------------------------------
976
- # Operators
977
- #-------------------------------------------------------------------------------
978
- INDENT_1[:multi_line_andop_first_line_indented] =
979
- %Q{def end_of_multiline_string?(lexed_line_output)
980
- lexed_line_output.any? { |e| e[1] == :on_tstring_end } &&
981
- lexed_line_output.none? { |e| e[1] == :on_tstring_beg }
982
- end}
983
-
984
- INDENT_1[:multi_line_andop_first_line_indented_trailing_comment] =
985
- %Q{def end_of_multiline_string?(lexed_line_output)
986
- lexed_line_output.any? { |e| e[1] == :on_tstring_end } && # comment
987
- lexed_line_output.none? { |e| e[1] == :on_tstring_beg }
988
- end}
989
-
990
- INDENT_1[:multi_line_andop_second_line_indented] =
991
- %Q{def end_of_multiline_string?(lexed_line_output)
992
- lexed_line_output.any? { |e| e[1] == :on_tstring_end } &&
993
- lexed_line_output.none? { |e| e[1] == :on_tstring_beg }
994
- end}
995
-
996
- INDENT_1[:multi_line_string_concat_with_plus_out] =
997
- %Q{DVR_SSDP_NOTIFICATION_TEMPLATE = File.dirname(__FILE__) +
998
- '/profiles/DVR5000/ssdp_notification.erb'}
999
-
1000
- INDENT_1[:multi_line_method_call_end_in] =
1001
- %Q{def initialize(raw_response)
1002
- if raw_response.nil? || raw_response.empty?
1003
- raise RTSP::Error,
1004
- "#{self.class} received nil string--this shouldn't happen."
1005
- end
1006
- end}
1007
-
1008
- INDENT_1[:multi_line_method_call_ends_with_period_2nd_line_in] =
1009
- %Q{unless streamer == MulticastStreamer.instance
1010
- streamer.state = :DISCONNECTED
1011
- UnicastStreamer.pool << streamer unless UnicastStreamer.pool.
1012
- member? streamer
1013
- end}
1014
-
1015
- INDENT_1[:multi_line_method_call_ends_with_many_periods_last_in] =
1016
- %Q{my_hashie.first_level.
1017
- second_level.
1018
- third_level}
1019
-
1020
- INDENT_1[:multi_line_method_call_ends_with_many_periods_last_in_trailing_comment] =
1021
- %Q{my_hashie.first_level.
1022
- second_level.
1023
- third_level # comment}
@@ -0,0 +1,136 @@
1
+ H_SPACING_OK = {}
2
+
3
+ H_SPACING_OK[:short_line_no_newline] = '#' * 79
4
+ H_SPACING_OK[:short_line_newline_at_81] =
5
+ %Q{'#{'#' * 78}'
6
+ }
7
+
8
+ =begin
9
+ H_SPACING_OK[:line_split_by_backslash] =
10
+ %Q{execute 'myscript' do
11
+ command \\
12
+ '/some/really/long/path/that/would/be/over/eight/chars.sh'
13
+ only_if { something }
14
+ end}
15
+ =end
16
+
17
+ #-------------------------------------------------------------------------------
18
+ # Comma spacing
19
+ #-------------------------------------------------------------------------------
20
+ H_SPACING_OK[:space_after_comma_in_array] = %Q{[1, 2]}
21
+
22
+ H_SPACING_OK[:trailing_comma] = %Q{def thing(one, two,
23
+ three)
24
+ end}
25
+
26
+ H_SPACING_OK[:trailing_comma_with_trailing_comment] =
27
+ %Q{def thing(one, two, # Comment!
28
+ three)
29
+ end}
30
+
31
+ H_SPACING_OK[:no_before_comma_in_array] = %Q{[1, 2]}
32
+ H_SPACING_OK[:line_ends_with_backslash] =
33
+ %Q{{ :thing => a_thing,\\
34
+ :thing2 => another_thing }}
35
+
36
+ #-------------------------------------------------------------------------------
37
+ # Braces
38
+ #-------------------------------------------------------------------------------
39
+ H_SPACING_OK[:empty_hash] = %Q{{}}
40
+ H_SPACING_OK[:single_line_hash] = %Q{{ :one => 'one' }}
41
+ H_SPACING_OK[:single_line_hash_lonely_braces] = %Q{{
42
+ :one => 'one'
43
+ }}
44
+
45
+ H_SPACING_OK[:hash_as_param_in_parens] =
46
+ %Q{add_headers({ content_length: new_body.length })}
47
+
48
+ H_SPACING_OK[:two_line_hash] = %Q{{ :one =>
49
+ 'one' }}
50
+
51
+ H_SPACING_OK[:two_line_hash_trailing_comment] = %Q{{ :one => # comment
52
+ 'one' }}
53
+
54
+ H_SPACING_OK[:three_line_hash] = %Q{{ :one =>
55
+ 'one', :two =>
56
+ 'two' }}
57
+
58
+ H_SPACING_OK[:single_line_block] = %Q{1..10.times { |n| puts number }}
59
+ H_SPACING_OK[:multi_line_braces_block] = %Q{1..10.times { |n|
60
+ puts number }}
61
+
62
+ H_SPACING_OK[:multi_line_qword_using_braces] = %Q{%w{
63
+ foo
64
+ bar
65
+ baz
66
+ }.each do |whatevs|
67
+ bla
68
+ end}
69
+
70
+ H_SPACING_OK[:empty_hash_in_multi_line_statement] =
71
+ %Q{if true
72
+ {}
73
+ end}
74
+
75
+ H_SPACING_OK[:multi_line_hash_in_multi_line_statement] =
76
+ %Q{if true
77
+ options = {
78
+ one: 1
79
+ }
80
+ end}
81
+
82
+ H_SPACING_OK[:single_line_string_interp] = %Q{`\#{IFCONFIG} | grep \#{ip}`}
83
+ H_SPACING_OK[:single_line_block_in_string_interp] =
84
+ %Q{"I did this \#{1..10.times { |n| n }} times."}
85
+
86
+ H_SPACING_OK[:empty_hash_in_string_in_block] =
87
+ %Q{[1].map { |n| { :first => "\#{n}-\#{{}}" } }}
88
+
89
+ H_SPACING_OK[:string_interp_with_colonop] =
90
+ %Q{"\#{::Rails.root}"}
91
+
92
+
93
+
94
+ #-------------------------------------------------------------------------------
95
+ # Brackets
96
+ #-------------------------------------------------------------------------------
97
+ H_SPACING_OK[:empty_array] = %Q{[]}
98
+ H_SPACING_OK[:simple_array] = %Q{[1, 2, 3]}
99
+ H_SPACING_OK[:two_d_array] = %Q{[[1, 2, 3], ['a', 'b', 'c']]}
100
+ H_SPACING_OK[:hash_key_reference] = %Q{thing[:one]}
101
+ H_SPACING_OK[:array_of_symbols] =
102
+ %Q{transition [:active, :reactivated] => :opened}
103
+ H_SPACING_OK[:array_of_hashes] =
104
+ %Q{[ { :one => [[1, 2, 3], ['a', 'b', 'c']] },
105
+ { :two => [[4, 5, 6], ['d', 'e', 'f']] }]}
106
+
107
+ H_SPACING_OK[:simple_array_lonely_brackets] =
108
+ %Q{[
109
+ 1, 2,
110
+ 3
111
+ ]}
112
+
113
+ H_SPACING_OK[:simple_nested_array_lonely_brackets] =
114
+ %Q{def thing
115
+ [
116
+ 1, 2,
117
+ 3
118
+ ]
119
+ end}
120
+
121
+
122
+ H_SPACING_OK[:empty_array_in_multi_line_statement] =
123
+ %Q{if true
124
+ []
125
+ end}
126
+
127
+ #-------------------------------------------------------------------------------
128
+ # Parens
129
+ #-------------------------------------------------------------------------------
130
+ H_SPACING_OK[:empty_parens] = %Q{def thing(); end}
131
+ H_SPACING_OK[:simple_method_call] = %Q{thing(one, two)}
132
+ H_SPACING_OK[:multi_line_method_call] = %Q{thing(one,
133
+ two)}
134
+ H_SPACING_OK[:multi_line_method_call_lonely_parens] = %Q{thing(
135
+ one, two
136
+ )}
@@ -0,0 +1,26 @@
1
+ NAMING_OK = {}
2
+
3
+ NAMING_OK[:single_word_method] =
4
+ %Q{def thing
5
+ end}
6
+
7
+ NAMING_OK[:two_word_method] =
8
+ %Q{def thing_one
9
+ end}
10
+
11
+ #-------------------------------------------------------------------------------
12
+ NAMING_OK[:single_word_class] =
13
+ %Q{class Thing
14
+ end}
15
+
16
+ NAMING_OK[:single_word_module] =
17
+ %Q{module Thing
18
+ end}
19
+
20
+ NAMING_OK[:two_word_class] =
21
+ %Q{class ThingOne
22
+ end}
23
+
24
+ NAMING_OK[:two_word_module] =
25
+ %Q{module ThingOne
26
+ end}