This repository was archived by the owner on Nov 30, 2024. It is now read-only.
File tree Expand file tree Collapse file tree 1 file changed +42
-0
lines changed Expand file tree Collapse file tree 1 file changed +42
-0
lines changed Original file line number Diff line number Diff line change @@ -103,4 +103,46 @@ def have_successful_no_warnings_output
103
103
104
104
expect ( loaded_features ) . to eq ( [ ] )
105
105
end
106
+
107
+ # This malformed whitespace detection logic has been borrowed from bundler:
108
+ # https://github.com/bundler/bundler/blob/v1.8.0/spec/quality_spec.rb
109
+ def check_for_tab_characters ( filename )
110
+ failing_lines = [ ]
111
+ File . readlines ( filename ) . each_with_index do |line , number |
112
+ failing_lines << number + 1 if line =~ /\t /
113
+ end
114
+
115
+ return if failing_lines . empty?
116
+ "#{ filename } has tab characters on lines #{ failing_lines . join ( ', ' ) } "
117
+ end
118
+
119
+ def check_for_extra_spaces ( filename )
120
+ failing_lines = [ ]
121
+ File . readlines ( filename ) . each_with_index do |line , number |
122
+ next if line =~ /^\s +#.*\s +\n $/
123
+ failing_lines << number + 1 if line =~ /\s +\n $/
124
+ end
125
+
126
+ return if failing_lines . empty?
127
+ "#{ filename } has spaces on the EOL on lines #{ failing_lines . join ( ', ' ) } "
128
+ end
129
+
130
+ RSpec ::Matchers . define :be_well_formed do
131
+ match do |actual |
132
+ actual . empty?
133
+ end
134
+
135
+ failure_message do |actual |
136
+ actual . join ( "\n " )
137
+ end
138
+ end
139
+
140
+ it "has no malformed whitespace" do
141
+ error_messages = [ ]
142
+ `git ls-files -z` . split ( "\x0 " ) . each do |filename |
143
+ error_messages << check_for_tab_characters ( filename )
144
+ error_messages << check_for_extra_spaces ( filename )
145
+ end
146
+ expect ( error_messages . compact ) . to be_well_formed
147
+ end
106
148
end
You can’t perform that action at this time.
0 commit comments