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,88 @@
|
|
1
|
+
require_relative '../../spec_helper'
|
2
|
+
require 'tailor/critic'
|
3
|
+
require 'tailor/configuration/style'
|
4
|
+
|
5
|
+
|
6
|
+
BRACKETS = {}
|
7
|
+
BRACKETS[:space_in_empty_array] = %Q{[ ]}
|
8
|
+
BRACKETS[:simple_array_space_after_lbracket] = %Q{[ 1, 2, 3]}
|
9
|
+
BRACKETS[:simple_array_space_before_rbracket] = %Q{[1, 2, 3 ]}
|
10
|
+
BRACKETS[:hash_key_ref_space_before_rbracket] = %Q{thing[:one ]}
|
11
|
+
BRACKETS[:hash_key_ref_space_after_lbracket] = %Q{thing[ :one]}
|
12
|
+
BRACKETS[:two_d_array_space_after_lbrackets] =
|
13
|
+
%Q{[ [1, 2, 3], [ 'a', 'b', 'c']]}
|
14
|
+
BRACKETS[:two_d_array_space_before_rbrackets] =
|
15
|
+
%Q{[[1, 2, 3 ], [ 'a', 'b', 'c'] ]}
|
16
|
+
|
17
|
+
|
18
|
+
describe "Detection of spaces around brackets" do
|
19
|
+
before do
|
20
|
+
Tailor::Logger.stub(:log)
|
21
|
+
FakeFS.activate!
|
22
|
+
File.open(file_name.to_s, 'w') { |f| f.write contents }
|
23
|
+
critic.check_file(file_name.to_s, style.to_hash)
|
24
|
+
end
|
25
|
+
|
26
|
+
let(:critic) do
|
27
|
+
Tailor::Critic.new
|
28
|
+
end
|
29
|
+
|
30
|
+
let(:contents) { BRACKETS[file_name]}
|
31
|
+
|
32
|
+
let(:style) do
|
33
|
+
style = Tailor::Configuration::Style.new
|
34
|
+
style.trailing_newlines 0, level: :off
|
35
|
+
style.allow_invalid_ruby true, level: :off
|
36
|
+
|
37
|
+
style
|
38
|
+
end
|
39
|
+
|
40
|
+
context "Arrays" do
|
41
|
+
context "empty with space inside" do
|
42
|
+
let(:file_name) { :space_in_empty_array }
|
43
|
+
specify { critic.problems[file_name.to_s].size.should be 1 }
|
44
|
+
specify { critic.problems[file_name.to_s].first[:type].should == "spaces_after_lbracket" }
|
45
|
+
specify { critic.problems[file_name.to_s].first[:line].should be 1 }
|
46
|
+
specify { critic.problems[file_name.to_s].first[:column].should be 1 }
|
47
|
+
specify { critic.problems[file_name.to_s].first[:level].should be :error }
|
48
|
+
end
|
49
|
+
|
50
|
+
context "space after lbracket" do
|
51
|
+
let(:file_name) { :simple_array_space_after_lbracket }
|
52
|
+
specify { critic.problems[file_name.to_s].size.should be 1 }
|
53
|
+
specify { critic.problems[file_name.to_s].first[:type].should == "spaces_after_lbracket" }
|
54
|
+
specify { critic.problems[file_name.to_s].first[:line].should be 1 }
|
55
|
+
specify { critic.problems[file_name.to_s].first[:column].should be 1 }
|
56
|
+
specify { critic.problems[file_name.to_s].first[:level].should be :error }
|
57
|
+
end
|
58
|
+
|
59
|
+
context "space before rbracket" do
|
60
|
+
let(:file_name) { :simple_array_space_before_rbracket }
|
61
|
+
specify { critic.problems[file_name.to_s].size.should be 1 }
|
62
|
+
specify { critic.problems[file_name.to_s].first[:type].should == "spaces_before_rbracket" }
|
63
|
+
specify { critic.problems[file_name.to_s].first[:line].should be 1 }
|
64
|
+
specify { critic.problems[file_name.to_s].first[:column].should be 9 }
|
65
|
+
specify { critic.problems[file_name.to_s].first[:level].should be :error }
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
context "Hash key references" do
|
70
|
+
context "space before rbracket" do
|
71
|
+
let(:file_name) { :hash_key_ref_space_before_rbracket }
|
72
|
+
specify { critic.problems[file_name.to_s].size.should be 1 }
|
73
|
+
specify { critic.problems[file_name.to_s].first[:type].should == "spaces_before_rbracket" }
|
74
|
+
specify { critic.problems[file_name.to_s].first[:line].should be 1 }
|
75
|
+
specify { critic.problems[file_name.to_s].first[:column].should be 11 }
|
76
|
+
specify { critic.problems[file_name.to_s].first[:level].should be :error }
|
77
|
+
end
|
78
|
+
|
79
|
+
context "space after lbracket" do
|
80
|
+
let(:file_name) { :hash_key_ref_space_after_lbracket }
|
81
|
+
specify { critic.problems[file_name.to_s].size.should be 1 }
|
82
|
+
specify { critic.problems[file_name.to_s].first[:type].should == "spaces_after_lbracket" }
|
83
|
+
specify { critic.problems[file_name.to_s].first[:line].should be 1 }
|
84
|
+
specify { critic.problems[file_name.to_s].first[:column].should be 6 }
|
85
|
+
specify { critic.problems[file_name.to_s].first[:level].should be :error }
|
86
|
+
end
|
87
|
+
end
|
88
|
+
end
|
@@ -0,0 +1,68 @@
|
|
1
|
+
require_relative '../../spec_helper'
|
2
|
+
require 'tailor/critic'
|
3
|
+
require 'tailor/configuration/style'
|
4
|
+
|
5
|
+
|
6
|
+
COMMA_SPACING = {}
|
7
|
+
COMMA_SPACING[:no_space_after_comma] = %Q{[1,2]}
|
8
|
+
COMMA_SPACING[:two_spaces_after_comma] = %Q{[1, 2]}
|
9
|
+
COMMA_SPACING[:one_space_before_comma] = %Q{[1 , 2]}
|
10
|
+
COMMA_SPACING[:two_spaces_before_comma] = %Q{[1 , 2]}
|
11
|
+
COMMA_SPACING[:two_spaces_before_comma_twice] = %Q{[1 , 2 , 3]}
|
12
|
+
COMMA_SPACING[:two_spaces_after_comma_twice] = %Q{[1, 2, 3]}
|
13
|
+
|
14
|
+
COMMA_SPACING[:spaces_before_with_trailing_comments] = %Q{[
|
15
|
+
1 , # Comment!
|
16
|
+
2 , # Another comment.
|
17
|
+
}
|
18
|
+
|
19
|
+
|
20
|
+
describe "Spacing around comma detection" do
|
21
|
+
before do
|
22
|
+
Tailor::Logger.stub(:log)
|
23
|
+
FakeFS.activate!
|
24
|
+
File.open(file_name.to_s, 'w') { |f| f.write contents }
|
25
|
+
critic.check_file(file_name.to_s, style.to_hash)
|
26
|
+
end
|
27
|
+
|
28
|
+
let(:critic) do
|
29
|
+
Tailor::Critic.new
|
30
|
+
end
|
31
|
+
|
32
|
+
let(:contents) { COMMA_SPACING[file_name]}
|
33
|
+
|
34
|
+
let(:style) do
|
35
|
+
style = Tailor::Configuration::Style.new
|
36
|
+
style.trailing_newlines 0, level: :off
|
37
|
+
style.allow_invalid_ruby true, level: :off
|
38
|
+
|
39
|
+
style
|
40
|
+
end
|
41
|
+
|
42
|
+
context "no space after a comma" do
|
43
|
+
let(:file_name) { :no_space_after_comma }
|
44
|
+
specify { critic.problems[file_name.to_s].size.should be 1 }
|
45
|
+
specify { critic.problems[file_name.to_s].first[:type].should == "spaces_after_comma" }
|
46
|
+
specify { critic.problems[file_name.to_s].first[:line].should be 1 }
|
47
|
+
specify { critic.problems[file_name.to_s].first[:column].should be 3 }
|
48
|
+
specify { critic.problems[file_name.to_s].first[:level].should be :error }
|
49
|
+
end
|
50
|
+
|
51
|
+
context "two spaces after a comma" do
|
52
|
+
let(:file_name) { :two_spaces_after_comma }
|
53
|
+
specify { critic.problems[file_name.to_s].size.should be 1 }
|
54
|
+
specify { critic.problems[file_name.to_s].first[:type].should == "spaces_after_comma" }
|
55
|
+
specify { critic.problems[file_name.to_s].first[:line].should be 1 }
|
56
|
+
specify { critic.problems[file_name.to_s].first[:column].should be 3 }
|
57
|
+
specify { critic.problems[file_name.to_s].first[:level].should be :error }
|
58
|
+
end
|
59
|
+
|
60
|
+
context "one space before comma" do
|
61
|
+
let(:file_name) { :one_space_before_comma }
|
62
|
+
specify { critic.problems[file_name.to_s].size.should be 1 }
|
63
|
+
specify { critic.problems[file_name.to_s].first[:type].should == "spaces_before_comma" }
|
64
|
+
specify { critic.problems[file_name.to_s].first[:line].should be 1 }
|
65
|
+
specify { critic.problems[file_name.to_s].first[:column].should be 2 }
|
66
|
+
specify { critic.problems[file_name.to_s].first[:level].should be :error }
|
67
|
+
end
|
68
|
+
end
|
@@ -0,0 +1,110 @@
|
|
1
|
+
require_relative '../../spec_helper'
|
2
|
+
require 'tailor/critic'
|
3
|
+
require 'tailor/configuration/style'
|
4
|
+
|
5
|
+
#-------------------------------------------------------------------------------
|
6
|
+
# Hard tabs
|
7
|
+
#-------------------------------------------------------------------------------
|
8
|
+
HARD_TABS = {}
|
9
|
+
|
10
|
+
HARD_TABS[:hard_tab] =
|
11
|
+
%Q{def something
|
12
|
+
\tputs "something"
|
13
|
+
end}
|
14
|
+
|
15
|
+
HARD_TABS[:hard_tab_with_spaces] =
|
16
|
+
%Q{class Thing
|
17
|
+
def something
|
18
|
+
\t puts "something"
|
19
|
+
end
|
20
|
+
end}
|
21
|
+
|
22
|
+
# This only reports the hard tab problem (and not the indentation problem)
|
23
|
+
# because a hard tab is counted as 1 space; here, this is 4 spaces, so it
|
24
|
+
# looks correct to the parser. I'm leaving this behavior, as detecting the
|
25
|
+
# hard tab should signal the problem. If you fix the hard tab and don't
|
26
|
+
# fix indentation, tailor will flag you on the indentation on the next run.
|
27
|
+
HARD_TABS[:hard_tab_with_1_indented_space] =
|
28
|
+
%Q{class Thing
|
29
|
+
def something
|
30
|
+
\t puts "something"
|
31
|
+
end
|
32
|
+
end}
|
33
|
+
|
34
|
+
HARD_TABS[:hard_tab_with_2_indented_spaces] =
|
35
|
+
%Q{class Thing
|
36
|
+
def something
|
37
|
+
\t puts "something"
|
38
|
+
end
|
39
|
+
end}
|
40
|
+
|
41
|
+
describe "Hard tab detection" do
|
42
|
+
before do
|
43
|
+
Tailor::Logger.stub(:log)
|
44
|
+
FakeFS.activate!
|
45
|
+
File.open(file_name.to_s, 'w') { |f| f.write contents }
|
46
|
+
critic.check_file(file_name.to_s, style.to_hash)
|
47
|
+
end
|
48
|
+
|
49
|
+
let(:critic) do
|
50
|
+
Tailor::Critic.new
|
51
|
+
end
|
52
|
+
|
53
|
+
let(:contents) { HARD_TABS[file_name]}
|
54
|
+
|
55
|
+
let(:style) do
|
56
|
+
style = Tailor::Configuration::Style.new
|
57
|
+
style.trailing_newlines 0, level: :off
|
58
|
+
style.allow_invalid_ruby true, level: :off
|
59
|
+
|
60
|
+
style
|
61
|
+
end
|
62
|
+
|
63
|
+
context "1 hard tab" do
|
64
|
+
let(:file_name) { :hard_tab }
|
65
|
+
specify { critic.problems[file_name.to_s].size.should be 2 }
|
66
|
+
specify { critic.problems[file_name.to_s].first[:type].should == "allow_hard_tabs" }
|
67
|
+
specify { critic.problems[file_name.to_s].first[:line].should be 2 }
|
68
|
+
specify { critic.problems[file_name.to_s].first[:column].should be 0 }
|
69
|
+
specify { critic.problems[file_name.to_s].first[:level].should be :error }
|
70
|
+
specify { critic.problems[file_name.to_s].last[:type].should == "indentation_spaces" }
|
71
|
+
specify { critic.problems[file_name.to_s].last[:line].should be 2 }
|
72
|
+
specify { critic.problems[file_name.to_s].last[:column].should be 1 }
|
73
|
+
specify { critic.problems[file_name.to_s].last[:level].should be :error }
|
74
|
+
end
|
75
|
+
|
76
|
+
context "1 hard tab with 2 spaces after it" do
|
77
|
+
let(:file_name) { :hard_tab_with_spaces }
|
78
|
+
specify { critic.problems[file_name.to_s].size.should be 2 }
|
79
|
+
specify { critic.problems[file_name.to_s].first[:type].should == "allow_hard_tabs" }
|
80
|
+
specify { critic.problems[file_name.to_s].first[:line].should be 3 }
|
81
|
+
specify { critic.problems[file_name.to_s].first[:column].should be 0 }
|
82
|
+
specify { critic.problems[file_name.to_s].first[:level].should be :error }
|
83
|
+
specify { critic.problems[file_name.to_s].last[:type].should == "indentation_spaces" }
|
84
|
+
specify { critic.problems[file_name.to_s].last[:line].should be 3 }
|
85
|
+
specify { critic.problems[file_name.to_s].last[:column].should be 3 }
|
86
|
+
specify { critic.problems[file_name.to_s].last[:level].should be :error }
|
87
|
+
end
|
88
|
+
|
89
|
+
context "1 hard tab with 3 spaces after it" do
|
90
|
+
let(:file_name) { :hard_tab_with_1_indented_space }
|
91
|
+
specify { critic.problems[file_name.to_s].size.should be 1 }
|
92
|
+
specify { critic.problems[file_name.to_s].first[:type].should == "allow_hard_tabs" }
|
93
|
+
specify { critic.problems[file_name.to_s].first[:line].should be 3 }
|
94
|
+
specify { critic.problems[file_name.to_s].first[:column].should be 0 }
|
95
|
+
specify { critic.problems[file_name.to_s].first[:level].should be :error }
|
96
|
+
end
|
97
|
+
|
98
|
+
context "1 hard tab with 4 spaces after it" do
|
99
|
+
let(:file_name) { :hard_tab_with_2_indented_spaces }
|
100
|
+
specify { critic.problems[file_name.to_s].size.should be 2 }
|
101
|
+
specify { critic.problems[file_name.to_s].first[:type].should == "allow_hard_tabs" }
|
102
|
+
specify { critic.problems[file_name.to_s].first[:line].should be 3 }
|
103
|
+
specify { critic.problems[file_name.to_s].first[:column].should be 0 }
|
104
|
+
specify { critic.problems[file_name.to_s].first[:level].should be :error }
|
105
|
+
specify { critic.problems[file_name.to_s].last[:type].should == "indentation_spaces" }
|
106
|
+
specify { critic.problems[file_name.to_s].last[:line].should be 3 }
|
107
|
+
specify { critic.problems[file_name.to_s].last[:column].should be 5 }
|
108
|
+
specify { critic.problems[file_name.to_s].last[:level].should be :error }
|
109
|
+
end
|
110
|
+
end
|
@@ -0,0 +1,51 @@
|
|
1
|
+
require_relative '../../spec_helper'
|
2
|
+
require 'tailor/critic'
|
3
|
+
require 'tailor/configuration/style'
|
4
|
+
|
5
|
+
|
6
|
+
LONG_LINE = {}
|
7
|
+
LONG_LINE[:long_line_no_newline] = %Q{'#{'#' * 79}'}
|
8
|
+
LONG_LINE[:long_line_newline_at_82] = %Q{'#{'#' * 79}'
|
9
|
+
}
|
10
|
+
|
11
|
+
|
12
|
+
describe "Long line detection" do
|
13
|
+
before do
|
14
|
+
Tailor::Logger.stub(:log)
|
15
|
+
FakeFS.activate!
|
16
|
+
File.open(file_name.to_s, 'w') { |f| f.write contents }
|
17
|
+
critic.check_file(file_name.to_s, style.to_hash)
|
18
|
+
end
|
19
|
+
|
20
|
+
let(:critic) do
|
21
|
+
Tailor::Critic.new
|
22
|
+
end
|
23
|
+
|
24
|
+
let(:contents) { LONG_LINE[file_name]}
|
25
|
+
|
26
|
+
let(:style) do
|
27
|
+
style = Tailor::Configuration::Style.new
|
28
|
+
style.trailing_newlines 0, level: :off
|
29
|
+
style.allow_invalid_ruby true, level: :off
|
30
|
+
|
31
|
+
style
|
32
|
+
end
|
33
|
+
|
34
|
+
context "line is 81 chars, no newline" do
|
35
|
+
let(:file_name) { :long_line_no_newline }
|
36
|
+
specify { critic.problems[file_name.to_s].size.should be 1 }
|
37
|
+
specify { critic.problems[file_name.to_s].first[:type].should == "max_line_length" }
|
38
|
+
specify { critic.problems[file_name.to_s].first[:line].should be 1 }
|
39
|
+
specify { critic.problems[file_name.to_s].first[:column].should be 81 }
|
40
|
+
specify { critic.problems[file_name.to_s].first[:level].should be :error }
|
41
|
+
end
|
42
|
+
|
43
|
+
context "line is 81 chars, plus a newline" do
|
44
|
+
let(:file_name) { :long_line_newline_at_82 }
|
45
|
+
specify { critic.problems[file_name.to_s].size.should be 1 }
|
46
|
+
specify { critic.problems[file_name.to_s].first[:type].should == "max_line_length" }
|
47
|
+
specify { critic.problems[file_name.to_s].first[:line].should be 1 }
|
48
|
+
specify { critic.problems[file_name.to_s].first[:column].should be 81 }
|
49
|
+
specify { critic.problems[file_name.to_s].first[:level].should be :error }
|
50
|
+
end
|
51
|
+
end
|
@@ -0,0 +1,102 @@
|
|
1
|
+
require_relative '../../spec_helper'
|
2
|
+
require 'tailor/critic'
|
3
|
+
require 'tailor/configuration/style'
|
4
|
+
|
5
|
+
|
6
|
+
PARENS = {}
|
7
|
+
PARENS[:simple_method_call_space_after_lparen] = %Q{thing( one, two)}
|
8
|
+
PARENS[:simple_method_call_space_before_rparen] = %Q{thing(one, two )}
|
9
|
+
PARENS[:method_call_space_after_lparen_trailing_comment] =
|
10
|
+
%Q{thing( one, two) # comment}
|
11
|
+
PARENS[:method_call_space_after_lparen_before_rparen_trailing_comment] =
|
12
|
+
%Q{thing( one, two ) # comment}
|
13
|
+
|
14
|
+
PARENS[:multi_line_method_call_space_after_lparen] = %Q{thing( one,
|
15
|
+
two)}
|
16
|
+
PARENS[:multi_line_method_call_space_after_lparen_trailing_comment] =
|
17
|
+
%Q{thing( one,
|
18
|
+
two)}
|
19
|
+
|
20
|
+
describe "Detection of spaces around brackets" do
|
21
|
+
before do
|
22
|
+
Tailor::Logger.stub(:log)
|
23
|
+
FakeFS.activate!
|
24
|
+
File.open(file_name.to_s, 'w') { |f| f.write contents }
|
25
|
+
critic.check_file(file_name.to_s, style.to_hash)
|
26
|
+
end
|
27
|
+
|
28
|
+
let(:critic) do
|
29
|
+
Tailor::Critic.new
|
30
|
+
end
|
31
|
+
|
32
|
+
let(:contents) { PARENS[file_name]}
|
33
|
+
|
34
|
+
let(:style) do
|
35
|
+
style = Tailor::Configuration::Style.new
|
36
|
+
style.trailing_newlines 0, level: :off
|
37
|
+
style.allow_invalid_ruby true, level: :off
|
38
|
+
|
39
|
+
style
|
40
|
+
end
|
41
|
+
|
42
|
+
context "methods" do
|
43
|
+
context "space after lparen" do
|
44
|
+
let(:file_name) { :simple_method_call_space_after_lparen }
|
45
|
+
specify { critic.problems[file_name.to_s].size.should be 1 }
|
46
|
+
specify { critic.problems[file_name.to_s].first[:type].should == "spaces_after_lparen" }
|
47
|
+
specify { critic.problems[file_name.to_s].first[:line].should be 1 }
|
48
|
+
specify { critic.problems[file_name.to_s].first[:column].should be 6 }
|
49
|
+
specify { critic.problems[file_name.to_s].first[:level].should be :error }
|
50
|
+
end
|
51
|
+
|
52
|
+
context "space before rparen" do
|
53
|
+
let(:file_name) { :simple_method_call_space_before_rparen }
|
54
|
+
specify { critic.problems[file_name.to_s].size.should be 1 }
|
55
|
+
specify { critic.problems[file_name.to_s].first[:type].should == "spaces_before_rparen" }
|
56
|
+
specify { critic.problems[file_name.to_s].first[:line].should be 1 }
|
57
|
+
specify { critic.problems[file_name.to_s].first[:column].should be 15 }
|
58
|
+
specify { critic.problems[file_name.to_s].first[:level].should be :error }
|
59
|
+
end
|
60
|
+
|
61
|
+
context "space after lparen, trailing comment" do
|
62
|
+
let(:file_name) { :method_call_space_after_lparen_trailing_comment }
|
63
|
+
specify { critic.problems[file_name.to_s].size.should be 1 }
|
64
|
+
specify { critic.problems[file_name.to_s].first[:type].should == "spaces_after_lparen" }
|
65
|
+
specify { critic.problems[file_name.to_s].first[:line].should be 1 }
|
66
|
+
specify { critic.problems[file_name.to_s].first[:column].should be 6 }
|
67
|
+
specify { critic.problems[file_name.to_s].first[:level].should be :error }
|
68
|
+
end
|
69
|
+
|
70
|
+
context "space after lparen, before rparen, trailing comment" do
|
71
|
+
let(:file_name) { :method_call_space_after_lparen_before_rparen_trailing_comment }
|
72
|
+
specify { critic.problems[file_name.to_s].size.should be 2 }
|
73
|
+
specify { critic.problems[file_name.to_s].first[:type].should == "spaces_after_lparen" }
|
74
|
+
specify { critic.problems[file_name.to_s].first[:line].should be 1 }
|
75
|
+
specify { critic.problems[file_name.to_s].first[:column].should be 6 }
|
76
|
+
specify { critic.problems[file_name.to_s].first[:level].should be :error }
|
77
|
+
specify { critic.problems[file_name.to_s].last[:type].should == "spaces_before_rparen" }
|
78
|
+
specify { critic.problems[file_name.to_s].last[:line].should be 1 }
|
79
|
+
specify { critic.problems[file_name.to_s].last[:column].should be 16 }
|
80
|
+
specify { critic.problems[file_name.to_s].last[:level].should be :error }
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
context "multi-line method calls" do
|
85
|
+
context "space after lparen" do
|
86
|
+
let(:file_name) { :multi_line_method_call_space_after_lparen }
|
87
|
+
specify { critic.problems[file_name.to_s].size.should be 1 }
|
88
|
+
specify { critic.problems[file_name.to_s].first[:type].should == "spaces_after_lparen" }
|
89
|
+
specify { critic.problems[file_name.to_s].first[:line].should be 1 }
|
90
|
+
specify { critic.problems[file_name.to_s].first[:column].should be 6 }
|
91
|
+
specify { critic.problems[file_name.to_s].first[:level].should be :error }
|
92
|
+
end
|
93
|
+
context "space after lparen, trailing comment" do
|
94
|
+
let(:file_name) { :multi_line_method_call_space_after_lparen_trailing_comment }
|
95
|
+
specify { critic.problems[file_name.to_s].size.should be 1 }
|
96
|
+
specify { critic.problems[file_name.to_s].first[:type].should == "spaces_after_lparen" }
|
97
|
+
specify { critic.problems[file_name.to_s].first[:line].should be 1 }
|
98
|
+
specify { critic.problems[file_name.to_s].first[:column].should be 6 }
|
99
|
+
specify { critic.problems[file_name.to_s].first[:level].should be :error }
|
100
|
+
end
|
101
|
+
end
|
102
|
+
end
|
@@ -0,0 +1,66 @@
|
|
1
|
+
require_relative '../../spec_helper'
|
2
|
+
require_relative '../../support/horizontal_spacing_cases'
|
3
|
+
require 'tailor/critic'
|
4
|
+
require 'tailor/configuration/style'
|
5
|
+
|
6
|
+
|
7
|
+
TRAILING_WHITESPACE = {}
|
8
|
+
TRAILING_WHITESPACE[:empty_line_with_spaces] = %Q{ }
|
9
|
+
TRAILING_WHITESPACE[:empty_line_with_spaces_in_method] = %Q{def thing
|
10
|
+
|
11
|
+
puts 'something'
|
12
|
+
end}
|
13
|
+
|
14
|
+
TRAILING_WHITESPACE[:trailing_spaces_on_def] = %Q{def thing
|
15
|
+
puts 'something'
|
16
|
+
end}
|
17
|
+
|
18
|
+
describe "Trailing whitespace detection" do
|
19
|
+
before do
|
20
|
+
Tailor::Logger.stub(:log)
|
21
|
+
FakeFS.activate!
|
22
|
+
File.open(file_name.to_s, 'w') { |f| f.write contents }
|
23
|
+
critic.check_file(file_name.to_s, style.to_hash)
|
24
|
+
end
|
25
|
+
|
26
|
+
let(:critic) do
|
27
|
+
Tailor::Critic.new
|
28
|
+
end
|
29
|
+
|
30
|
+
let(:contents) { TRAILING_WHITESPACE[file_name]}
|
31
|
+
|
32
|
+
let(:style) do
|
33
|
+
style = Tailor::Configuration::Style.new
|
34
|
+
style.trailing_newlines 0, level: :off
|
35
|
+
style.allow_invalid_ruby true, level: :off
|
36
|
+
|
37
|
+
style
|
38
|
+
end
|
39
|
+
|
40
|
+
context "line is empty spaces" do
|
41
|
+
let(:file_name) { :empty_line_with_spaces }
|
42
|
+
specify { critic.problems[file_name.to_s].size.should be 1 }
|
43
|
+
specify { critic.problems[file_name.to_s].first[:type].should == "allow_trailing_line_spaces" }
|
44
|
+
specify { critic.problems[file_name.to_s].first[:line].should be 1 }
|
45
|
+
specify { critic.problems[file_name.to_s].first[:column].should be 2 }
|
46
|
+
specify { critic.problems[file_name.to_s].first[:level].should be :error }
|
47
|
+
end
|
48
|
+
|
49
|
+
context "method contains an empty line with spaces" do
|
50
|
+
let(:file_name) { :empty_line_with_spaces_in_method }
|
51
|
+
specify { critic.problems[file_name.to_s].size.should be 1 }
|
52
|
+
specify { critic.problems[file_name.to_s].first[:type].should == "allow_trailing_line_spaces" }
|
53
|
+
specify { critic.problems[file_name.to_s].first[:line].should be 2 }
|
54
|
+
specify { critic.problems[file_name.to_s].first[:column].should be 2 }
|
55
|
+
specify { critic.problems[file_name.to_s].first[:level].should be :error }
|
56
|
+
end
|
57
|
+
|
58
|
+
context "def line ends with spaces" do
|
59
|
+
let(:file_name) { :trailing_spaces_on_def }
|
60
|
+
specify { critic.problems[file_name.to_s].size.should be 1 }
|
61
|
+
specify { critic.problems[file_name.to_s].first[:type].should == "allow_trailing_line_spaces" }
|
62
|
+
specify { critic.problems[file_name.to_s].first[:line].should be 1 }
|
63
|
+
specify { critic.problems[file_name.to_s].first[:column].should be 11 }
|
64
|
+
specify { critic.problems[file_name.to_s].first[:level].should be :error }
|
65
|
+
end
|
66
|
+
end
|