tailor 1.0.1 → 1.1.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.
- data/.tailor +1 -0
- data/Gemfile.lock +1 -1
- data/History.rdoc +34 -0
- data/README.rdoc +17 -1
- data/features/valid_ruby.feature +1 -1
- data/lib/ext/string_ext.rb +0 -4
- data/lib/tailor/cli/options.rb +9 -2
- data/lib/tailor/configuration.rb +103 -150
- data/lib/tailor/configuration/file_set.rb +110 -0
- data/lib/tailor/formatters/text.rb +108 -79
- data/lib/tailor/rake_task.rb +148 -0
- data/lib/tailor/tailorrc.erb +1 -1
- data/lib/tailor/version.rb +1 -1
- data/spec/functional/configuration_spec.rb +244 -0
- data/spec/functional/horizontal_spacing/braces_spec.rb +238 -0
- data/spec/functional/horizontal_spacing/brackets_spec.rb +88 -0
- data/spec/functional/horizontal_spacing/comma_spacing_spec.rb +68 -0
- data/spec/functional/horizontal_spacing/hard_tabs_spec.rb +110 -0
- data/spec/functional/horizontal_spacing/long_lines_spec.rb +51 -0
- data/spec/functional/horizontal_spacing/parens_spec.rb +102 -0
- data/spec/functional/horizontal_spacing/trailing_whitespace_spec.rb +66 -0
- data/spec/functional/horizontal_spacing_spec.rb +59 -0
- data/spec/functional/indentation_spacing/bad_indentation_spec.rb +372 -0
- data/spec/functional/indentation_spacing_spec.rb +85 -0
- data/spec/functional/naming/camel_case_methods_spec.rb +56 -0
- data/spec/functional/naming/screaming_snake_case_classes_spec.rb +83 -0
- data/spec/functional/naming_spec.rb +35 -0
- data/spec/functional/vertical_spacing/class_length_spec.rb +67 -0
- data/spec/functional/vertical_spacing/method_length_spec.rb +61 -0
- data/spec/functional/vertical_spacing_spec.rb +35 -0
- data/spec/support/bad_indentation_cases.rb +265 -0
- data/{features/support/file_cases/indentation_cases.rb → spec/support/good_indentation_cases.rb} +6 -266
- data/spec/support/horizontal_spacing_cases.rb +136 -0
- data/spec/support/naming_cases.rb +26 -0
- data/{features/support/file_cases → spec/support}/vertical_spacing_cases.rb +0 -33
- data/spec/{tailor → unit/tailor}/cli_spec.rb +1 -1
- data/spec/{tailor → unit/tailor}/composite_observable_spec.rb +1 -1
- data/spec/unit/tailor/configuration/file_set_spec.rb +65 -0
- data/spec/{tailor → unit/tailor}/configuration/style_spec.rb +1 -1
- data/spec/{tailor → unit/tailor}/configuration_spec.rb +1 -59
- data/spec/{tailor → unit/tailor}/critic_spec.rb +1 -1
- data/spec/{tailor → unit/tailor}/formatter_spec.rb +1 -1
- data/spec/{tailor → unit/tailor}/lexed_line_spec.rb +1 -1
- data/spec/{tailor → unit/tailor}/lexer/token_spec.rb +1 -1
- data/spec/{tailor → unit/tailor}/lexer_spec.rb +1 -2
- data/spec/{tailor → unit/tailor}/options_spec.rb +1 -1
- data/spec/{tailor → unit/tailor}/problem_spec.rb +1 -1
- data/spec/{tailor → unit/tailor}/reporter_spec.rb +1 -1
- data/spec/{tailor → unit/tailor}/ruler_spec.rb +1 -1
- data/spec/{tailor → unit/tailor}/rulers/indentation_spaces_ruler/indentation_manager_spec.rb +1 -1
- data/spec/{tailor → unit/tailor}/rulers/indentation_spaces_ruler_spec.rb +1 -1
- data/spec/{tailor → unit/tailor}/rulers/spaces_after_comma_ruler_spec.rb +1 -1
- data/spec/{tailor → unit/tailor}/rulers/spaces_after_lbrace_ruler_spec.rb +1 -1
- data/spec/{tailor → unit/tailor}/rulers/spaces_before_lbrace_ruler_spec.rb +1 -1
- data/spec/{tailor → unit/tailor}/rulers/spaces_before_rbrace_ruler_spec.rb +1 -1
- data/spec/{tailor → unit/tailor}/rulers_spec.rb +1 -1
- data/spec/unit/tailor/version_spec.rb +6 -0
- data/spec/{tailor_spec.rb → unit/tailor_spec.rb} +1 -1
- data/tasks/spec.rake +8 -3
- metadata +121 -93
- data/features/horizontal_spacing.feature +0 -263
- data/features/indentation/bad_files_with_no_trailing_newline.feature +0 -91
- data/features/indentation/good_files_with_no_trailing_newline.feature +0 -219
- data/features/name_detection.feature +0 -72
- data/features/support/file_cases/horizontal_spacing_cases.rb +0 -266
- data/features/support/file_cases/naming_cases.rb +0 -51
- data/features/vertical_spacing.feature +0 -135
- data/m.rb +0 -15
- data/spec/tailor/version_spec.rb +0 -6
@@ -0,0 +1,59 @@
|
|
1
|
+
require_relative '../spec_helper'
|
2
|
+
require_relative '../support/horizontal_spacing_cases'
|
3
|
+
require 'tailor/critic'
|
4
|
+
require 'tailor/configuration/style'
|
5
|
+
|
6
|
+
describe "Horizontal Space problem detection" do
|
7
|
+
before do
|
8
|
+
Tailor::Logger.stub(:log)
|
9
|
+
FakeFS.activate!
|
10
|
+
end
|
11
|
+
|
12
|
+
let(:critic) do
|
13
|
+
Tailor::Critic.new
|
14
|
+
end
|
15
|
+
|
16
|
+
let(:style) do
|
17
|
+
style = Tailor::Configuration::Style.new
|
18
|
+
style.trailing_newlines 0, level: :off
|
19
|
+
style.allow_invalid_ruby true, level: :off
|
20
|
+
|
21
|
+
style
|
22
|
+
end
|
23
|
+
|
24
|
+
H_SPACING_OK.each do |file_name, contents|
|
25
|
+
before do
|
26
|
+
FileUtils.touch file_name.to_s
|
27
|
+
File.open(file_name.to_s, 'w') { |f| f.write contents }
|
28
|
+
end
|
29
|
+
|
30
|
+
it "should be OK" do
|
31
|
+
critic.check_file(file_name.to_s, style.to_hash)
|
32
|
+
critic.problems.should == { file_name.to_s => [] }
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
context "line ends with a backslash" do
|
37
|
+
let(:file_name) { :line_split_by_backslash }
|
38
|
+
|
39
|
+
let(:contents) do
|
40
|
+
%Q{execute 'myscript' do
|
41
|
+
command \\
|
42
|
+
'/some/really/long/path/that/would/be/over/eighty/chars.sh'
|
43
|
+
only_if { something }
|
44
|
+
end}
|
45
|
+
end
|
46
|
+
|
47
|
+
before do
|
48
|
+
FileUtils.touch file_name.to_s
|
49
|
+
File.open(file_name.to_s, 'w') { |f| f.write contents }
|
50
|
+
end
|
51
|
+
|
52
|
+
it "is OK" do
|
53
|
+
pending "Fix of gh-101"
|
54
|
+
|
55
|
+
critic.check_file(file_name.to_s, style.to_hash)
|
56
|
+
critic.problems.should == { file_name.to_s => [] }
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
@@ -0,0 +1,372 @@
|
|
1
|
+
require_relative '../../spec_helper'
|
2
|
+
require_relative '../../support/bad_indentation_cases'
|
3
|
+
require 'tailor/critic'
|
4
|
+
require 'tailor/configuration/style'
|
5
|
+
|
6
|
+
|
7
|
+
describe "Detection of method length" do
|
8
|
+
before do
|
9
|
+
Tailor::Logger.stub(:log)
|
10
|
+
FakeFS.activate!
|
11
|
+
File.open(file_name.to_s, 'w') { |f| f.write contents }
|
12
|
+
critic.check_file(file_name.to_s, style.to_hash)
|
13
|
+
end
|
14
|
+
|
15
|
+
let(:critic) do
|
16
|
+
Tailor::Critic.new
|
17
|
+
end
|
18
|
+
|
19
|
+
let(:contents) { INDENT_1[file_name] }
|
20
|
+
|
21
|
+
let(:style) do
|
22
|
+
style = Tailor::Configuration::Style.new
|
23
|
+
style.trailing_newlines 0, level: :off
|
24
|
+
style.allow_invalid_ruby true, level: :off
|
25
|
+
|
26
|
+
style
|
27
|
+
end
|
28
|
+
|
29
|
+
context "simple classes" do
|
30
|
+
context "empty with an indented end" do
|
31
|
+
let(:file_name) { :class_indented_end }
|
32
|
+
specify { critic.problems[file_name.to_s].size.should be 1 }
|
33
|
+
specify { critic.problems[file_name.to_s].first[:type].should == "indentation_spaces" }
|
34
|
+
specify { critic.problems[file_name.to_s].first[:line].should be 2 }
|
35
|
+
specify { critic.problems[file_name.to_s].first[:column].should be 1 }
|
36
|
+
specify { critic.problems[file_name.to_s].first[:level].should be :error }
|
37
|
+
end
|
38
|
+
|
39
|
+
context "body extra indented" do
|
40
|
+
let(:file_name) { :class_indented_single_statement }
|
41
|
+
specify { critic.problems[file_name.to_s].size.should be 1 }
|
42
|
+
specify { critic.problems[file_name.to_s].first[:type].should == "indentation_spaces" }
|
43
|
+
specify { critic.problems[file_name.to_s].first[:line].should be 2 }
|
44
|
+
specify { critic.problems[file_name.to_s].first[:column].should be 3 }
|
45
|
+
specify { critic.problems[file_name.to_s].first[:level].should be :error }
|
46
|
+
end
|
47
|
+
|
48
|
+
context "body extra indented, trailing comment" do
|
49
|
+
let(:file_name) { :class_indented_single_statement_trailing_comment }
|
50
|
+
specify { critic.problems[file_name.to_s].size.should be 1 }
|
51
|
+
specify { critic.problems[file_name.to_s].first[:type].should == "indentation_spaces" }
|
52
|
+
specify { critic.problems[file_name.to_s].first[:line].should be 2 }
|
53
|
+
specify { critic.problems[file_name.to_s].first[:column].should be 3 }
|
54
|
+
specify { critic.problems[file_name.to_s].first[:level].should be :error }
|
55
|
+
end
|
56
|
+
|
57
|
+
context "body extra outdented" do
|
58
|
+
let(:file_name) { :class_outdented_single_statement }
|
59
|
+
specify { critic.problems[file_name.to_s].size.should be 1 }
|
60
|
+
specify { critic.problems[file_name.to_s].first[:type].should == "indentation_spaces" }
|
61
|
+
specify { critic.problems[file_name.to_s].first[:line].should be 2 }
|
62
|
+
specify { critic.problems[file_name.to_s].first[:column].should be 1 }
|
63
|
+
specify { critic.problems[file_name.to_s].first[:level].should be :error }
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
context "simple methods" do
|
68
|
+
context "empty with an indented end" do
|
69
|
+
let(:file_name) { :def_indented_end }
|
70
|
+
specify { critic.problems[file_name.to_s].size.should be 1 }
|
71
|
+
specify { critic.problems[file_name.to_s].first[:type].should == "indentation_spaces" }
|
72
|
+
specify { critic.problems[file_name.to_s].first[:line].should be 2 }
|
73
|
+
specify { critic.problems[file_name.to_s].first[:column].should be 1 }
|
74
|
+
specify { critic.problems[file_name.to_s].first[:level].should be :error }
|
75
|
+
end
|
76
|
+
|
77
|
+
context "body and end extra indented" do
|
78
|
+
let(:file_name) { :def_content_indented_end }
|
79
|
+
specify { critic.problems[file_name.to_s].size.should be 1 }
|
80
|
+
specify { critic.problems[file_name.to_s].first[:type].should == "indentation_spaces" }
|
81
|
+
specify { critic.problems[file_name.to_s].first[:line].should be 3 }
|
82
|
+
specify { critic.problems[file_name.to_s].first[:column].should be 1 }
|
83
|
+
specify { critic.problems[file_name.to_s].first[:level].should be :error }
|
84
|
+
end
|
85
|
+
|
86
|
+
context "in a class, end outdented" do
|
87
|
+
let(:file_name) { :class_def_content_outdented_end }
|
88
|
+
specify { critic.problems[file_name.to_s].size.should be 1 }
|
89
|
+
specify { critic.problems[file_name.to_s].first[:type].should == "indentation_spaces" }
|
90
|
+
specify { critic.problems[file_name.to_s].first[:line].should be 4 }
|
91
|
+
specify { critic.problems[file_name.to_s].first[:column].should be 1 }
|
92
|
+
specify { critic.problems[file_name.to_s].first[:level].should be :error }
|
93
|
+
end
|
94
|
+
|
95
|
+
context "in a class, body outdented" do
|
96
|
+
let(:file_name) { :class_def_outdented_content }
|
97
|
+
specify { critic.problems[file_name.to_s].size.should be 1 }
|
98
|
+
specify { critic.problems[file_name.to_s].first[:type].should == "indentation_spaces" }
|
99
|
+
specify { critic.problems[file_name.to_s].first[:line].should be 3 }
|
100
|
+
specify { critic.problems[file_name.to_s].first[:column].should be 3 }
|
101
|
+
specify { critic.problems[file_name.to_s].first[:level].should be :error }
|
102
|
+
end
|
103
|
+
|
104
|
+
context "class method outdented, in a class" do
|
105
|
+
let(:file_name) { :class_method_def_using_self_outdented }
|
106
|
+
specify do
|
107
|
+
pending "Fix of gh-109"
|
108
|
+
critic.problems[file_name.to_s].size.should be 1
|
109
|
+
end
|
110
|
+
=begin
|
111
|
+
specify { critic.problems[file_name.to_s].first[:type].should == "indentation_spaces" }
|
112
|
+
specify { critic.problems[file_name.to_s].first[:line].should be 2 }
|
113
|
+
specify { critic.problems[file_name.to_s].first[:column].should be 1 }
|
114
|
+
specify { critic.problems[file_name.to_s].first[:level].should be :error }
|
115
|
+
=end
|
116
|
+
end
|
117
|
+
end
|
118
|
+
|
119
|
+
context "case statements" do
|
120
|
+
context "case extra indented" do
|
121
|
+
let(:file_name) { :case_indented_whens_level }
|
122
|
+
specify { critic.problems[file_name.to_s].size.should be 1 }
|
123
|
+
specify { critic.problems[file_name.to_s].first[:type].should == "indentation_spaces" }
|
124
|
+
specify { critic.problems[file_name.to_s].first[:line].should be 2 }
|
125
|
+
specify { critic.problems[file_name.to_s].first[:column].should be 3 }
|
126
|
+
specify { critic.problems[file_name.to_s].first[:level].should be :error }
|
127
|
+
end
|
128
|
+
|
129
|
+
context "case extra indented, trailing comment" do
|
130
|
+
let(:file_name) { :case_indented_whens_level_trailing_comment }
|
131
|
+
specify { critic.problems[file_name.to_s].size.should be 1 }
|
132
|
+
specify { critic.problems[file_name.to_s].first[:type].should == "indentation_spaces" }
|
133
|
+
specify { critic.problems[file_name.to_s].first[:line].should be 2 }
|
134
|
+
specify { critic.problems[file_name.to_s].first[:column].should be 3 }
|
135
|
+
specify { critic.problems[file_name.to_s].first[:level].should be :error }
|
136
|
+
end
|
137
|
+
|
138
|
+
context "case extra outdented" do
|
139
|
+
let(:file_name) { :case_outdented_whens_level }
|
140
|
+
specify { critic.problems[file_name.to_s].size.should be 1 }
|
141
|
+
specify { critic.problems[file_name.to_s].first[:type].should == "indentation_spaces" }
|
142
|
+
specify { critic.problems[file_name.to_s].first[:line].should be 2 }
|
143
|
+
specify { critic.problems[file_name.to_s].first[:column].should be 1 }
|
144
|
+
specify { critic.problems[file_name.to_s].first[:level].should be :error }
|
145
|
+
end
|
146
|
+
|
147
|
+
context "when extra intdented" do
|
148
|
+
let(:file_name) { :case_when_indented_whens_level }
|
149
|
+
specify { critic.problems[file_name.to_s].size.should be 1 }
|
150
|
+
specify { critic.problems[file_name.to_s].first[:type].should == "indentation_spaces" }
|
151
|
+
specify { critic.problems[file_name.to_s].first[:line].should be 3 }
|
152
|
+
specify { critic.problems[file_name.to_s].first[:column].should be 3 }
|
153
|
+
specify { critic.problems[file_name.to_s].first[:level].should be :error }
|
154
|
+
end
|
155
|
+
|
156
|
+
context "when extra outdented" do
|
157
|
+
let(:file_name) { :case_when_outdented_whens_level }
|
158
|
+
specify { critic.problems[file_name.to_s].size.should be 1 }
|
159
|
+
specify { critic.problems[file_name.to_s].first[:type].should == "indentation_spaces" }
|
160
|
+
specify { critic.problems[file_name.to_s].first[:line].should be 3 }
|
161
|
+
specify { critic.problems[file_name.to_s].first[:column].should be 1 }
|
162
|
+
specify { critic.problems[file_name.to_s].first[:level].should be :error }
|
163
|
+
end
|
164
|
+
|
165
|
+
context "case extra indented" do
|
166
|
+
pending "Implementation of option to allow whens in"
|
167
|
+
|
168
|
+
=begin
|
169
|
+
let(:file_name) { :case_indented_whens_in }
|
170
|
+
specify { critic.problems[file_name.to_s].size.should be 1 }
|
171
|
+
specify { critic.problems[file_name.to_s].first[:type].should == "indentation_spaces" }
|
172
|
+
specify { critic.problems[file_name.to_s].first[:line].should be 2 }
|
173
|
+
specify { critic.problems[file_name.to_s].first[:column].should be 1 }
|
174
|
+
specify { critic.problems[file_name.to_s].first[:level].should be :error }
|
175
|
+
=end
|
176
|
+
end
|
177
|
+
end
|
178
|
+
|
179
|
+
context "while/do loops" do
|
180
|
+
context "while/do indented" do
|
181
|
+
let(:file_name) { :while_do_indented }
|
182
|
+
specify { critic.problems[file_name.to_s].size.should be 1 }
|
183
|
+
specify { critic.problems[file_name.to_s].first[:type].should == "indentation_spaces" }
|
184
|
+
specify { critic.problems[file_name.to_s].first[:line].should be 1 }
|
185
|
+
specify { critic.problems[file_name.to_s].first[:column].should be 1 }
|
186
|
+
specify { critic.problems[file_name.to_s].first[:level].should be :error }
|
187
|
+
end
|
188
|
+
|
189
|
+
context "while/do outdented" do
|
190
|
+
let(:file_name) { :while_do_outdented }
|
191
|
+
specify { critic.problems[file_name.to_s].size.should be 1 }
|
192
|
+
specify { critic.problems[file_name.to_s].first[:type].should == "indentation_spaces" }
|
193
|
+
specify { critic.problems[file_name.to_s].first[:line].should be 2 }
|
194
|
+
specify { critic.problems[file_name.to_s].first[:column].should be 1 }
|
195
|
+
specify { critic.problems[file_name.to_s].first[:level].should be :error }
|
196
|
+
end
|
197
|
+
|
198
|
+
context "while/do content outdented" do
|
199
|
+
let(:file_name) { :while_do_content_outdented }
|
200
|
+
specify { critic.problems[file_name.to_s].size.should be 1 }
|
201
|
+
specify { critic.problems[file_name.to_s].first[:type].should == "indentation_spaces" }
|
202
|
+
specify { critic.problems[file_name.to_s].first[:line].should be 3 }
|
203
|
+
specify { critic.problems[file_name.to_s].first[:column].should be 3 }
|
204
|
+
specify { critic.problems[file_name.to_s].first[:level].should be :error }
|
205
|
+
end
|
206
|
+
|
207
|
+
context "while/do content indented" do
|
208
|
+
let(:file_name) { :while_do_content_indented }
|
209
|
+
specify { critic.problems[file_name.to_s].size.should be 1 }
|
210
|
+
specify { critic.problems[file_name.to_s].first[:type].should == "indentation_spaces" }
|
211
|
+
specify { critic.problems[file_name.to_s].first[:line].should be 3 }
|
212
|
+
specify { critic.problems[file_name.to_s].first[:column].should be 5 }
|
213
|
+
specify { critic.problems[file_name.to_s].first[:level].should be :error }
|
214
|
+
end
|
215
|
+
|
216
|
+
context "another while/do indented" do
|
217
|
+
let(:file_name) { :while_do_indented2 }
|
218
|
+
specify { critic.problems[file_name.to_s].size.should be 1 }
|
219
|
+
specify { critic.problems[file_name.to_s].first[:type].should == "indentation_spaces" }
|
220
|
+
specify { critic.problems[file_name.to_s].first[:line].should be 4 }
|
221
|
+
specify { critic.problems[file_name.to_s].first[:column].should be 1 }
|
222
|
+
specify { critic.problems[file_name.to_s].first[:level].should be :error }
|
223
|
+
end
|
224
|
+
|
225
|
+
context "another while/do indented, trailing comment" do
|
226
|
+
let(:file_name) { :while_do_indented2_trailing_comment }
|
227
|
+
specify { critic.problems[file_name.to_s].size.should be 1 }
|
228
|
+
specify { critic.problems[file_name.to_s].first[:type].should == "indentation_spaces" }
|
229
|
+
specify { critic.problems[file_name.to_s].first[:line].should be 4 }
|
230
|
+
specify { critic.problems[file_name.to_s].first[:column].should be 1 }
|
231
|
+
specify { critic.problems[file_name.to_s].first[:level].should be :error }
|
232
|
+
end
|
233
|
+
end
|
234
|
+
|
235
|
+
context "until/do loops" do
|
236
|
+
context "until indented" do
|
237
|
+
let(:file_name) { :until_do_indented }
|
238
|
+
specify { critic.problems[file_name.to_s].size.should be 1 }
|
239
|
+
specify { critic.problems[file_name.to_s].first[:type].should == "indentation_spaces" }
|
240
|
+
specify { critic.problems[file_name.to_s].first[:line].should be 4 }
|
241
|
+
specify { critic.problems[file_name.to_s].first[:column].should be 1 }
|
242
|
+
specify { critic.problems[file_name.to_s].first[:level].should be :error }
|
243
|
+
end
|
244
|
+
end
|
245
|
+
|
246
|
+
context "for/do loops" do
|
247
|
+
context "for indented" do
|
248
|
+
let(:file_name) { :for_do_indented }
|
249
|
+
specify { critic.problems[file_name.to_s].size.should be 1 }
|
250
|
+
specify { critic.problems[file_name.to_s].first[:type].should == "indentation_spaces" }
|
251
|
+
specify { critic.problems[file_name.to_s].first[:line].should be 1 }
|
252
|
+
specify { critic.problems[file_name.to_s].first[:column].should be 1 }
|
253
|
+
specify { critic.problems[file_name.to_s].first[:level].should be :error }
|
254
|
+
end
|
255
|
+
end
|
256
|
+
|
257
|
+
context "loop/do loops" do
|
258
|
+
context "loop indented" do
|
259
|
+
let(:file_name) { :loop_do_indented }
|
260
|
+
specify { critic.problems[file_name.to_s].size.should be 1 }
|
261
|
+
specify { critic.problems[file_name.to_s].first[:type].should == "indentation_spaces" }
|
262
|
+
specify { critic.problems[file_name.to_s].first[:line].should be 1 }
|
263
|
+
specify { critic.problems[file_name.to_s].first[:column].should be 1 }
|
264
|
+
specify { critic.problems[file_name.to_s].first[:level].should be :error }
|
265
|
+
end
|
266
|
+
end
|
267
|
+
|
268
|
+
context "if statements" do
|
269
|
+
context "first line extra indented" do
|
270
|
+
let(:file_name) { :if_line_indented }
|
271
|
+
specify { critic.problems[file_name.to_s].size.should be 1 }
|
272
|
+
specify { critic.problems[file_name.to_s].first[:type].should == "indentation_spaces" }
|
273
|
+
specify { critic.problems[file_name.to_s].first[:line].should be 2 }
|
274
|
+
specify { critic.problems[file_name.to_s].first[:column].should be 3 }
|
275
|
+
specify { critic.problems[file_name.to_s].first[:level].should be :error }
|
276
|
+
end
|
277
|
+
|
278
|
+
context "first line extra indented, trailing comment" do
|
279
|
+
let(:file_name) { :if_line_indented_trailing_comment }
|
280
|
+
specify { critic.problems[file_name.to_s].size.should be 1 }
|
281
|
+
specify { critic.problems[file_name.to_s].first[:type].should == "indentation_spaces" }
|
282
|
+
specify { critic.problems[file_name.to_s].first[:line].should be 2 }
|
283
|
+
specify { critic.problems[file_name.to_s].first[:column].should be 3 }
|
284
|
+
specify { critic.problems[file_name.to_s].first[:level].should be :error }
|
285
|
+
end
|
286
|
+
end
|
287
|
+
|
288
|
+
context "multi_line_tstring" do
|
289
|
+
let(:file_name) { :multi_line_tstring }
|
290
|
+
specify { critic.problems[file_name.to_s].size.should be 1 }
|
291
|
+
specify { critic.problems[file_name.to_s].first[:type].should == "indentation_spaces" }
|
292
|
+
specify { critic.problems[file_name.to_s].first[:line].should be 2 }
|
293
|
+
specify { critic.problems[file_name.to_s].first[:column].should be 0 }
|
294
|
+
specify { critic.problems[file_name.to_s].first[:level].should be :error }
|
295
|
+
end
|
296
|
+
|
297
|
+
context "operators" do
|
298
|
+
context "multi-line &&, first line indented" do
|
299
|
+
let(:file_name) { :multi_line_andop_first_line_indented }
|
300
|
+
specify { critic.problems[file_name.to_s].size.should be 1 }
|
301
|
+
specify { critic.problems[file_name.to_s].first[:type].should == "indentation_spaces" }
|
302
|
+
specify { critic.problems[file_name.to_s].first[:line].should be 2 }
|
303
|
+
specify { critic.problems[file_name.to_s].first[:column].should be 3 }
|
304
|
+
specify { critic.problems[file_name.to_s].first[:level].should be :error }
|
305
|
+
end
|
306
|
+
|
307
|
+
context "multi-line &&, first line indented, trailing comment" do
|
308
|
+
let(:file_name) { :multi_line_andop_first_line_indented_trailing_comment }
|
309
|
+
specify { critic.problems[file_name.to_s].size.should be 1 }
|
310
|
+
specify { critic.problems[file_name.to_s].first[:type].should == "indentation_spaces" }
|
311
|
+
specify { critic.problems[file_name.to_s].first[:line].should be 2 }
|
312
|
+
specify { critic.problems[file_name.to_s].first[:column].should be 3 }
|
313
|
+
specify { critic.problems[file_name.to_s].first[:level].should be :error }
|
314
|
+
end
|
315
|
+
|
316
|
+
context "multi-line &&, second line indented" do
|
317
|
+
let(:file_name) { :multi_line_andop_second_line_indented }
|
318
|
+
specify { critic.problems[file_name.to_s].size.should be 1 }
|
319
|
+
specify { critic.problems[file_name.to_s].first[:type].should == "indentation_spaces" }
|
320
|
+
specify { critic.problems[file_name.to_s].first[:line].should be 3 }
|
321
|
+
specify { critic.problems[file_name.to_s].first[:column].should be 5 }
|
322
|
+
specify { critic.problems[file_name.to_s].first[:level].should be :error }
|
323
|
+
end
|
324
|
+
|
325
|
+
context "multi-line string concat, second line outdented" do
|
326
|
+
let(:file_name) { :multi_line_string_concat_with_plus_out }
|
327
|
+
specify { critic.problems[file_name.to_s].size.should be 1 }
|
328
|
+
specify { critic.problems[file_name.to_s].first[:type].should == "indentation_spaces" }
|
329
|
+
specify { critic.problems[file_name.to_s].first[:line].should be 2 }
|
330
|
+
specify { critic.problems[file_name.to_s].first[:column].should be 1 }
|
331
|
+
specify { critic.problems[file_name.to_s].first[:level].should be :error }
|
332
|
+
end
|
333
|
+
end
|
334
|
+
|
335
|
+
context "combinations of stuff" do
|
336
|
+
context "multi-line if with end in" do
|
337
|
+
let(:file_name) { :multi_line_method_call_end_in }
|
338
|
+
specify { critic.problems[file_name.to_s].size.should be 1 }
|
339
|
+
specify { critic.problems[file_name.to_s].first[:type].should == "indentation_spaces" }
|
340
|
+
specify { critic.problems[file_name.to_s].first[:line].should be 5 }
|
341
|
+
specify { critic.problems[file_name.to_s].first[:column].should be 3 }
|
342
|
+
specify { critic.problems[file_name.to_s].first[:level].should be :error }
|
343
|
+
end
|
344
|
+
|
345
|
+
context "multi-line chained methods with 2nd line in" do
|
346
|
+
let(:file_name) { :multi_line_method_call_ends_with_period_2nd_line_in }
|
347
|
+
specify { critic.problems[file_name.to_s].size.should be 1 }
|
348
|
+
specify { critic.problems[file_name.to_s].first[:type].should == "indentation_spaces" }
|
349
|
+
specify { critic.problems[file_name.to_s].first[:line].should be 4 }
|
350
|
+
specify { critic.problems[file_name.to_s].first[:column].should be 5 }
|
351
|
+
specify { critic.problems[file_name.to_s].first[:level].should be :error }
|
352
|
+
end
|
353
|
+
|
354
|
+
context "multi-line chained methods with 3rd line in" do
|
355
|
+
let(:file_name) { :multi_line_method_call_ends_with_many_periods_last_in }
|
356
|
+
specify { critic.problems[file_name.to_s].size.should be 1 }
|
357
|
+
specify { critic.problems[file_name.to_s].first[:type].should == "indentation_spaces" }
|
358
|
+
specify { critic.problems[file_name.to_s].first[:line].should be 3 }
|
359
|
+
specify { critic.problems[file_name.to_s].first[:column].should be 4 }
|
360
|
+
specify { critic.problems[file_name.to_s].first[:level].should be :error }
|
361
|
+
end
|
362
|
+
|
363
|
+
context "multi-line chained methods with 3rd line in, trailing comment" do
|
364
|
+
let(:file_name) { :multi_line_method_call_ends_with_many_periods_last_in_trailing_comment }
|
365
|
+
specify { critic.problems[file_name.to_s].size.should be 1 }
|
366
|
+
specify { critic.problems[file_name.to_s].first[:type].should == "indentation_spaces" }
|
367
|
+
specify { critic.problems[file_name.to_s].first[:line].should be 3 }
|
368
|
+
specify { critic.problems[file_name.to_s].first[:column].should be 4 }
|
369
|
+
specify { critic.problems[file_name.to_s].first[:level].should be :error }
|
370
|
+
end
|
371
|
+
end
|
372
|
+
end
|
@@ -0,0 +1,85 @@
|
|
1
|
+
require_relative '../spec_helper'
|
2
|
+
require_relative '../support/good_indentation_cases'
|
3
|
+
require 'tailor/critic'
|
4
|
+
require 'tailor/configuration/style'
|
5
|
+
|
6
|
+
describe "Indentation spacing problem detection" do
|
7
|
+
before do
|
8
|
+
Tailor::Logger.stub(:log)
|
9
|
+
FakeFS.activate!
|
10
|
+
end
|
11
|
+
|
12
|
+
let(:critic) do
|
13
|
+
Tailor::Critic.new
|
14
|
+
end
|
15
|
+
|
16
|
+
let(:style) do
|
17
|
+
style = Tailor::Configuration::Style.new
|
18
|
+
style.trailing_newlines 0, level: :off
|
19
|
+
style.allow_invalid_ruby true, level: :off
|
20
|
+
|
21
|
+
style
|
22
|
+
end
|
23
|
+
|
24
|
+
let(:contents) { INDENT_1[file_name] }
|
25
|
+
|
26
|
+
INDENT_OK.each do |file_name, contents|
|
27
|
+
before do
|
28
|
+
FileUtils.touch file_name.to_s
|
29
|
+
File.open(file_name.to_s, 'w') { |f| f.write contents }
|
30
|
+
end
|
31
|
+
|
32
|
+
it "should be OK" do
|
33
|
+
critic.check_file(file_name.to_s, style.to_hash)
|
34
|
+
critic.problems.should == { file_name.to_s => [] }
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
context "case statement with indented whens" do
|
39
|
+
let(:file_name) { :case_whens_in }
|
40
|
+
|
41
|
+
let(:contents) do
|
42
|
+
%Q{def my_method
|
43
|
+
case true
|
44
|
+
when true
|
45
|
+
puts "stuff"
|
46
|
+
when false
|
47
|
+
puts "blah blah"
|
48
|
+
end
|
49
|
+
end}
|
50
|
+
end
|
51
|
+
|
52
|
+
it "is OK" do
|
53
|
+
pending "Implementation of the option to allow for this"
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
context "method with rparen on following line" do
|
58
|
+
let(:file_name) { :method_closing_lonely_paren }
|
59
|
+
|
60
|
+
let(:contents) do
|
61
|
+
%Q{def your_thing(one
|
62
|
+
)
|
63
|
+
end}
|
64
|
+
end
|
65
|
+
|
66
|
+
it "is OK" do
|
67
|
+
pending
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
context "lonely rparen and do on the same line" do
|
72
|
+
let(:file_name) { :rparen_and_do_same_line }
|
73
|
+
|
74
|
+
let(:contents) do
|
75
|
+
%Q{opt.on('-c', '--config-file FILE',
|
76
|
+
"Use a specific config file.") do |config|
|
77
|
+
options.config_file = config
|
78
|
+
end}
|
79
|
+
end
|
80
|
+
|
81
|
+
it "is OK" do
|
82
|
+
pending
|
83
|
+
end
|
84
|
+
end
|
85
|
+
end
|